Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
token_use:
website:
*/
// Verify JWT here.
const parsed = parseJwt(jwt);
if (new Date().getTime() / 1000 >= parseInt(parsed.exp)) {
console.log("JWT expired");
localStorage.removeItem("jwt");
let refreshToken = localStorage.getItem("refresh_token");
if (refreshToken) {
dispatch(exchangeRefreshToken(refreshToken));
}
}
else {
Auth.signOut();
let attributes: IUserAttributes = { "name": parsed["name"], "email": parsed["email"], "email_verified": parsed["email_verified"], "cognito:groups": parsed["cognito:groups"] };
return await {
"username": parsed["sub"],
attributes
};
}
}
// If JWT from SAML has expired, or if there is no JWT in the first place, run this code.
// Need to parse our local JWT as well to get cognito:groups attribute, because Auth.currentAuthenticatedUser() does not return user groups.
return Promise.all([
Auth.currentAuthenticatedUser(),
parseJwt((await Auth.currentSession()).getIdToken().getJwtToken())
]).then(([user, token]) => {
user.attributes["cognito:groups"] = token["cognito:groups"];
return user;
signOut = async () => {
await Auth.signOut()
.then(() => {
console.log('Sign out complete')
this.props.navigation.navigate('Authloading')
})
.catch(err => console.log('Error while signing out!', err))
}
render() {
return dispatch => {
loadingStart();
console.log("signing out");
Cache.removeItem("federatedInfo");
localStorage.clear();
Auth.signOut().then(e => {
loadingEnd();
dispatch(loggedOut());
})
}
}
const logout = async () => {
await Auth.signOut();
};
case Constants.AMAZON:
if (amazonSignOut) amazonSignOut();
else logger.debug('No Amazon signout method provided');
break;
case Constants.AUTH0:
if (auth0SignOut) auth0SignOut(payload.opts);
else logger.debug('No Auth0 signout method provided');
break;
default:
break;
}
if (!Auth || typeof Auth.signOut !== 'function') {
throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported');
}
Auth.signOut()
.then(() => {
if (!this.state.stateFromStorage) {
this.changeState('signedOut');
}
})
.catch(err => { logger.debug(err); this.error(err); });
}
handleLogout = async () => {
await Auth.signOut();
this.userHasAuthenticated(false);
this.props.history.push("/login");
}
.catch(err => {
if (!this._isMounted) {
return;
}
let cachedAuthState = null;
try {
cachedAuthState = localStorage.getItem(AUTHENTICATOR_AUTHSTATE);
} catch (e) {
logger.debug('Failed to get the auth state from local storage', e);
}
const promise =
cachedAuthState === 'signedIn' ? Auth.signOut() : Promise.resolve();
promise
.then(() => this.handleStateChange(this._initialAuthState))
.catch(e => {
logger.debug('Failed to sign out', e);
});
});
}
async function signOut() {
await Auth.signOut();
}
export const signOut = () =>
Auth.signOut().then(() => {
localStorage.removeItem('credential')
singInPerform.next(null)
})
.catch(err => {
if (!this._isMounted) { return; }
let cachedAuthState = null;
try {
cachedAuthState = localStorage.getItem(AUTHENTICATOR_AUTHSTATE);
} catch (e) {
logger.debug('Failed to get the auth state from local storage', e);
}
const promise = cachedAuthState === 'signedIn'? Auth.signOut() : Promise.resolve();
promise.then(() => this.handleStateChange(this._initialAuthState))
.catch((e) => {
logger.debug('Failed to sign out', e);
});
});
}