Skip to content

httpAction Authorization Bearer is broken #58

Closed
@adelin-b

Description

@adelin-b

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions