[AUTH0 IdToken Refresh]: how to get a refresh_token to get a new idToken and pass it on when it expires

Hello

I would like to know if you could help me how to get a refresh_token to get a new idToken and pass it on when it expires.

I currently detect when it expires with graphql Error, and I call the api/auth/login in nextjs.

I’m using nextjs-auth0 + auth0 as Authentication Profiles.

Everything else works ok, I would just like to know how they solved the issue of refreshing the IdToken with auth0.

I have read everything but without options to solve it.

or if the solution is simply to make the user log in again?

Thank you!

Hello!

Sorry about the long wait. I’ll give you a response soon.

Lada Kokotova | Technical Support Engineer

You can get refreshToken with userLogin mutation:

mutation {
  userLogin(data:{
    email: "your_email",
    authProfileId: "your_authProfileID",
    password: "your_password"
  }) {
    success
    auth{
        idToken
        refreshToken
    }
  }
}

Then just pass it to update your idToken:

mutation {
  userRefreshToken(data:{
    email: "your_email"
    refreshToken: "token_from_previous_mutation"
    authProfileId: "your_authProfileID"})
  {
    refreshToken
    idToken
  }
}

Please let us know if you need more help with auth logic.

Lada Kokotova | Technical Support Engineer

How many time can I do this?, or can I do it every time that I want?

You can use this whenever you need it.

Lada Kokotova | Technical Support Engineer

Thanks for responding.

If this works for authentication with native 8base, but I’m using Auth0-nextjs. https://github.com/auth0/nextjs-auth0

Everything works fine but the idToken expires and I would like to see if there is the refresh token option. or if you managed to solve it in some way.

I currently have it like this:

  1. The user login
  2. Graphql “Token expired” error
  3. Redirect to Login - /api/auth/login
  4. I get a new session with “idToken”.

The flow I’m thinking of is:

  1. The user login
  2. Graphql “Token expired” error
  3. Get refresh token Auth0
  4. I pass the new token
  5. I get a new session with “idToken”.

Hello!

The flow you are thinking of should work just fine with custom Auth0 authethication profile. What are your concerns about Auth0-nextjs?

Lada Kokotova | Technical Support Engineer