Closed
Description
Hello, its is not possible to auth using httpAction
useEffect(() => {
const fetchData = async () => {
const token = await authData.getToken();
const response = await fetch(`${CONVEX_SITE_URL}/api/chat`, {
method: "POST",
body: JSON.stringify({ messages: [] }),
headers: {
Authorization: `Bearer ${token}`,
},
});
console.log(response);
};
fetchData();
}, [token]);
Will have no more Authorization headers inside the req once it reach httpAction and no identiry
export const chat = httpAction(async (ctx: ActionCtx, req) => {
// Extract the `messages` and organizationId from the body of the request
const { messages, organizationId } = await req.json();
const userIdentity = await ctx.auth.getUserIdentity(); // This is null NULL
}
But on the doc it says it should. https://docs.convex.dev/auth/functions-auth#http-actions
You can also access the user identity from an HTTP action ctx.auth.getUserIdentity(), by calling your endpoint with an Authorization header including a JWT token:
myPage.ts
const jwtToken = "...";
fetch("https://<deployment name>.convex.site/myAction", {
headers: {
Authorization: `Bearer ${jwtToken}`,
},
});
Metadata
Metadata
Assignees
Labels
No labels