Currently when I create my routes, I check an Auth0 method - isAuthenticated() - to determine whether or not to return a protected page or redirect to login. However, this s
You can use Silent authentication to renew the tokens on browser refresh.
Specifically for your react SPA app
tokenRenewed to false in your main App componentrenewToken method in your auth.js so call that in componentDidMount methodcomponentDidMount() {
this.auth.renewToken(() => {
this.setState({tokenRenewed : true});
})
}
renewToken to accept a callback cb like belowrenewSession(cb) {
this.auth0.checkSession({}, (err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.setSession(authResult);
} else if (err) {
this.logout();
console.log(`Could not get a new token. (${err.error}: ${err.error_description})`);
}
if(cb) cb(err, authResult);
});
}
tokenRenewed is true i.e. unless you have the valid tokens renewed via silent authenticationrender() {
if(!this.state.tokenRenewed) return "loading...";
return (
// Your App component
);
}
Notes:
Allowed Web Origins set in the Application settings for this to work