# Session Property Expression - Check User Roles

**URL:** <https://forum.inductiveautomation.com/t/session-property-expression-check-user-roles/73105>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [May 1, 2023, 6:54pm UTC](https://forum.inductiveautomation.com/t/session-property-expression-check-user-roles/73105 "2023-05-01T18:54:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 1, 2023, 6:54pm UTC](https://forum.inductiveautomation.com/t/session-property-expression-check-user-roles/73105/1 "2023-05-01T18:54:27Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/6/c66b1364149ed787d4ecb850067843682f974bfb.png)

Based on the [documentation](https://docs.inductiveautomation.com/display/DOC81/hasRole), would this not be a client scope expression?

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28da67c37a36936f05c72d3633771baa975c95b8.png)

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/f/0f66a40ee950b4271554ebac9d15f476086c8575.png)

Logging in does not change the result.

Using `indexOf()` instead works while logged in, but I still get "Bad\_Stale" while logged out.

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

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 1, 2023, 7:04pm UTC](https://forum.inductiveautomation.com/t/session-property-expression-check-user-roles/73105/2 "2023-05-01T19:04:41Z")

</div>

> [@amarks](#):
>
> would this not be a client scope expression?

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.

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

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 1, 2023, 7:06pm UTC](https://forum.inductiveautomation.com/t/session-property-expression-check-user-roles/73105/3 "2023-05-01T19:06:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 1, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/session-property-expression-check-user-roles/73105/4 "2023-05-01T19:09:31Z")

</div>

see my edit above

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 1, 2023, 7:10pm UTC](https://forum.inductiveautomation.com/t/session-property-expression-check-user-roles/73105/5 "2023-05-01T19:10:50Z")

</div>

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...
