Usage
Initialisation
A dependency of our modified Auth0 library is our supertokens-website
package. This is automatically downloaded. You need to call the init
function for that:
Changes
Change all imports of
@auth0/auth0-spa-js
tosupertokens-auth0-spa-js
and all imports of@auth0/auth0-react
tosupertokens-auth0-react
You no longer need to use
getTokenSilently
&getTokenWithPopup
. This implies that you do not have to put Auth0's access token as a header in any of your API calls.On the Auth0 dashboard, please make sure that you have not selected rotating refresh tokens.
In your code, set:
useRefreshToken
totrue
cacheLocation
to"localstorage"
. This is OK from a security point of view since only the Auth0 ID Token is being stored in thelocalstorage
.
Please refer to
@auth0/auth0-spa-js
or@auth0/auth0-react
documentation since the interface is the same.Please see the docs for your SuperTokens backend SDK to complete the Auth0 integration.
Changing backend URL Path (Optional)
By default, the SDK will query /supertokens-auth0 POST
API on your backend. To change this, you can set your own path like so:
import SuperTokensRequest from 'supertokens-website';
SuperTokensRequest.init({
refreshTokenUrl: "https://api.example.com/session/refresh"
});
// this will query https://api.example.com/custom-auth0-path
SuperTokensRequest.setAuth0API("/custom-auth0-path");
import SuperTokensRequest from 'supertokens-website/axios';
SuperTokensRequest.init({
refreshTokenUrl: "https://api.example.com/session/refresh"
});
// this will query https://api.example.com/custom-auth0-path
SuperTokensRequest.setAuth0API("/custom-auth0-path");