https://supertokens.com/ logo
h

howard

04/17/2022, 5:43 PM
Hi, I'm trying to implement supertokens into my nestjs + nextjs application with ThirdPartyEmailPassword. I encountered an error when trying to signin/signup with Google. The account is successfully signup/signin in the development environment but the /signinup api failed with status code 500 on frontend 400 on backend, then the error got displayed on the form. When reload the frontend application, it does recognize that I've logged in and redirect to the home page tho.
r

rp

04/17/2022, 5:44 PM
hey @howard can you please enable debug logging and show the logs on app start + when you make the API call that behaves weirdly.
h

howard

04/17/2022, 5:47 PM
here is the debug log.
r

rp

04/17/2022, 5:47 PM
thanks.
What's the config you have provided for google in the provider's list?
h

howard

04/17/2022, 5:52 PM
here is my supertokens.service.ts
I've tried the demo clientId and secret too but it didn't help
r

rp

04/17/2022, 5:54 PM
hmm this seems about fine
So for some reason, google is returning a 400 status code when supertokens is querying it with the auth code
h

howard

04/17/2022, 5:58 PM
yeah, I see that it still work afterwards. Can I skip the /signinup api call?
the email password works fine too
r

rp

04/17/2022, 5:59 PM
You can't skip it. Can you try this:
Copy code
let google = ThirdpartyEmailPassword.Google({...});

providers: [
                {
                    ...google,
                    get: function (redirectURI: string | undefined, authCodeFromRequest: string | undefined, userContext: any) {
                        const getResult = google.get(redirectURI, authCodeFromRequest, userContext);
                        return {
                            ...getResult,
                            getProfileInfo: async function (authCodeResponse: any, userContext: any) {
                                try {
                                    const result = await getResult.getProfileInfo(authCodeResponse, userContext);
                                    console.log(result); //<- this one has my login details (id, email, verified)
                                    return result;
                                } catch (err) {
                                    console.log(err);
                                    throw err;
                                }
                            }
                        };
                    }
                },
            ],
for the providers array
hmm. So it does get the result.
The issue is that it calls the API twice from the frontend
Are you running in react strict mode?
h

howard

04/17/2022, 6:06 PM
yeah, I am
r

rp

04/17/2022, 6:06 PM
Ah yea.. so in nextjs, weirdly, they call
useEffect
twice in development mode when react strict mode is enabled
h

howard

04/17/2022, 6:06 PM
oh, the first signinup request is not the POSR request
r

rp

04/17/2022, 6:06 PM
so it's calling the API twice
h

howard

04/17/2022, 6:07 PM
it got canceled and only contains the headers
r

rp

04/17/2022, 6:07 PM
Can you try to run this in a production build or without react strict mode?
It should work then
h

howard

04/17/2022, 6:09 PM
ok, I'll try it in the morning. Now it's 1 am in my place tho
r

rp

04/17/2022, 6:09 PM
ah alright!
h

howard

04/17/2022, 6:09 PM
thank you, I'll notice you later if there's a problem
r

rp

04/17/2022, 6:09 PM
do lmk if it solves the issue
h

howard

04/18/2022, 6:20 AM
The production build worked!
r

rp

04/18/2022, 6:20 AM
Yea! I opened an issue about this in nextjs: https://github.com/vercel/next.js/issues/36233
h

howard

04/18/2022, 6:22 AM
thank you! hope it will be resolved soon
r

rp

04/18/2022, 6:22 AM
yup! me too.. i was surprised that this wasn't an open issue already.. very strange
3 Views