Back

[SOLVED] Creating collection with Server SDK and reading from it on Client SDK

  • 0
  • Flutter
  • Functions
  • Cloud
Hassanmrwt
16 May, 2023, 18:53

I am creating collection by function execution and then check if execution was successful then get its documents but hence leads to unauthorized_scope error. Remember users permissions are provided in server side function execution. After HotReload everything works fine and same user can get all documents from newly created Collection.

TL;DR
Summary: The user was trying to create a collection with attributes and indices using the Server SDK and then read from it using the Client SDK. They ran into some issues with permissions and the code not waiting for each call to complete. The problem was solved by ensuring that every call was awaited and checking the permissions settings. Solution: Await each call and ensure that permissions are set properly for the user before trying to access the newly created collection's documents. Upgrading to the latest version of the Appwrite SDK may also fix any permission migration issues.
Hassanmrwt
16 May, 2023, 18:55

I think after successful execution of functions which creates Collection, it's attributes, indices and set Permissions, "completed" status is returned while permissions are not created yet. @Moderator

D5
16 May, 2023, 18:58

Seems like the user doesnt has permission for a document?

D5
16 May, 2023, 18:59

If you have appwrite 1.3.x upgrade to the last version 1.3.4, since previous had a problem with permissions migration

safwan
16 May, 2023, 19:00

@Hassanmrwt could you share the code for this function?

Hassanmrwt
16 May, 2023, 19:02

Sure

Hassanmrwt
16 May, 2023, 19:06

Full code in file

Hassanmrwt
16 May, 2023, 19:07

Function works fine, completes it's execution but accessing newly created Collection's documents throws permissions error

safwan
16 May, 2023, 19:15

okay here's what i can think of

safwan
16 May, 2023, 19:15

in your function code, you're not await-ing every call to create attributes, etc.

safwan
16 May, 2023, 19:16

which is causing the code to jump through without even checking if the execution of each call was complete. And hence you get the status: ok

safwan
16 May, 2023, 19:16

what i would do is

Hassanmrwt
16 May, 2023, 19:17

Find a way to cheat my code Closed the code in try {

TypeScript
     from where error is thrown 

db.listDocuments() }on AppwriteException { called the same above code again and works fine }

πŸ™ˆπŸ™ˆ

safwan
16 May, 2023, 19:17

await each of these calls amd try again. might slow it down a little, but might work!

safwan
16 May, 2023, 19:18
Hassanmrwt
16 May, 2023, 19:18

Yes this could be the exact error let me go through this again and see what's happen

safwan
16 May, 2023, 19:18

not exactly a good practice for production πŸ˜…

Hassanmrwt
16 May, 2023, 19:19

Yes

safwan
16 May, 2023, 19:19

let me know! if i stop replying, I've fallen asleep πŸ˜… it's way past my bed time lmaoooo

Hassanmrwt
16 May, 2023, 19:19

Have nice dreams πŸ’€

Hassanmrwt
16 May, 2023, 19:23

Yes πŸ‘ did work πŸ‘

Hassanmrwt
16 May, 2023, 19:24

Just awaited on creating attributes and index

safwan
17 May, 2023, 05:10

Sounds good!

safwan
17 May, 2023, 05:12

[SOLVED] Creating collection with Server SDK and reading from it on Client SDK

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