How to access auth0 token with react SDK?

Viewed 211

I have been struggling for a while now to find a nice way to implement auth0 in a React application.

At the moment I'm using the "new" react SDK. The issue I'm facing is that to use this SDK I can't access an accessToken (for API calls) outside of hooks or components... I'm looking for a way to create an Axios interceptor such that the token is set once and not every call separately...

Is there a way to achieve this?

Thanks in Advance!

1 Answers

You can setup a cookie with the auth0 token in component which will be redirected to by the auth0 after successful authentication. Then using the cookie, in axios interceptors, take token from cookie and pass it for the call.

If you don't want to store it in cookie, alternatives can be localStorage, sessionStorage.

Related