Link Search Menu Expand Document

Auth

Summary

Static Props

currentSession

CognitoUserSession {
  idToken: CognitoIdToken, refreshToken: CognitoRefreshToken, accessToken: CognitoAccessToken, clockDrift: 1}
  accessToken: CognitoAccessToken {jwtToken: "***", payload: {}}
  clockDrift: 1
  idToken: CognitoIdToken {jwtToken: "***", payload: {}}
  refreshToken: CognitoRefreshToken {token: "***"}

currentUserInfo

attributes: {sub: "***", email_verified: true, email: "***"}
id: undefined
username: "test-user"

Cook

custom attributes

try {
  const currentUserInfo = await Auth.currentUserInfo()
  const favoriteFlavor = currentUserInfo.attributes['custom:favorite_flavor']
} catch (err) {
  console.log('error fetching user info: ', err);
}
  • update
const user = await Auth.currentAuthenticatedUser();
const result = await Auth.updateUserAttributes(user, {
    'custom:favorite_flavor': 'Strawberry'
})

Signout

import { Auth } from 'aws-amplify';

Auth.signOut()
    .then(data => console.log(data))
    .catch(err => console.log(err));

// By doing this, you are revoking all the auth tokens(id token, access token and refresh token)
// which means the user is signed out from all the devices
// Note: although the tokens are revoked, the AWS credentials will remain valid until they expire (which by default is 1 hour)
Auth.signOut({ global: true })
    .then(data => console.log(data))
    .catch(err => console.log(err));