916
Views
7
Comments
Solved
Show different homescreens after login for different user roles
Application Type
Reactive

Hello everyone,

I'm quite new to outsystems so I have a question for you.

I defined two different roles in my application. I've already created different screens for them because they don't have the same layout and permissions (it's like an employee and customer view).

The use case should be that the user is directed to the suitable homescreen directly after the login (based on the user role). Is it possible to show the different screens depending on the user role? Maybe I have to integrate it to the Login Action?

Thank you in advance :)

2018-10-29 08-31-03
João Marques
 
MVP
Solution

Hi Leonie,


In your Login screen, you have a screen action with the logic for when the user presses the Login button:


This is the logic that needs to be changed to check the user role and to redirect to the screen accordingly.

After the DoLogin action, you can check if the logged-in user has a given role with a simple Javascript. In the example below, I want to check if the user has the Admin role, so I add the Javascript widget with an output parameter IsAdmin.


You should replace the $roles.Admin for $roles.<Your Role>.

And then a simple If using the output of the javascript to redirect to the right screen if he has the role or not.


Hope it helps.


Regards,
JoĂ£o

UserImage.jpg
Leonie Besler

Hi JoĂ£o,

first of all thank you for your suggestions. I understand how it is going to work. But I have a problem with the javascript. As you can see in the Screenshot I get an error message. Do I have to define the output parameter in advance or just in the javascript? Do you maybe know where my fault is?

outsystemsgetrole.PNG
2018-10-29 08-31-03
João Marques
 
MVP

Hi Leonie,


You're welcome, I'm glad to help.

Inside the JavaScript window, you should right click the folder parameters, and choose the option add Output Parameter and name the Parameter IsBank_intern.

You should then use that Parameter in the if afterwards.


Regards,

JoĂ£o

UserImage.jpg
Leonie Besler

Thank you very much. Now it works!

Best regards

Leonie

2024-06-21 13-17-52
Gonçalo Machado

Hi this is an old post but I think its important for future users to know that using "Role Check JavaScript" is not intended for security checks, you should instead use Server Side logic...

Regards

Gonçalo

2021-01-12 13-21-28
Kadu Borges

Hi, Leoni.

I have done some tests and I think that it is possible to do what you want by changing the Common/Login/Login Run Server Action. After User_Login action, you will need to check if the user has the apropriate Role and then go to the Role-URL.

It could be done by using IF statements after the User_Login Action using the Check<Role>Role() action provided by each role.

UserImage.jpg
Leonie Besler

Thank you for your reply. I've already solved my problem with JoĂ£os help :)

Best regards

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.