I am using token.getWithRedirect for logging in and the tokens are stored in my local storage.
I have the isAuthenticated function to check if the token is present in local storage which will return true otherwise the token.getWithRedirect function will be called. The id token appears to get renewed every 1 hour and everything is working fine until the SSO session is valid.
My organization’s SSO session is set to expire every 12 hours.
When this session expires, my isAuthenticated function is returning true since the token is present in the local storage but I also get a login_required error in the console and then the okta-token-storage is blank.
error.errorCode: login_required, error.description: The client specified not to prompt, but the user is not logged in.
When I navigate to any other page, since the token is not in okta-token-storage the token.getWithRedirect function gets called and I get the new tokens
I want to catch the login_required error so that I can call the getWithRedirect function to login but I am not able to catch the error.
The authClient.tokenManager.get(‘idToken’) is also not a promise function, it gives me error authClient.tokenManager.get(…).idToken.then is not a function.
I am not sure how the login_required error is printed in the console, the only function I am calling is authClient.tokenManager.get(‘idToken’)
Following is my code snippet
Login function
login() {
// Launches the login redirect.
this.oktaAuth.token.getWithRedirect({
responseType: [‘id_token’, ‘token’],
scopes: [‘openid’]
})
.catch(err => console.error(‘error logging in’, err));
}
isAuthenticated function
isAuthenticated() {
try {
if (this.oktaAuth.tokenManager.get(‘idToken’)) {
var token = this.oktaAuth.tokenManager.get(‘idToken’).idToken;
if (token == null) {
return false;
} else {
return true;
}
}
return false;
}
catch (e) {
console.log(‘exception in getting token’+e)
return false;
}
}
Sorry for the long post. Please respond and help!