Get `access_token` outside React
See original GitHub issueIssue
I would like to have the access_token
available outside React too. Is there a reliable mechanism for that?
My use case
I have a fetch wrapper that is defined outside React and is being used across the codebase outside React’s scope. The wrapper requires the access_token
. I could read that from the store (sessionStorage
or localStorage
) but I would prefer if the library naturally supported that.
In addition, I use the same token for my Websocket authentication. So it’s not only about fetch
.
Note
I know that the worker automatically injects the token, but I’m targeting old browsers too where Service Worker isn’t available.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
access token from auth0provider outside of react components
The short answer: Get the token when auth0 is initialized and ... Here is a tiny version which also can be used outside...
Read more >How to get Auth0 token from outside React components in this ...
I need to set an Authorization header for all of the requests happening after the authentication with a value of “Bearer accessToken”. What...
Read more >How to access the token within a redux middleware that is ...
Hi, is there a way of calling getAccessTokenSilently from outside a react component? I need to get the token in an axios interceptor....
Read more >How to get Auth0 token from outside React components?
Coding example for the question How to get Auth0 token from outside React components? ... import { useEffect } from "react"; import {...
Read more >Is It Necessary to Have So Much Code to Get an Access ...
Hi @Andrew-1027 , I was given a document showing how to require an access token outside of a react component. 189894-react.png.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
hi @DavidErben,
Unfortunately i do not have solution 😦
ServiceWorker mode is not usable with WebSocket at all for now. I hope ServiceWorker will evolve in the future to catch WebSocket stream.
Hi @amir-ziaei,
Thank you for the feedback. It seems it is not possible for the moment. https://stackoverflow.com/questions/37741185/is-it-possible-to-intercept-and-cache-websocket-messages-in-a-service-worker-lik I will continue to search. I really would like to see wesocket working with the service worker mode.