Back

I am not allowed to set header for x-appwrite-user-ud in postman

  • 0
  • Functions
Mosh Ontong
2 Dec, 2023, 17:17
TypeScript
  const { clinicRef, patientRef }: CreateConsultationData = req.body;
  const databases = new Databases(client);
  const teams = new Teams(client);
  const functions = new Functions(client);

  const { "x-appwrite-user-id": creator }: RequestHeaders = req.headers;

  log(JSON.stringify(req.headers));

  if (!creator) {
    return res.send(
      JSON.stringify({
        message: "x-appwrite-user-id header is required",
      }),
      404,
      {
        "content-type": "application/json",
      }
    );
  }

The result is the second image

TL;DR
Issue: The user is unable to set the header for 'x-appwrite-user-ud' in Postman. Solution: The user can try using the header 'user-id' as an alternative solution. However, this header may not work for unauthenticated requests. It is recommended to use the Appwrite REST API for proper authentication. Additionally, it is not allowed to use headers containing 'x-appwrite' in the provided Appwrite domain.
Mosh Ontong
2 Dec, 2023, 17:20

How to set a header on provided domain of specific appwrite?

Mosh Ontong
2 Dec, 2023, 17:35

I see I am not allowed to use that contains x-appwrite

Drake
2 Dec, 2023, 18:07

Of course...it's automatically set by Appwrite

Drake
2 Dec, 2023, 18:07

Do you have to use that function domain?

Mosh Ontong
2 Dec, 2023, 18:10

nope just for testing

Mosh Ontong
2 Dec, 2023, 18:10

I know that we have the rest api for function, but this makes me easy to set up hehe

Drake
2 Dec, 2023, 18:11

When you execute a function like this, it's an unauthenticated request so Appwrite doesn't pick up the user and it doesn't set the user id and JWT headers

Mosh Ontong
2 Dec, 2023, 18:12

ohh I see I implement this as my alternative solution

TypeScript
  const { "x-appwrite-user-id": userId, "user-id": backup }: RequestHeaders =
    req.headers;
  const databases = new Databases(client);

  const authorId = userId || backup;

  if (!authorId) {
    return res.send(
      JSON.stringify({
        message: "either x-appwrite-user-id or user-id header is required",
      }),
      404,
      {
        "content-type": "application/json",
      }
    );
  }

I added user-id just for testing so I can use it to my postman

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more