Skip to content

Commit

Permalink
Merge pull request #1450 from powerful23/doc-enhancement
Browse files Browse the repository at this point in the history
Add description about how to use currentAuthenticatedUser
  • Loading branch information
powerful23 authored Aug 27, 2018
2 parents 65c7e9e + 1df7754 commit b13180e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/media/authentication_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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`.
Expand Down
2 changes: 2 additions & 0 deletions docs/media/hub_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');

}
}
Expand Down

0 comments on commit b13180e

Please sign in to comment.