Getting Refresh token error in auth0-nextjs application

Viewed 350

We are building a web application (Single page application)using NextJS. In which we are using auth0 for login. We are facing weird problem, after login we are getting an error message saying Error: A refresh token is required to refresh the access token, but none is present. Error message in browser

We have getAccessToken.js file where we have added all the necessary configs to get the token but still getting the error.

const afterRefresh = (req, res, session) => {
    console.log("sess", session);
    delete session.idToken;
    return session;
};
export default async function MyHandler(req, res) {
    const token = await getAccessToken(req, res, {
        refresh: true,
        afterRefresh,
    });

also we are setting scope as offline in [...auth0].ts file

export default handleAuth({
    async login(req, res) {
        try {
            await handleLogin(req, res, {
                authorizationParams: {
                    audience: "gateway.dev.abcdDomain.com",
                    // Add the `offline_access` scope to also get a Refresh Token
                    scope: "openid profile email offline_access", // or AUTH0_SCOPE
                    useRefreshTokens: true,
                },
            });
        } catch (error) {
            res.status(error.status || 400).end(error.message);
        }
    },

The get-access-token.ts in nextjs-auth0 library, the accessTokenRequest is Boolean

export interface AccessTokenRequest {
  /**
   * A list of desired scopes for your Access Token.
   */
  scopes?: string[];
  /**
   * If set to `true`, a new Access Token will be requested with the Refresh Token grant, regardless of whether
   * the Access Token has expired or not.
   */
  refresh?: boolean;

any idea where we are going wrong.

1 Answers
Related