简体   繁体   English

使用新的 auth0 SPA 存储令牌反应和 Redux

[英]React and Redux with the new auth0 SPA storing token

I'm using the new auth0-SPA to make api calls.我正在使用新的 auth0-SPA 进行 api 调用。 I'm facing an issue when storing the token in redux as I am making API calls with my actions.我在 redux 中存储令牌时遇到问题,因为我正在使用我的操作进行 API 调用。 I'm concerned about the refresh of my token where in the docs it says to use the我担心我的令牌的刷新,在文档中它说要使用

await getTokenSilently()

however I am doing this on the inital load of the context and storing that token in state, how will I know when to update the token as I can only store serialised data within state.但是我在上下文的初始加载中执行此操作并将该令牌存储在 state 中,我怎么知道何时更新令牌,因为我只能在 state 中存储序列化数据。 Unlike in the docs where they are using that method directly on a fetch.与他们在获取时直接使用该方法的文档不同。 Thanks!谢谢!

You can also store your token in cookie.您还可以将令牌存储在 cookie 中。 Your apiclient will include cookie in every API call.您的 apiclient 将在每个 API 调用中包含 cookie。 That also helps in dealing with browser refresh because redux will loose the token in browser refresh.这也有助于处理浏览器刷新,因为 redux 将在浏览器刷新时丢失令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 API 的 Auth0 React SPA 访问令牌不正确 - Auth0 React SPA incorrect access token for API React / Redux / Router-Auth0登录加载 - React/Redux/Router - Auth0 login on load 如何使用新的 auth0-spa.js 在不单击“登录”按钮的情况下重定向到 auth0? - How can I redirect to auth0 without clicking on the Log In button in react using the new auth0-spa.js? 如何在浏览器中为 React SPA 保留 Auth0 登录状态 - How to persist Auth0 login status in browser for React SPA 如何使用 react SDK 访问 auth0 令牌? - How to access auth0 token with react SDK? React Native Auth Flow with Redux(新版本)令牌获取问题 - React Native Auth Flow with Redux (New Version) Token Fetch Problem 使用react和redux对auth0锁定示例感到困惑 - Confused about an auth0 lock example using react and redux 有谁知道如何使用 Azure Active Directory 和 React SPA 设置 OpenIdConnect Auth 而不在浏览器中存储访问令牌 - Does anyone know how to set up OpenIdConnect Auth using Azure Active Directory and React SPA without storing access token in the broswer 如何在反应中使用@auth0/auth0-spa-js 通过浏览器刷新保持登录 - How to persist login through browser refresh using @auth0/auth0-spa-js in react 如何将 auth0 访问令牌添加到 react-apollo - how to add auth0 access token to react-apollo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM