Hey! I’m building an API Workflow that will be used by an external app, but I’m having a problem with privacy rules.
Basically, I have two tables: Teacher and Products. Each product has a owner(teacher), and each teacher has a user. A product is only visible for a user if it’s owner’s user is the current user, as you can see right here:
So I created an API Workflow that log the user in, and return if it has a product. By default, I would only have to do a search for the products and filter by the product I want to check, right?
The problem is, it’s not returning anything, it’s like the current user doesn’t have permission to see any product. Even when I return a search without any constraints it doesn’t return anything, I’m having to check the “Ignore privacy rules” box for it to work, but it’s not really good for performance, so I wanted to make it work just with privacy rules.
I actually can’t, because I do the authentication on this same Workflow.
My process is like this:
I call this endpoint on my external app, passing the parameters.
I log the user in using the parameters.
Then I do the search.
If I understood correctly the privacy rules and the API authentication, it shoud be working.
By the way, I also tried to split this workflow, making a workflow that can be run without authentication and log the user in, then I use the token and call another workflow, and also didn’t work.
The strange thing is that if I return any other data, the user name for example, it works just fine, it seems to be really a privacy rule problem.
How do you log in the user? You cannot do that in the same workflow. You need to do that in a separate workflow, this will return an access token that can be used in header after.
Are you following that:
Got a deeper look to your screenshot… doesn’t seem to have any “authentication” error right? Just data not returned as it should? (based on the auth/privacy rules)
Have a backend workflow for logging in a user which has an ‘email’ and ‘password’ parameter
Log the user in action
When called, this will return a cookie that can be used to authenticate a subsequent request to whatever other backend workflow you actually want to call.
What data are you returning from the API? And try adding the token as a ‘Cookie’ header rather than Authorization. You won’t need ‘Bearer’ before either.
As for the header, I don’t really think it would change anything, because it’s not an authentication problem, if I return the current user name or email, it works, it just doesn’t return the data.
Now I tried showing the products on a repeating group and logged in as the user I’m using, and it looks like the user really doesn’t have acess to the data. So it’s really a privacy rules problem, I just don’t know what. Is there anything wrong with the privacy rules?:
I’m using 3 data types: User, Teacher and ProductStock. The product stock has an owner, that is a Teacher. The teacher has a user, that is a user. And if I’m not crazy, the rule is saying that when a ProductStock’s owner’s user is the logged user, the ProductStock is visible. I need this privacy rule because the users can’t see each others products.
Am I doing something wrong or forggeting to do something?
Is there any other workaround? I would have to create a user field on each table that uses a similar rule, just for that, or I would have to change the entire relationship to use the current user instead of the teacher, which isn’t really semantic, because I have multiple types of users, and the teacher is only one of them.