[英]How to check if auth token is expired and force logout?
I am using auth0 for my client-side user authentication and authorization.我使用 auth0 进行客户端用户身份验证和授权。 This is the flow`这是流量`
const authService = new auth0.WebAuth(coreConstants.AUTH0_OPTIONS);
const currentDate = Date.now();
authService.parseHash((err, authResult) => {
if(err) console.log(err)
const idToken = authResult.idToken;
window.localStorage.setItem('auth', JSON.stringify({
expiresAt: someDate + Date.now()
accessToken: authResult.accessToken,
idToken,
}));
})
My problem now is that when the token is expired the user yet can interact with the page and just refreshing the page redirects the user to the login page.我现在的问题是,当令牌过期时,用户还可以与页面交互,只需刷新页面即可将用户重定向到登录页面。 I have already read auth0
documentation but couldn't find an appropriate solution for checking if the token is expired.我已经阅读了auth0
文档,但找不到合适的解决方案来检查令牌是否已过期。 Any bits of advice?有什么建议吗?
Did you try jwt.verify ?你试过jwt.verify吗? it will check if the token is expired.它将检查令牌是否已过期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.