Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description about how to use currentAuthenticatedUser #1450

Merged
merged 3 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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