Skip to content

Instantly share code, notes, and snippets.

@christianmalek
Forked from paulbreslin/save-auth.js
Created July 24, 2017 10:33
Show Gist options
  • Save christianmalek/f0d8d6c69ce2b50a976e2fe87b4f3280 to your computer and use it in GitHub Desktop.
Save christianmalek/f0d8d6c69ce2b50a976e2fe87b4f3280 to your computer and use it in GitHub Desktop.
firebase.auth().onAuthStateChanged( user => {
if (user) {
// If user state changes and 'user' exists, check Firebase Database for user
const userReference = db.ref(`users/${user.uid}`);
userReference.once('value', snapshot => {
if (!snapshot.val()) {
// User does not exist, create user entry
userReference.set({
email: user.email,
displayName: user.displayName
});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment