Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Created May 10, 2016 05:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidgilbertson/52a72f7c5e35502127e5848a8bf881b2 to your computer and use it in GitHub Desktop.
Save davidgilbertson/52a72f7c5e35502127e5848a8bf881b2 to your computer and use it in GitHub Desktop.
// where `db` is a `Firebase` ref
export function checkIfUserExists(authData) {
return db
.child('users')
.child(authData.uid)
.once('value')
.then(dataSnapshot => {
return Promise.resolve({
authData,
userExists: dataSnapshot.exists(),
});
});
}
// example usage
db.authWithOAuthPopup(provider)
.then(checkIfUserExists)
.then(({authData, userExists}) => {
if (userExists) {
// update user
} else {
// go create a user
}
})
.catch(err => {
console.warn('Error signing in.', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment