Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class Auth {
- //parameters of Auth-object
- accessToken;
- idToken;
- expiresAt;
- userProfile;
- auth0 = new auth0.WebAuth({
- domain: AUTH_CONFIG.domain,
- clientID: AUTH_CONFIG.clientId,
- redirectUri: AUTH_CONFIG.callbackUrl,
- responseType: AUTH_CONFIG.responseType,
- scope: AUTH_CONFIG.scope
- });
- constructor() {
- if (localStorage.getItem("accessToken") && localStorage.getItem("idToken") && localStorage.getItem("expiresAt")) {
- console.log("Auth.js.constructor() IF - Data found in the localStorage");
- this.accessToken = localStorage.getItem("accessToken");
- this.idToken = localStorage.getItem("idToken");
- this.expiresAt = localStorage.getItem("expiresAt");
- }
- else {
- console.log("Auth.js.constructor() ELSE - No data found in the localstorage ELSE");
- }
- 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.getAccessToken = this.getAccessToken.bind(this);
- this.getIdToken = this.getIdToken.bind(this);
- this.renewSession = this.renewSession.bind(this);
- this.getProfile = this.getProfile.bind(this);
- }
- setSession(authResult) {
- console.log("Auth.js.setSession() called with : authResult ->", authResult);
- // Set the time that the access token will expire at
- let expiresAt = (authResult.expiresIn * 1000) + new Date().getTime();
- this.accessToken = authResult.accessToken;
- this.idToken = authResult.idToken;
- this.expiresAt = expiresAt;
- localStorage.setItem("accessToken", authResult.accessToken);
- localStorage.setItem("idToken", authResult.idToken);
- localStorage.setItem("expiresAt", (new Date().getTime() / 1000) + authResult.expiresIn);
- localStorage.setItem("isLoggedIn", true);
- // navigate to the home route
- history.replace('/dashboard');
- }
- }
Add Comment
Please, Sign In to add comment