Created
June 25, 2017 16:13
-
-
Save guzmonne/23d266ee3dd4090a63f40adf214b641d to your computer and use it in GitHub Desktop.
cognito-auth.Welcome-mount.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
| /** | |
| * Function to handle the display of the Welcome function only for authenticated | |
| * users. If they are not authenticated, or an error occurs, we'll redirect them | |
| * to the login page. | |
| */ | |
| EventEmitter.on('Welcome:mount', function() { | |
| // Check if the user is authenticated. | |
| Cognito.isAuthenticated() | |
| .then(function() { | |
| // Mount the component on the DOM. | |
| $root.appendChild($container); | |
| // Show the loading banner. | |
| loading(); | |
| // Get the user data. | |
| Cognito.getUser() | |
| .then(function(user) { | |
| // Toggle the loading banner for the Welcome template. | |
| $container.innerHTML = tmpl('Welcome', user); | |
| $button = $container.getElementsByTagName('button')[0]; | |
| $button.addEventListener('click', handleSignOut); | |
| }) | |
| }) | |
| // Handle any errors that pop up and redirect the user to the login page. | |
| .catch(function(error) { | |
| redirectToLoginPage({ | |
| type: 'error', | |
| message: error.message, | |
| }) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment