So my constructor for auth0 is basically the same as the React SPA guide.
constructor() {
let hostname = window.location.hostname;
this.auth0 = new auth0.WebAuth({
domain: process.env.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID,
redirectUri: `${window.location.protocol}//${hostname}/callback`,
audience: `${process.env.AUTH0_AUDIENCE}`,
responseType: 'token id_token',
scope: 'openid profile app_metadata roles'
});
this.login = this.login.bind(this);
this.logout = this.logout.bind(this);
this.handleAuthentication = this.handleAuthentication.bind(this);
this.isAuthenticated = this.isAuthenticated.bind(this);
this.userHasScopes = this.userHasScopes.bind(this);
}
login() {
this.auth0.authorize();
}
handleAuthentication() {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.setSession(authResult);
history.replace('/');
}
else if (err) {
console.log(err);
alert(`Error: ${err.error}. Check the console for further details.`);
}
});
}