'firebase (v9) How to get 'isNewUser' info after Google redirect?

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source