Auth0.checksession new token
A Auth0 question!
auth0.checkSession
is a method provided by the Auth0 JavaScript SDK that allows you to check the validity of an existing authentication session. When you call auth0.checkSession
, Auth0 will verify the session token and return a new token if the session is still valid.
Here's an example of how to use auth0.checkSession
to obtain a new token:
import { WebAuth } from '@auth0/web-auth';
const auth0 = new WebAuth({
domain: 'your-domain.auth0.com',
clientId: 'your-client-id',
redirectUri: 'http://localhost:3000',
});
auth0.checkSession({
audience: 'https://your-domain.auth0.com/api/v2/',
scope: 'openid profile email',
})
.then((response) => {
const newToken = response.accessToken;
// Use the new token to make API calls or authenticate the user
})
.catch((error) => {
console.error(error);
});
In this example, we create an instance of the WebAuth
class and call checkSession
with the following options:
audience
: The audience URL for the token.scope
: The scope of the token (in this case, openid, profile, and email).
When you call checkSession
, Auth0 will verify the session token and return a new token if the session is still valid. The response
object will contain the new token, which you can use to make API calls or authenticate the user.
Note that checkSession
will only return a new token if the session is still valid. If the session has expired or is invalid, checkSession
will return an error.