I read the Authenticate Using Google Sign-In with JavaScript and I cant see a solution for the error code auth/credential-already-in-use.
Basically I try to linkWithPopup but the user has already in another browser previously sign in so I cant link him, so I can simply just sign him in at this browser no linking needed.
That's why I get this error auth/credential-already-in-use
I have this code:
(The firebase.auth.currentUser is an anonymous signed in user)
onSocialLoginLink = provider => {
const { firebase, changeUserRole } = this.props;
firebase.auth.currentUser
.linkWithPopup(firebase[provider])
.then(res => {
if (res.credential) {
// do stuff;
}
})
.catch(error => {
if (error.code == 'auth/credential-already-in-use') {
// Here I want to directly sign in with this credential
console.log('linkWithProvider Failure, error', error);
console.log('linkWithProvider Failure, error["credential"]', error['credential']);
} else {
this.setState({ error });
}
});
};
I'm a beginner at this and I cant find in the docs how to do this.
Do I first have to sign out the anonymous user before doing signInWithPopup?
Is it possible to do this without user interaction, without signInWithPopup?
When I'm inside the .catch(error =... I know the prover like Gmail and the specific user Gmail address. I get that from error.credential
Or maybe this is a bad solution please advice?