How to use the @aws-amplify/auth.signOut function in @aws-amplify/auth

To help you get started, we’ve selected a few @aws-amplify/auth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TreeHacks / root / src / store / auth / actions.ts View on Github external
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;
github yhenni1989 / ReactNativeAuth / src / components / screens / SettingsScreen.js View on Github external
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() {
github TreeHacks / root / src / store / auth / actions.ts View on Github external
return dispatch => {
    loadingStart();
    console.log("signing out");
    Cache.removeItem("federatedInfo");
    localStorage.clear();
    Auth.signOut().then(e => {
      loadingEnd();
      dispatch(loggedOut());
    })
  }
}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / SignOut.jsx View on Github external
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); });
    }
github awslabs / aws-full-stack-template / assets / src / App.tsx View on Github external
handleLogout = async () => {
    await Auth.signOut();

    this.userHasAuthenticated(false);
    this.props.history.push("/login");
  }
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Authenticator.tsx View on Github external
.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);
					});
			});
	}
github josephluck / internote / ui / auth / auth.ts View on Github external
async function signOut() {
    await Auth.signOut();
  }
github systemaccounting / mxfactorial / react / src / lib / amplify.js View on Github external
export const signOut = () =>
  Auth.signOut().then(() => {
    localStorage.removeItem('credential')
    singInPerform.next(null)
  })
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Authenticator.jsx View on Github external
.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);
                    });
            });
    }