I would like to check if the user is new after a Google redirect. Inside the signInWithEmailLink routine this works
let credential = await signInWithEmailLink(auth, email, window.location.href)
const details = getAdditionalUserInfo(credential)
const isNewUser = details.isNewUser
but logging this credential gives UserCredentialImpl and the credential after the redirect OAuthCredential
So this doesn't work
const redirectResult = await getRedirectResult(auth)
if(redirectResult) {
try {
const credential = GoogleAuthProvider.credentialFromResult(redirectResult);
console.log('credential', credential)
const details = getAdditionalUserInfo(credential)
const isNewUser = details.isNewUser
} catch (error) {
const email = error.email;
const credential = GoogleAuthProvider.credentialFromError(error);
console.log('error while signing in with google - getting redirect result', email, credential, error)
}
}
with the IDE already complaining "Argument type OAuthCredential is not assignable to parameter type UserCredential" and the error "TypeError: Cannot read properties of undefined (reading 'isAnonymous')"
How can the .isNewUser info be read after the redirect?
I just realized that the redirectResult is of type UserCredentialImpl so this works
const redirectResult = await getRedirectResult(auth)
if(redirectResult) {
try {
const details = getAdditionalUserInfo(redirectResult)
const isNewUser = details.isNewUser
...
} catch (error) {
...
}
}