UserContext does not appear to be passed by getAut...
# support-questions-legacy
a
UserContext does not appear to be passed by getAuthorisationURLWithQueryParamsAndSetState. I tried to retrieve it with frontend ThirdPartyEmailPasswordReact.init onHandleEvent & getRedirectionUrl but userContext is empty
n
Hi @ansont , Can I see the code for what you are trying?
a
Copy code
typescript
// SignupForm.tsx
const SignupForm: React.FC = () => {
  // ...
  const onThirdPartySignup = async (providerId: string) => {
    const authUrl = await getAuthorisationURLWithQueryParamsAndSetState({
      providerId,
      authorisationURL: `${process.env.NEXT_PUBLIC_APP_URL}/auth/callback/google`,
      userContext: { test: 'abc', signup: true },
    })
    router.push(authUrl)
  }
  // ...
}

// frontendConfig.ts

frontendConfig = () => {
  return {
    appInfo,
    recipeList: [
  
        ThirdPartyEmailPasswordReact.init({
        onHandleEvent: async (context) => {
          console.log(JSON.stringify(context, null, 2))
        },
        getRedirectionURL: async (context) => {
          console.log(JSON.stringify(context, null, 2))
          return '/register'
        },
        signInAndUpFeature: {
          providers: [
            ThirdPartyEmailPasswordReact.Google.init(),
          ],
        },
      }),
      SessionReact.init(),
    ],
    // this is so that the SDK uses the next router for navigation
    windowHandler: (oI) => {
      return {
        ...oI,
        location: {
          ...oI.location,
          setHref: (href) => {
            Router.push(href)
          },
        },
      }
    },
  }
}
Returned by onHandleEvent:
Copy code
json
{
  "action": "SUCCESS",
  "isNewUser": true,
  "user": {
    "email": "xxx@gmail.com",
    "id": "2f6aad23-...",
    "timeJoined": 1669185393299,
    "thirdParty": {
      "id": "google",
      "userId": "1026..."
    }
  },
  "userContext": {}
}
Returned by getRedirectiorURL:
Copy code
json
{
  "action": "SUCCESS",
  "isNewUser": true
}
Expecting:
Copy code
json
{
  //...
  "userContext": {
     "test": "abc",
     "signup" true
  }
}
n
Right can you clarify what you are trying to accomplish? Because a couple things
getRedirectionURL
isnt a social login thing, its called when the SDKs prebuilt UI needs to redirect to a page (wont be applicable since you seem to be using custom UI?). Since
getAuthorisationURLWithQueryParamsAndSetState
does not trigger any redirection, the user context would not get passed.
If you are using Custom UI for the full flow you want to pass the user context when calling
ThirdPartyEmailPasswordReact.thirdPartySignInUp
which will then get passed to getRedirectionURL at some point
If you are using pre built UI and want access to some custom information in getReidrectionURL then you should override
thirdPartySignInUp
and pass user context to it
I can help with more specifics if you explain your use case a little
a
I'm collecting some information before getting the user to signup via google. I'd like to pass a reference of that information through the signin/up OAth2 flow so that when the user successful logs in, I can retrieve that information and link to the third party id
n
Right in that case you cant use user context, you will need to save that information in local storage and read it during/after signinup
7 Views