question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get `access_token` outside React

See original GitHub issue

Issue

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:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
guillaume-chervetcommented, Dec 13, 2022

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.

1reaction
guillaume-chervetcommented, Sep 29, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found