Creating an automatic login feature can be quite a challenge. A feature which is intended to make approval processes smoother and more efficient, can quickly make a developers life difficult. From regular login features, to more complex approval processes without even the need for a login, Deeplinks are incredibly powerful if used correctly. In this demo I would like to show you how we made an autologin with existing widgets and modules available from the Mendix Marketplace.
First of all, thanks to those who have contributed on the market place modules for
All of these are modules are needed in this demo project. With that being said, let’s get started using Mendix Studio Pro 7.23.20 (LTS).
Now we have all the required modules but there are also 2 errors.
The errors are just about the popup layout. You can change these pages to use the Atlas popup layout instead.
Then the errors will be gone.
Next we can configure the deep link to automatically start when the app does, using the after startup microflow setting under the project settings.
From this point you also need to add an autologin deeplink request handler with a return value as a boolean.
Next we need to setup the deeplinkhome microflow on the app’s Navigation.
Take a look at the DeepLinkHome microflow, we should implement something here which tells the application to redirect specific user roles to specific pages.
From myfirstmodule, create a new microflow, name it ACT_GoToHomePage. Select “Inheritance Split” (light green diamond shape) and map it with the currentUser object. This CurrentUser is the user who is accessing the web page.
Add an “Action Activity” box, select Cast Object
Type the output name as “Account”.
Right click on the red arrow point from CurrentUser to CastObject, then select Condition value, and select Administration.Account.
There are another 2 paths you need to define for the inheritance split to get rid of all the errors.
From the account Entity, we need to make one Enum field for checking account types in order to route to correct page.
We make 2 pages and name them as UserPage_Overview, and AdminPage_Overview.
Just make a simple title to see which page is used for user or admin.
Now back to the microflow ACT_GoToHomePage. We cast an object account, and setup AccountType to navigate to different pages.
In the security settings, you can select Production.
Still in the security settings, under the tab “User roles”, we need to add one more role, name it “Anonymous”. The AutoLogin module has already had this role since the beginning, so no need to select again.
Anonymous security setting
User security setting
Admin Security setting
Final Security Setting
In Navigation menu, you will have to setup the Administrators navigation as follows so they can access and configure the project settings.
Now add the microflow ACT_GoToHome to the deeplinkhome microflow.
Everything is almost done, however we still need one microflow for deeplink with email parameters.
At this point you can save and run locally. Just remember that when you enable anonymous access, it means you need to have a login screen for anonymous users to login. If you run locally now, you will see a white screen, because there is no landing page for anonymous setup. To fix this we need to implement something on ACT_GoToHomePage. The Anonymous and MxAdmin roles are initiated with system.User, but the difference is ,one is Anonymous but MxAdmin is not and has an Admin role which Account Object Inheriting to System.User.
Save and run again, we can see that after sign in MxAdmin will be at another page.
Ok, so far so good, we can setup deeplink and create test account for now.
Login as admin so that you can navigate to model reflection overview and refresh the object list with mx reflection.
Then create a new deeplink which we will connect with the microflow “ACT_AutoLoginWithEmail” which we have created in the previous steps.
The result of deeplink is
Now go to account, create 2 new users with 2 user roles to test the auto login.
So I have 2 accounts : tony1(User) and tony2(Admin).
If Ipass the deeplink with format http://localhost:firstname.lastname@example.org. It should navigate to Welcome User Page.
Here we go
Something else that you may need to know: this AutoLogin feature also works in Mendix 8, but some users will be faced with the error below.
To resolve this, make sure your project is upgraded at least 8.18.4 to overcome the issue. After upgrading you will still see the error message as shown below.
After copying and overwriting it, please synchronize the project one more time by pressing F4 or going to “Project” in the top left hand menu inside Studio Pro and click on “Synchronize Project Directory”.
You will see one final error, caused by the widget definition changing.
Right click on the widget and select “Update all widgets”.
Run locally again and test.
There should be resolved and the user should be directed to the correct page when they use the deeplink to login.
Here is the github repo link for both version 7 and 8 project.
Contribute to qntbkk/BlogAutoLogin development by creating an account on GitHub.
Good luck, and thanks for reading!
From the Publisher -