How to use the aws-amplify.Auth.currentAuthenticatedUser function in aws-amplify

To help you get started, we’ve selected a few aws-amplify 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 aws-samples / aws-appsync-chat / src / mobx / UserStore.js View on Github external
async init() {
    try {
      const user = await Auth.currentAuthenticatedUser()
      this.username = user.username
      this.email = user.signInUserSession.idToken.payload.email
    } catch (err) {
      console.log('error getting user data... ', err)
    }
    console.log('username:', this.username)
    // check if user exists in db, if not then create user
    if (this.username !== '') {
      this.checkIfUserExists(this.username)
    }
  }
github smoghal / cognito-amplify-custom-auth / src / actions / auth_actions.js View on Github external
return function(dispatch) {
    console.log('actions.validateUserSession()');

    Auth.currentAuthenticatedUser()
      .then(currentAuthUser => {
        console.log('actions.validateUserSession():Auth.currentAuthenticatedUser() currentAuthUser:', currentAuthUser);
        // grab the user session
        Auth.userSession(currentAuthUser)
          .then(session => {
            console.log('actions.validateUserSession():Auth.userSession() session:', session);
            // finally invoke isValid() method on session to check if auth tokens are valid
            // if tokens have expired, lets call "logout"
            // otherwise, dispatch AUTH_USER success action and by-pass login screen
            if (session.isValid()) {
              // fire user is authenticated
              dispatch({ type: AUTH_USER });
              //history.push('/');
            } else {
              // fire user is unauthenticated
              dispatch({ type: UNAUTH_USER });
github kkemple / journey / src / App.js View on Github external
const checkLoggedIn = () => {
    Auth.currentAuthenticatedUser()
      .then(data => {
        const user = { username: data.username, ...data.attributes };
        setState({ isLoggedIn: true, user });
      })
      .catch(error => console.log(error));
  };
github dabit3 / amplify-auth-demo / src / App.js View on Github external
async function checkUser(dispatch) {
  try {
    const user = await Auth.currentAuthenticatedUser()
    console.log('user: ', user)
    dispatch({ type: 'setUser', user })
  } catch (err) {
    console.log('err: ', err)
    dispatch({ type: 'loaded' })
  }
}
github pjay79 / MoviesApp / app / screens / LoadingScreen.js View on Github external
checkUser = async () => {
    await Auth.currentAuthenticatedUser()
      .then((user) => {
        this.props.navigation.navigate(user ? 'App' : 'Auth');
        console.log('Cognito: ', user);
      })
      .catch((error) => {
        this.props.navigation.navigate('Auth');
        console.log(error.message);
      });
  };
github odyssy-automaton / pocket-moloch / src / components / account / AccountList.js View on Github external
const _accountDevices = await currentUser.sdk.getConnectedAccountDevices();
          setIsThisDeviceAdded(
            _accountDevices.items.some(
              (item) =>
                item.device.address === currentUser.sdk.state.deviceAddress,
            ),
          );

          setAccountDevices(
            _accountDevices.items.filter((item) => {
              return (
                item.device.address !== currentUser.sdk.state.deviceAddress
              );
            }),
          );
          const user = await Auth.currentAuthenticatedUser();
          const userAttributes = await Auth.userAttributes(user);
          setWaitingSdk(false);
          if (
            userAttributes.find((item) => item.Name === 'custom:named_devices')
          ) {
            setParsedNamedDevices(
              JSON.parse(
                userAttributes.find(
                  (item) => item.Name === 'custom:named_devices',
                ).Value,
              ),
            );
          }
        } catch (error) {
          console.error(error);
          setWaitingSdk(false);
github aws-samples / connected-drink-dispenser-workshop / dispenser_app / src / views / auth / SignIn.vue View on Github external
async isUserSignedIn() {
      try {
        const userObj = await Auth.currentAuthenticatedUser();
        this.signedIn = true;
        console.log(userObj);
      } catch (err) {
        this.signedIn = false;
        console.log(err);
      }
    },
    loginUser() {
github aws-amplify / amplify-js / packages / aws-amplify-react-native / src / Auth / Authenticator.js View on Github external
checkUser() {
		const { authState } = this.state;
		const statesJumpToSignIn = ['signedIn', 'signedOut', 'loading'];
		Auth.currentAuthenticatedUser()
			.then(user => {
				if (!this._isMounted) return;
				if (user) {
					this.checkContact(user);
				} else {
					if (statesJumpToSignIn.includes(authState)) {
						this.handleStateChange(this._initialAuthState, null);
					}
				}
			})
			.catch(err => {
				if (!this._isMounted) return;
				logger.debug(err);
				if (statesJumpToSignIn.includes(authState)) {
					Auth.signOut()
						.then(() => {
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Greetings.jsx View on Github external
checkUser() {
        const that = this;
        const { authState } = this.state;
        return Auth.currentAuthenticatedUser()
            .then(user => {
                if (!that._isMounted) { return; }
                if (authState !== 'signedIn') {
                    this.setState({
                        authState: 'signedIn',
                        authData: user
                    });
                    this.changeState('signedIn', user);
                }
            })
            .catch(err => {
                if (!that._isMounted) { return; }
                if (!authState || authState === 'signedIn') {
                    this.setState({ authState: 'signIn' });
                    this.changeState('signIn');
                }
github aws-amplify / amplify-js / packages / aws-amplify-react-native / src / Auth / Authenticator.js View on Github external
checkUser() {
        Auth.currentAuthenticatedUser()
            .then(user => {
                const state = user? 'signedIn' : 'signIn';
                this.handleStateChange(state, user)
            })
            .catch(err => {
                this.handleStateChange('signIn', null);
                logger.error(err);
            });
    }