When linking credentials to a user account as described
here - the Firebase team’s example seems to be incorrect:
// Get reference to the currently signed-in user
var prevUser = auth.currentUser;
// Sign in user with another account
auth.signInWithCredential(credential).then(function(user) {
console.log("Sign In Success", user);
var currentUser = user;
// Merge prevUser and currentUser data stored in Firebase.
// Note: How you handle this is specific to your application
// After data is migrated delete the duplicate user
return user.delete().then(function() {
// Link the OAuth Credential to original account
return prevUser.linkWithCredential(credential);
}).then(function() {
// Sign in with the newly linked credential
return auth.signInWithCredential(credential);
});
}).catch(function(error) {
console.log("Sign In Error", error);
});
For one, the
user variable in the line:
return user.delete().then(function() {
does not have a .delete function, it would need to be user.user.delete()
& in this example they suggest:
// Merge prevUser and currentUser data stored in Firebase
which in this auth context (& assuming basic security rules enabled) would mean you would only have access to
currentUser ’s storage, but then they delete the current user & link the credential to the previous user. In otherwords you would only be able to merge the previous user’s data into the current user’s storage, however the current user is deleted & no longer accessible
So I’d just like a sanity check here that this example is indeed a flawed approach!