我阅读了有关身份验证的文档。我在 Nuxt 项目上工作,我的服务器返回一个 cookieHtppOnly
我的问题:
关于 JWT 令牌的存储有很多困惑,有些不建议使用localStroage
我还阅读了我们可以将令牌直接复制到下一个请求的标头中,但我没有找到示例。此外,当 cookie 存在时HttpOnly
,由于 JavaScript 无法访问,我们如何使用它?
// https://github.com/FormidableLabs/urql/tree/main/exchanges/auth#quick-start-guide
if (result.data?.refreshLogin) {
// save the new tokens in storage for next restart
localStorage.setItem('token', result.data.refreshLogin.token);
localStorage.setItem('refreshToken', result.data.refreshLogin.refreshToken);
//...
}
资源:
- nuxt/auth => https://www.npmjs.com/package/@nuxtjs/auth-next
- urql/auth => https://www.npmjs.com/package/@urql/exchange-auth
- https://formidable.com/open-source/urql/docs/advanced/authentication/
- https://formidable.com/open-source/urql/docs/api/auth-exchange/#options
- https://github.com/FormidableLabs/urql/tree/main/exchanges/auth#quick-start-guide
- https://blog.logrocket.com/jwt-authentication-best-practices/
- https://www.howtographql.com/react-urql/5-authentication/