cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AdamH
Helper IV
Helper IV

Restrict Access to screens

Hi All,

 

I am trying to restrict access to parts of my app by using this code:

 

If(User().Email = "user.emai1@email.com" Or "user.email2@email.com" Or "user.email3.email.com" Or "user.email4@email.com", Set(isAdmin,true),Set(isAdmin,false)); If(isAdmin,Navigate(myscreen,none),Set(ShowAccessError,true))

 

I'm not sure if this is the best way to go around this though. I want to try and keep away from passwords as I am using the office365 connector within the app. 

 

Any thoughts?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @AdamH ,

Just change OnStart to this

Set(gblUser,User());
If(
   LookUp(
      YourSPRefList,
      YourEmailField=gblUser.Email
   ).Status = "Admin",
   Navigate(myscreen,none),
   Set(ShowAccessError,true)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

10 REPLIES 10
WarrenBelz
Super User III
Super User III

Hi @AdamH ,

You could also keep a list of user's emails and their Status (which is what I do) - you then simply do a LookUp at App OnStart

Set(gblUser,User());
Set(
   gblAdmin,
   Lookup(
      YourSPRefList,
      YourEmailField=gblUser.Email
   ).Status = "Admin"
)

This will return true to the Variable gblAdmin if their status is Admin, false if not. \p>Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

I did look at creating a SP List but at the time, could not find any information on how to code authentication check.

 

I might have to look at this option and re-think the App as the option I went for does not seem to like the "email@email.com" Or "email1@email.com" Or "email2@email.com" Or "email3@email.com", approach. 

@WarrenBelz 

 

Started to look at this idea Warren, but I am getting an error:

 

2021-04-14 00_04_20-Window.png

This is the App - OnStart 

 

My SP List is: NC Codes Admin

Email Field is: Email

Status Field is: Status

 

 

Hi @AdamH ,

Missing a bracket - now corrected on my post

Set(gblUser,User());

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz 

Yeah that fixed it. I was trying to add another bracket at the end!

 

Now I have that working, If I wanted to show a button when user = Admin, allowing admin into certain screens?

 

 

Hi @AdamH ,

Just change OnStart to this

Set(gblUser,User());
If(
   LookUp(
      YourSPRefList,
      YourEmailField=gblUser.Email
   ).Status = "Admin",
   Navigate(myscreen,none),
   Set(ShowAccessError,true)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

WarrenBelz
Super User III
Super User III

Hi @AdamH ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

AdamH
Helper IV
Helper IV

@WarrenBelz 

Sorry I have not been able to reply, was away having some R&R.

 

I tried your suggestion but was having an issue with part of the code 

YourEmailField=gblUser.Email
).Status = "Admin",

I had a SP list setup and had the data fields setup, but for some reason, it was not wanting to recognise gblUser.Email and ).Status = "Admin",

 

I needed a really really quick fix with this so I just decided to do:

App > Onstart: Set(varUserEmail, User().Email)

and then went into the visible properties of my buttons and used varUserEmail = "User@email.com" Or varUserEmail = "User1@email.com" and so on. 

 

Not the perfect solution, as when a manager changes we have to edit the code rather than just add or remove a name from the SP List. 

 

Something I needed to roll out quick and will probably work on the SP List part of it more soon. 

 

@AdamH ,

That is the same thing OnStart - I just used the gbl as it is a Global Variable (gblUser.Email is actually User().EMail, but also allows gblUser.FullName if you need it for a Delegable query).

I assume here you did not actually use YourEmailField in the code (rather the actual email field name from the List I assume you created).

 

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (54,269)