Back

the current user is not authorized to perform action with createDocument

  • 0
  • Web
ahmedehab
31 Jul, 2023, 01:27

What i am doing wrong?

TL;DR
The user is not authorized to perform the createDocument action. The user needs to have a session on the browser, not just in the user dashboard. If you're creating the session server-side, make sure the same cookie is used for both Appwrite and your app. If there is no session, that would explain the error. The createDocument() function is now in the Next.js client component. Make sure you have a session on the client side, not just on the server side. Set the collection permissions to users to allow logged-in users to access it. If you're still experiencing issues, try adding the any role to the collection
Drake
31 Jul, 2023, 01:46

Can you try to add the any role to the collection?

ahmedehab
31 Jul, 2023, 02:57

It works with Any

ahmedehab
31 Jul, 2023, 03:03

Is the problem related with client-side session ?

Drake
31 Jul, 2023, 03:41

So you might not have a session then. Did you log in first?

ahmedehab
31 Jul, 2023, 03:42

I got session on server not client

ahmedehab
31 Jul, 2023, 03:42

Createdocument requires client session?

Drake
31 Jul, 2023, 03:43

How?

Drake
31 Jul, 2023, 03:43

You set the collection permissions to users. That means only logged in users (session)

ahmedehab
31 Jul, 2023, 03:44

Third photo i use next-auth with appwrite rest apis

Drake
31 Jul, 2023, 03:45

I see so this createDocument()...is that being executed server side with the session cookie?

ahmedehab
31 Jul, 2023, 03:46

No Createdocument is now in nextjs client component

Drake
31 Jul, 2023, 03:46

So if there's no session, that would explain the error.

ahmedehab
31 Jul, 2023, 03:47

Ok I understand now

Drake
31 Jul, 2023, 03:48

Btw, since you're creating the session server-side, if you have Appwrite running on a subdomain of your app and you have your app set a cookie, the same cookie should be used for both Appwrite and your app

ahmedehab
31 Jul, 2023, 03:48

So the Createdocument function work if only appwrite has the session on browser not only in user dashboard

Drake
31 Jul, 2023, 03:49

See this repo for setting the session on the server and client side: https://github.com/Meldiron/appwrite-ssr-next-js

ahmedehab
31 Jul, 2023, 03:51

Ok , thanks for explaining

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