From 0e51ddfb759147672fb4a708a2c87939ca931c64 Mon Sep 17 00:00:00 2001 From: powerful23 Date: Wed, 15 Aug 2018 10:02:31 -0700 Subject: [PATCH] add description about how to use currentAuthenticatedUser --- docs/media/authentication_guide.md | 13 +++++++++++++ docs/media/hub_guide.md | 2 ++ 2 files changed, 15 insertions(+) diff --git a/docs/media/authentication_guide.md b/docs/media/authentication_guide.md index 4e45c0beb34..6ca553de547 100644 --- a/docs/media/authentication_guide.md +++ b/docs/media/authentication_guide.md @@ -223,6 +223,19 @@ Auth.forgotPasswordSubmit(username, code, new_password) .catch(err => console.log(err)); ``` +#### Retrieve Current Authenticated User + +You can call `Auth.currentAuthenticatedUser()` to get the current authenticated user object. +```js +import { Auth } from 'aws-amplify'; + +Auth.currentAuthenticatedUser() + .then(user => console.log(user)); + .catch(err => console.log(err)); +``` +This method can be used to check if a user is logged in when the page is loaded. It will throw an error if there is no user logged in. +This method should be called after the Auth module is configured. To ensure that you can listen on the auth events `configured`. [Learn how to listen on auth events.]({%if jekyll.environment == 'production'%}{{site.amplify.baseurl}}{%endif%}/media/hub_guide#listening-authentication-events) + #### Retrieve Current Session `Auth.currentSession()` returns a `CognitoUserSession` object which contains JWT `accessToken`, `idToken`, and `refreshToken`. diff --git a/docs/media/hub_guide.md b/docs/media/hub_guide.md index 9ce681c4121..68552128450 100644 --- a/docs/media/hub_guide.md +++ b/docs/media/hub_guide.md @@ -72,6 +72,8 @@ alex.onHubCapsule = (capsule) => { case 'signIn_failure': alex.error('user sign in failed'); break; + case 'configured': + alex.error('the Auth module is configured'); } }