How to use the state parameter in passport-okta-oauth?

I am using passport-okta-oauth to implement Okta SSO in my application . I referred the documentation and came to know about the usage of the state parameter. However , when I pass state parameter in my request. I get the following error :

{ 'message': 'Unable to verify authorization request state'}

Here is the reference to my code:

app.get('/oauth/redirect/okta', function (req, res, next) {
        // Retriving the state value here 
        let stateString = JSON.parse(Buffer.from(req.query.state, 'base64').toString('ascii'));
        passport.authenticate('okta', { failureRedirect: `${config.oauthDomainUrl}/oauth/failure?provider=okta` }, function (err, user, info) {
            if (req.query.error != undefined) {
            } else {
                var profileId =;

                /* Profile Id is sent along the URL to know that the user authentication is successful */
                let redirectUrl = `${config.redirectUrl}?pid=${profileId}&orgId=${stateString.orgId}&clientId=${stateString.clientId}`;

        })(req, res, next);

app.get('/oauth/okta', function (req, res, next) {
    let stateString = Buffer.from(JSON.stringify(req.query)).toString('base64')
            state: stateString // passing the state string here
        },function () {
            /* The request will be redirected to Okta for authentication, so this
                function will not be called. */
        })(req, res, next);

In the three parameters in the successful redirect (err, user, info) . I get the following response

err : null

user : false

info : { 'message': 'Unable to verify authorization request state'}

Everything worked fine until I passed the state parameter.