Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattdanielbrown/5a36a86cfbf1b16ab7fc19fca3497c8a to your computer and use it in GitHub Desktop.
Save mattdanielbrown/5a36a86cfbf1b16ab7fc19fca3497c8a 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