How do I precondition on an array stored in extras?

Options

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

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    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 filter

    If 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:


  • Gorkwobbler
    Gorkwobbler Member
    edited September 2023
    Options

    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.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    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.