Skip to content

Instantly share code, notes, and snippets.

@guzmonne
Created June 25, 2017 16:18
Show Gist options
  • Select an option

  • Save guzmonne/43d8281b3786ace03d29a0630cb98106 to your computer and use it in GitHub Desktop.

Select an option

Save guzmonne/43d8281b3786ace03d29a0630cb98106 to your computer and use it in GitHub Desktop.
cognito-auth.signOut.js
/**
* 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