Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class Auth {
- ...
- handleAuthentication() {
- this.auth0.parseHash((err, authResult) => {
- if (authResult && authResult.accessToken && authResult.idToken) {
- this.setSession(authResult);
- Router.push('/home');
- } else if (err) {
- console.log(err);
- alert(`Error: ${err.error}. Check the console for further details.`);
- Router.push('/home');
- }
- });
- }
- setSession(authResult) {
- // Set the time that the access token will expire at
- let expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime());
- localStorage.setItem('access_token', authResult.accessToken);
- localStorage.setItem('id_token', authResult.idToken);
- localStorage.setItem('expires_at', expiresAt);
- // navigate to the home route
- Router.push('/home');
- }
Add Comment
Please, Sign In to add comment