[Symbol(Response internals)]: { url: 'https://...
# support-questions-legacy
l
[Symbol(Response internals)]: { url: 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json', status: 401, statusText: 'Unauthorized', headers: Headers { [Symbol(map)]: [Object: null prototype] }, counter: 0 } I am using signin using google using my custom ui and my backend is giving this error
r
hey @Lucifer979
can you enable backend debug logs and show the output of the api call?
l
How can I do that?
r
search in our docs for debug logs
l
I checked the network tab of my browser, it is calling the /auth/signinup url twice, could it be the issue?
r
Yea. Most likely
That happens cause useEffect in react runs twice in dev build, strict mode.
l
Okay
How I can resolve it?
async function handleGoogleCallback() { console.log(window.location.href); try { const response = await thirdPartySignInAndUp(); console.log("Calback Response: ", response); // console.log("Response headers ", response.headers.get("Set-Cookie")); if (response.status === "OK") { console.log(response.user) if (response.createdNewUser) { console.log("SignUp sucess"); // sign up successful } else { console.log("Signin Success"); // window.location.assign("/Login"); // sign in successful } window.location.assign("/Home"); } else { // SuperTokens requires that the third party provider // gives an email for the user. If that's not the case, sign up / in // will fail. // As a hack to solve this, you can override the backend functions to create a fake email for the user. window.alert("No email provided by social login. Please use another form of login"); window.location.assign("/Login"); // redirect back to login page } } catch (err) { if (err.isSuperTokensGeneralError === true) { // this may be a custom error message sent from the API by you. window.alert(err.message); } else { window.alert("Oops! Something went wrong."); } } }
This is my handle callback function
r
this is more of a react issue. You might want to google it or talk to someone in the react community
l
Okay
r
you can do something like this with useEffect to run the handleGoogleCallback just once:
Copy code
import React, { useEffect, useRef } from 'react';

function MyComponent() {
  const isInitialRender = useRef(true);

  useEffect(() => {
    if (isInitialRender.current) {
      isInitialRender.current = false;
      return;
    }

    handleGoogleCallback()
  }, []); // Empty dependency array

  // Your component's JSX...
}
7 Views