Forked from sharon-rozinsky/firebase-by-example-authenticaiton.js
Created
October 8, 2018 01:41
-
-
Save spac3unit/05f83ae2cba907fb7f4523d672746cde to your computer and use it in GitHub Desktop.
firebase-by-example: Authenticaiton
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
| var provider = new firebase.auth.GoogleAuthProvider(); | |
| document.getElementById('signIn').addEventListener('click', function (e) { | |
| firebase.auth().signInWithRedirect(provider); | |
| }); | |
| document.getElementById('signOut').addEventListener('click', function (e) { | |
| firebase.auth().signOut() | |
| .then(function () { | |
| console.log('User signed out'); | |
| }).catch(function (error) { | |
| console.error('Error while signing out: ', error); | |
| }) | |
| }); | |
| firebase.auth().getRedirectResult() | |
| .then(function (result) { | |
| if (result.credential) { | |
| console.log('Got Google Token'); | |
| } | |
| var user = result.user; | |
| console.log(user); | |
| }).catch(function (error) { | |
| console.error('Error(code: ' + error.code + ', message: ' + error.message + ')'); | |
| }); | |
| firebase.auth().onAuthStateChanged(function (user) { | |
| if (user) { | |
| document.getElementById('signedUserName').textContent = 'Signed in user: ' + user.displayName + '[email: ' + user.email + ']'; | |
| document.getElementById('userImage').src = user.photoURL; | |
| } else { | |
| document.getElementById('signedUserName').textContent = 'Signed in user: NONE'; | |
| document.getElementById('userImage').src = ''; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment