Session Property Expression - Check User Roles

I want to create a session prop to check for a specific role. Tried using the hasRole() expression function within a binding. However, I get an expression error if I don't supply the username and usersource:

Based on the documentation, would this not be a client scope expression?

Defining the username and usersource does not seem to have the desired effect during runtime:

Not logged in, so this expression should evaluate to false (this screenshot is from the designer).
These fields are only enabled when this property is true, but I'm getting a "Bad_Stale" quality.
image

Logging in does not change the result.

Using indexOf() instead works while logged in, but I still get "Bad_Stale" while logged out.

if(indexOf({this.props.auth.user.roles},"Operator") = -1,false,true)

In Vision it would be, but not in Perspective. Perspective client scripts/bindings run on the gateway. I use the hasRole() expression function in a perspective project without any problems, while including the username and usersource params.

hasRole(
    "Managers",
	{session.props.auth.user.userName},
	"Sewing"
)

Do you pass the username using {this.props.auth.user.userName} ?

see my edit above

Looks like I did nothing wrong...

Deleted my bindings to the session prop.
Deleted the session prop.
Recreated the session prop and bindings.
Now it works...

2 Likes