Back

Collection permissions issue with Cloud Functions

  • 0
  • Web
  • Cloud
SanjivJais
19 Aug, 2024, 14:03

I'm trying to fetch some documents from a collection called transactions using a cloud function. It works fine when the permission is set to 'Any' in the collection; however, shows an error SyntaxError: Unexpected end of JSON input when the permission is set to Users.

I have implemented GoogleOAuth and executing the function from the client using Client SDK. Why it works when permission is set to Any and doesn't work when set to Users even though I'm logged in in the app?

Doesn't the collection authenticate that its documents are being accessed by a registered user through cloud function?

This is the first time I'm trying to implement Cloud Function in Appwrite 🙂

@faye @Steven

TL;DR
Developers discussing permission issues with Cloud Functions when accessing documents from a collection. Error occurs when permission is set to 'Users' but works fine when set to 'Any'. One developer using GoogleOAuth for authentication. Solutions: Check JWT token with `req.headers["x-appwrite-user-jwt"]` when user is logged in. Make sure Cloud Function is properly authenticated with the collection.
faye
19 Aug, 2024, 14:05

You are using next.js, yeah?

faye
19 Aug, 2024, 14:07
SanjivJais
19 Aug, 2024, 14:16

It's React

SanjivJais
19 Aug, 2024, 14:17

Yeah, I read it.. but couldn't understand exactly what to do as I'm not using JWT, rather using GoogleOAuth for authentication.

faye
19 Aug, 2024, 14:18

If the user is logged in in your app, it means the user has a JWT token automatically. You can get the JWT token by using req.headers["x-appwrite-user-jwt"], at least there should be (if the user is logged in), try to log it and see if something pops up.

SanjivJais
19 Aug, 2024, 14:19

Sure, thanks

SanjivJais
19 Aug, 2024, 14:20

Will reach out if something is intangible for me 🙂

faye
19 Aug, 2024, 14:20

You can also log the entire req response, it has some other info you might or might not think is useful, like the userId etc.

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