It then displays an error text and terminates the flow.
However, I can’t get this to work. It doesn’t seem to be doing the search and just logs in the user. Note, I’m still on a free plan and testing this functionality.
Why are you making it so complicated by involving states?
Just apply the condition on “Log the user in” step. Make it, Only when: Current user’s User Role is not Cancelled (to prevent the login). <<If this doesn’t work, only then should you attempt searching (getting current user is way faster than searching)
Once you’ve prevented the login, you can then show the user whatever you want later on
I think that referencing the current user in the login condition wouldn’t work since the user attempting to login isn’t the current user until after being logged in.
Review the debugger for your workflow that uses search in the login condition. I would expect that to work.
Alternatively, follow the login action immediately with a logout action that has the necessary condition.
I don’t think ‘current user’ would work. And custom state may not be needed.
Your method of searching user with email and checking user role of first item should work.
If this one is not working, I would check what is the search returning. Is search having right criteria? Are any privacy rules preventing you from getting data?
Your privacy rules don’t allow access to the User Role field, so it’s not possible to access that value in the expression: Search for Users: first item’s User Role is Not Cancelled.
(it will never be cancelled, as no value is ever returned).
So instead, add User Role is cancelled as a constraint on the Search, then check that the count of returned items is less than 1.
Just FYI, anyone can publicly find out how many users your app has, how many admins, how many cancelled users, etc. using this method. You may not find this to be problematic, but a heads-up to those who want to use this method.