[英]How can I use refresh token
我有一个像这样的获取刷新令牌 api http://token.net/api/auth/refresh-token
。 我想在我的登录名 function 中使用它,但说实话,我对刷新令牌一无所知。 我怎样才能在其中实现刷新令牌。
登录认证.js
export const useLogin = () => {
const LoginAuth = async (data: AuthenticationProps) => {
await axios.post(`client.com/auth/login`,
{
email: data.email,
password: data.password,
},
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
}
}
)
.then((res) => {
if(res.status === 200) {
console.log("works");
}
}, (err) => {
console.log(err);
})
}
return {
LoginAuth,
}
}
刷新令牌用于为应用程序生成新的访问令牌。 如果访问令牌有到期日期,一旦到期,用户将必须再次进行身份验证才能获得访问令牌。
脚步:
localStorage
中。axios.interceptors.response
以调用refresh_token
API 并使用新的access_token
更新localStorage
。INVALID_TOKEN
代码作为响应,并调用refresh_token
API。 现在,将使用新的刷新token
进一步调用任何 API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.