How do I precondition on an array stored in extras?
Hi,
I have my user tables set up with relationships as follows:
users - 1…* - user_roles - 1…1 - roles - 1…* - role_functions - 1…1 - user_functions
In other words, user has a set of roles. Each role has a set of related user_functions.
I believe I have auth.extras set up to include a list of allowed user functions. It should be looking like this:
{
"allowed_user_functions": [
{"function_name": "edit_users"},
{"function_name": "upload"}
]
}
Whenever I try to print or query the extras I get an access denied error from run/debug. I surmise the auth.extras can only be used in the "Precondition" operator? Is that a correct assumption? I also tried to decode the auth token using the site jwt.io but the payload came back as gibberish.
I tried to set up a Precondition to check auth.extras, but it's not clear to me how to set up the preconditon to check against a list. The auth.extras should (theoretically, if it's working as intended) look like this:
Questions:
- How can I see the contents of auth.extras for debugging?
- Am I correct in assuming that only Precondition can access auth.extras?
- How do I set up a Precondition that checks for items in a list like the one given above?
If it matters, I am using email login currently for testing.
Answers
-
Hi @Gorkwobbler -
To see the contents of extras, you can set a variable as extras in your function stack
Extracting components from extras, would be exactly like treating it like a variable with dot notation:
For checking with the values in the array, it depends on what you're comparing. If you are checking for a single (Scalar) value to be inside an array then you want to use the IN filterIf you're comparing two arrays then there's an extra filter, where you'd use the intersect filter between the two arrays and then add a count, which gets the count of the resulting array. You can then compare that to be greater than 0 (or equal to). It'd look something like this:
-
Hi, Michael,
Thanks for your help. I was able to show the extras in the debugger like you showed. I determined that this doesn't work within a custom function but it works when I run the function within an API request.
I don't understand the part about the "in/intersect" operator. I don't see this option in my condition editor when I go to set up a precondition. My editor has no "add filter" button like the one in your screenshot.
-
The "add filter" doesn't show up until you move your mouse over the black text entry box (in this case, where it says "extras.stuff". Xano has some of these "reveal" UI touches - moving your mouse around the screen will let you see more of what is available to you.
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