I am using auth0 and nextJS.
I want to do next: When the user will add his credentials and will log in he is redirected to the callback
API.
And here
import auth0 from '../../utils/auth0';
export default async function callback(req, res) {
try {
await auth0.handleCallback(req, res, {
redirectTo: '/'
});
} catch (error) {
console.error(error);
res.status(error.status || 400).end(error.message);
}
}
I want to redirect the user depending on the token.
Decoding the token I will get data if the application is a simple user or admin.
If he is an admin he should be redirected to the admin page if not to the user page.
So I did something like this:
import auth0 from '../../utils/auth0';
export default async function callback(req, res) {
const tokenCache = auth0.tokenCache(req, res);
const { accessToken } = await tokenCache.getAccessToken();
console.log(accessToken)
try {
await auth0.handleCallback(req, res, { redirectTo: '/' });
} catch (error) {
console.error(error);
res.status(error.status || 400).end(error.message);
}
}
So I want to get the token inside this function to be able to redirect users on different pages, but if I want to get the token here I get the issue:
The user does not have a valid session.
If I delete the code related to the token the user is redirected, but I need to get the token here to be able to do the checking of users.
How could I get the token inside this callback
function and achieve what I described above?