Search code examples
vuejs2google-oauthmongodb-stitch

Cannot authenticate to mongodb stitch app with google oauth


I'm working in a vue.js frontend. I can successfully make calls to stitch and write to the database if I use anonymous authentication. When I switch to Google oauth and attempt to make the same write call to the database I get the following error:

uncaught exception: t: (MustAuthenticateFirst): method called requires being authenticated

I've setup the Google Authentication Provider in the Stitch Admin console. I've created and configured a project on the Google Cloud Platform. In my vue code I've added a "login with google" button that runs this snippet:

  loginWithGoogle() {
    const googleCredential = new GoogleRedirectCredential();
    client.auth.loginWithRedirect(googleCredential);
  },

When I click to login I'm redirected to a Google form and asked to login by Google, then successfully redirected back to my app. But when I then try to write to stitch database it still says that I must authenticate first.


Solution

  • do you call de hasRedirectResult() and handleRedirectResult() when google redirect back to your app?. This method store credential locally (I guest in localstorage).