Skip to content
Sites Hackathon is live / Aug 29 - Sep 12
Back

[SOLVED] How to get user id from the executed function?

  • 0
  • Cloud
Tet
9 Nov, 2024, 19:51

I have a function that inserts a document to a collection, but I also need to get the user id of the one who invoked the function. I use client side SDK for executing the function.

I tried the following:

`const { Client, Databases, Account } = require('node-appwrite');

const appwriteClient = new Client(); const databases = new Databases(appwriteClient); const account = new Account(appwriteClient);`

but the account variable produces an error.

(role: applications) missing scope (account)

TL;DR
Solution: Developers can get the user id by using req.headers x-appwrite-user-id. This does not require additional client-side SDK configuration.
Tet
9 Nov, 2024, 20:08

nvm, i just found out about the req.headers x-appwrite-user-id

Tet
9 Nov, 2024, 20:09

[SOLVED] How to get user id from the executed function?

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