Only get projects belonging to user
Hi, new to this and I can't figure out how to do this:
I have a table with "users" and a table with "projects". The projects has a reference field to the user, as each project belongs to a user. In my frontend I want to ONLY show the user the projects that belongs to the user. How would I go about setting that up in Xano?
Thanks!
Answers
-
Hey @filiphartman - you'll be able to do this by filtering your projects table in the Query to say
WHERE db projects.user_id = auth ID
(When the endpoint has authentication on)
Here's some documentation around restricting access so users can only see things you intend them to:
-
Thank you! You mean like this? Is there anything else I need to add? I've added restricted access, but when I try to run the request (I'm using wized). I get back unauthorized although the request includes the auth token of the user.
-
Okay so I got it working! But right now I have a single user associated, if i change it to "list" and add another user, it won't work. What do I need to do to make it work with multiple users?
-
So if you have a list of users, your expression will change.
WHERE auth:id IN db:projects.user_id
If projects.user_id is a list (array). This is saying the authenticated user ID is in the array of user IDs.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback