0

I am trying to link an anonymous mongodb stitch session to a Google account using the following code snippet from the docs:

function linkWithGoogleAccount() {
  user
    .linkUserWithRedirect(new GoogleRedirectCredential())
    .then(_=> alert("getting here"))
    .catch(console.error)
}

Further, I added http://localhost:8080 (where I develop the app) to the list of Allowed Request Origins.

With the above code, I expect to handle the OAuth redirect similar to the regular Google authentication (which works fine).

However, when the alert "getting here" is triggered I see a GET 400 error with URI https://eu-west-1.aws.stitch.mongodb.com/api/client/v2.0/app/myapp-abcde/auth/providers/oauth2-google/login?redirect=http://localhost:8080/&state=M2I...In0%3D&link=true&providerRedirectHeader=true. After accepting the alert I get redirected to localhost:8080/null.

I assume I misunderstand some aspects of the whole procedure (it's hard to debug) and would appreciate any help. Thanks!

royru
  • 13
  • 3
  • Did you specify a redirectURI in users config in mongodb dashboard? – Parth Chokshi Jun 08 '20 at 05:01
  • Hi @ParthChokshi. Thanks for asking. Yes, I read about that and use `GoogleRedirectCredential(window.location.href)`. I am now get redirected and end up on `https://eu-west-1.aws.stitch.mongodb.com/api/client/v2.0/auth/callback?state=...` with an error `{"error":"must start a new auth request"}`. – royru Jun 08 '20 at 19:35

0 Answers0