Created
May 10, 2016 05:20
-
-
Save davidgilbertson/52a72f7c5e35502127e5848a8bf881b2 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