-
-
Save mattdanielbrown/5a36a86cfbf1b16ab7fc19fca3497c8a to your computer and use it in GitHub Desktop.
This file contains 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
// 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