Created
June 25, 2017 16:18
-
-
Save guzmonne/43d8281b3786ace03d29a0630cb98106 to your computer and use it in GitHub Desktop.
cognito-auth.signOut.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Cognito signOut function wrapped inside a promise. | |
| */ | |
| function signOut() { | |
| User || (User = UserPool.getCurrentUser()) | |
| if (!User) { | |
| return Promise.reject('Current user session not found'); | |
| } | |
| return Promise.resolve(User.signOut()); | |
| } | |
| /** | |
| * Function that handles the signOut event. It set's the navigation inside a | |
| * setTimeout function so we can see the process working on this example. | |
| * Clearly it is not necessary to do so. | |
| */ | |
| function handleSignOut(event) { | |
| event.preventDefault(); | |
| Cognito.signOut() | |
| .then(function() { | |
| addAlert({ | |
| type: 'success', | |
| message: 'Logging out. Please wait...' | |
| }) | |
| setTimeout(function() { | |
| EventEmitter.emit('Welcome:unmount'); | |
| EventEmitter.emit('LoginForm:mount'); | |
| }, 3000) | |
| }) | |
| .catch(function(error) { | |
| addAlert({ | |
| type: 'error', | |
| message: error.message, | |
| }) | |
| console.error(error); | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment