How to use the @aws-amplify/auth.currentAuthenticatedUser 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 yhenni1989 / Zopher / src / components / Posts.js View on Github external
componentDidMount = async () => {
    await Auth.currentAuthenticatedUser()
    .then(user => {
      this.setState(
        {  
          postOwnerUsername: user.username,
          likeOwnerUsername: user.username,
          postOwnerId: user.attributes.sub,
          likeOwnerId: user.attributes.sub,
        }
      )
    })
    .catch(err => console.log(err))
    await this.listPosts()
    // Update the number of entries in the parent component: ChallengeScreen
    await this.props.countPosts()
  }
github josephluck / internote / ui / auth / auth.ts View on Github external
async function getUser() {
    if (!user) {
      console.log("Getting current authenticated user");
      user = await Auth.currentAuthenticatedUser();
    }
    return user;
  }
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Provider / withAuth0.jsx View on Github external
).then((cred) => {
                            if (onStateChange) {
                                Auth.currentAuthenticatedUser().then(user => {
                                    onStateChange('signedIn', user);
                                });
                            }
                        }).catch((e) => {
                            logger.debug('Failed to get the aws credentials', e);
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Authenticator.tsx View on Github external
checkUser() {
		if (!Auth || typeof Auth.currentAuthenticatedUser !== 'function') {
			throw new Error(
				'No Auth module found, please ensure @aws-amplify/auth is imported'
			);
		}
		return Auth.currentAuthenticatedUser()
			.then(user => {
				if (!this._isMounted) {
					return;
				}
				this.handleStateChange('signedIn', user);
			})
			.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);
				}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Greetings.tsx View on Github external
findState() {
		if (!this.props.authState && !this.props.authData) {
			Auth.currentAuthenticatedUser()
				.then(user => {
					this.setState({
						authState: 'signedIn',
						authData: user,
						stateFromStorage: true,
					});
				})
				.catch(err => logger.debug(err));
		}
	}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Provider / withGoogle.tsx View on Github external
!Auth ||
				typeof Auth.federatedSignIn !== 'function' ||
				typeof Auth.currentAuthenticatedUser !== 'function'
			) {
				throw new Error(
					'No Auth module found, please ensure @aws-amplify/auth is imported'
				);
			}

			await Auth.federatedSignIn(
				'google',
				{ token: id_token, expires_at },
				user
			);

			user = await Auth.currentAuthenticatedUser();

			if (onStateChange) {
				onStateChange('signedIn', user);
			}
		}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / SignOut.jsx View on Github external
findState(){
        if (!this.props.authState && !this.props.authData) {
            Auth.currentAuthenticatedUser()
            .then(user => {
                this.setState({
                    authState: 'signedIn',
                    authData: user,
                    stateFromStorage: true
                })
            })
            .catch(err => logger.error(err));
        } else if (this.props.stateFromStorage) {
            this.setState({
                stateFromStorage: true
            })
        }
    }