Back

How to get user in fuction

  • 0
  • Functions
Q T
30 Jan, 2024, 21:19

i want to get the user id of the requestor inside a function. How can i achive this?

TL;DR
Developers are discussing how to get the user ID of the requester inside a function. It is mentioned that the user ID can be obtained from the header 'x-appwrite-user-id' using the following code: ```js const headers = req.headers const userId = headers['x-appwrite-user-id']; ... ``` The solution provided should allow the developer to retrieve the user ID of the requester.
Kenny
30 Jan, 2024, 21:21

You can get it from the header x-appwrite-user-id

Q T
30 Jan, 2024, 21:23

Okay, sorry for not reading the docs. does the overlaying framework fill this field?

Kenny
30 Jan, 2024, 21:25

Not really, if you want the id of the user that triggered the function you can do something like this.

TypeScript
const headers = req.headers
const userId = headers['x-appwrite-user-id'];
...
Q T
30 Jan, 2024, 21:27

is this field validated tho? link, can someone just send a request with an existing user id in this field an the function will accept it?

Kenny
30 Jan, 2024, 21:29

https://discord.com/channels/564160730845151244/564160731327758347/1201964884762558524

Here is a discussion someone else had with the same question earlier today, beyond this I'm not entirely sure if it's validated.

D5
30 Jan, 2024, 21:56

From what I understand from the source code, it's being validated server side to ensure it's not being spoofed: https://github.com/appwrite/appwrite/blob/47ea083ea4bac0b2299b0b8d3fbe7648dac44af7/app/controllers/api/functions.php#L1573

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