Google Auth linking with Anon account

So, I have issue with linking my anonymous user accounts with Google provider. My process is following:

// 1) Anon user is created
if (!client.auth.isLoggedIn) {
 const user = await this._auth.loginWithCredential(new AnonymousCredential())

// 2) When user decide to login, I try to link them like that
this._auth.user.linkUserWithRedirect(new GoogleRedirectCredential()).then(user => console.log("I AM BACK", user)).catch(console.error)
// ^ this fails with following error
// error: "error exchanging access code with OAuth2 provider",
// error_code: "AuthError",
// link: ""
// }

// 3) I've found out on stack overflow that adding url to provider could solve that but I get CORS error if I try to do this
this._auth.user.linkUserWithRedirect(new GoogleRedirectCredential(window.location.href)).then(user => console.log("I AM BACK", user)).catch(console.error)
  1. I’ve also read that it may be because client IDs and secret IDs doesn’t match but I made sure 2 times that value here
    Are exactly the same as ones here
    App Services

Any idea what could still be wrong?

Hi Ondrej, I am currently trying to achieve the same. I am struggling as well.

Passing window.location.href to the provider already helped me a step further. However, after logging in to my google account I currently get redirected to with an error message:

{"error":"must start a new auth request"}

To avoid a CORS error I had to set “Allowed Request Origins” under “Settings” as mentioned here

I’ve actually gave up on that and moved to developing other features but your post gave me a little extra guidance on how to do it. Thanks for the CORS help.

1 Like