imightbejesus
imightbejesus
CCConvex Community
Created by imightbejesus on 8/11/2024 in #support-community
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>
<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);
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}`,
},
});
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.
32 replies
CCConvex Community
Created by imightbejesus on 8/1/2024 in #support-community
Auth0 with convex in vanilla js PWA.
Hello. I am trying to wire up convex with auth0 in a vanilla js progressive web app. Docs seem to only cover this for a react app, and I am having trouble getting this to work in vanilla js pwa. I have added auth.config.ts file with my Auth0 provider (specifying domain and applicationID). Auth through Auth0 works fine, as I am able to get logged in. In my convex query I added the following check:
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Unauthenticated call");
}
}
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Unauthenticated call");
}
}
However the identity in the code above is always null, even though the user is logged in. What am I missing? Thanks in advance.
2 replies