If you really want to use signInWithPopup
method, you have this option,
but it's not the best way. when you are signing in with google, signInWithPopup
method returns a promise. you can access the isNewUser
property in additionalUserInfo
from resulting object. then delete the user you just created.
firebase.auth().signInWithPopup(provider).then(
function (result) {
var token = result.credential.accessToken;
var user = result.user;
//this is what you need
var isNewUser = result.additionalUserInfo.isNewUser;
if (isNewUser) {
//delete the created user
result.user.delete();
} else {
// your sign in flow
console.log('user ' + user.email + ' does exist!');
}
}).catch(function (error) {
// Handle Errors here.
});
This is the easy way but deleting after creating is not the best practice. There is an another option,
you can use, signInAndRetrieveDataWithCredential
method for this. accoriding to the docs,
auth/user-not-found
will be Thrown if signing in with a credential fromfirebase.auth.EmailAuthProvider#credential
and there is no user corresponding to the given email.
function googleSignInWithCredentials(id_token) {
// Build Firebase credential with the Google ID token.
var credential = firebase.auth.GoogleAuthProvider.credential(id_token);
// Sign in with credential from the Google user.
firebase.auth().signInAndRetrieveDataWithCredential(credential)
.then(function (userCredential) {
//sign in
console.log(userCredential.additionalUserInfo.username);
}).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
if (errorCode === 'auth/user-not-found') {
//handle this
} else {
console.error(error);
}
});
}
here is an example from firebase github repo.
I am looping through elements using jQuery like this: $(".myelement").each(function() { $element = $(this).closest(".panel").attr("id"); console.log($element); }); This is working correctly and ...
I am looping through elements using jQuery like this: $(".myelement").each(function() { $element = $(this).closest(".panel").attr("id"); console.log($element); }); This is working correctly and ...
I am getting problem to save my form data in the database. I am done small code on that which is shown below, when i enter data in form and click on my submit button it not work. $(".btn").click(...
I am getting problem to save my form data in the database. I am done small code on that which is shown below, when i enter data in form and click on my submit button it not work. $(".btn").click(...
Please help me to write a function to compute the square root of positive real numbers using the formula: x i+1 = (1/2) * (xi + (A / x1)), where 'A' - input real number. On the zero iteration next ...
Please help me to write a function to compute the square root of positive real numbers using the formula: x i+1 = (1/2) * (xi + (A / x1)), where 'A' - input real number. On the zero iteration next ...
On my server side I have socket server listening and in my own laptop I have socket.io-client service and whenever I turn on both they are connecting. And when other people request to my server, ...
On my server side I have socket server listening and in my own laptop I have socket.io-client service and whenever I turn on both they are connecting. And when other people request to my server, ...