imightbejesusI
Convex Community2y ago
37 replies
imightbejesus

await ctx.auth.getUserIdentity() returns null in http action

I have a react app and using Auth0.
  <React.StrictMode>
    <Auth0Provider
      domain={auth0_domain || ""}
      clientId={auth0_clientId || ""}
      authorizationParams={{
        redirect_uri: window.location.origin,
      }}
      useRefreshTokens={true}
      cacheLocation="localstorage"
    >
      <ConvexProviderWithAuth0 client={convex}>
        <App/>
      </ConvexProviderWithAuth0>
    </Auth0Provider>
  </React.StrictMode>


I am able to authenticate the user and get access token from Auth0, however when I pass this token to Authorization header of a request to http action, in my http action - await ctx.auth.getUserIdentity() returns null.

  const { getAccessTokenSilently } = useAuth0();
  let token: string;
  getAccessTokenSilently().then(t => token = t);

 await fetch(`${convexSiteUrl}/chat`, {
      method: "POST",
      body: JSON.stringify(requestBody),
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${token}`,
      },
    });

What am I missing here?
Thanks in advance.
Was this page helpful?