Using the After Sign-In Microflow

on December 15, 2015

Share:

While I was working on my first application that utilizes anonymous users, I ran into another feature of Mendix that I have never used before. The After Sign-In microflow allows for users to carry over data from before they login, through the login process. In the example used in this blog, we allow for a potential user to browse through a list of items available for purchase, before logging in.

Setting up the Data Model

There are two things we need to be aware of here, the first of which is security. Allowing anonymous users access to our application means that anyone can view our data. We must take extra time to ensure that Anonymous users are only allowed to view data and access microflows that they should be able to use. This is very important.

The second is how we are going to transfer the data from the Anonymous user to the logged in user. In this example we will have two associations to the Order entity: one to User (for Anonymous users) and one to Account (for the logged in user).

After Sign-in Microflow

Next we need to create a view that both the Anonymous and Confirmed users can access. This page will have security set up so that the Anonymous users can only add Products to their order, while Users can Create, Edit, and Delete products, in addition to being able to add them.

Homepage for anonymous access

Home Page for Anonymous access

In the microflow for adding a product to an order, we will need to ensure that the order is created on the proper association. If we are an anonymous user, we want to use the ‘Order_User’ association, and if not, we want to use the ‘Order_Account’ association:

Now that we have a way for an Anonymous user to add Products to their order, they will need to be able to check out. However, we want them to sign in first. In our ‘Checkout’ microflow, we simply check if they are a ‘User’ or an ‘Account’. If they are an Account, they have signed in, and can simply check out. If they are anonymous, we force them to login:

With this microflow we bring the anonymous users to the Login Page. Then, when they log in, we run our Sign-in microflow. This is set up in the Project Security settings in the modeler:

Project Security Settings

Project Security Settings

In our Sign-in microflow, we must transfer the data from our Anonymous user to the new signed in User. We do that by retrieving the order from the ‘Order_User’ association from the AnonymousUser, and updating the SignedInUser:

Now if I select some items from the list, sign in, and view my cart, the data was carried over!

Placing an order anonymously (click to view animation)

Have you used this feature before? Are there any cool ways you have taken advantage of this? Share them in the comments below!

Tags:

Subscribe to Our Blog

Receive Mendix platform tips, tricks, and other resources straight to your inbox every two weeks.

RSS Feed of the Mendix Blog
Adam Fothergill

About Adam Fothergill

As a consultant at Mendix, Adam develops custom applications on behalf of our customers and provides platform training to enable our customers. His experience working in Mendix started during his tenure in the financial services industry where he developed loan origination, disbursement, and administration applications.

  • Janos

    Hi Adam,

    We developed a site creation application but we recognised that Mendix does not have the ability to hold Session Variables. In nutshell, the entered email address is verified through an email verification service to make sure it is valid. The service charges per verification so ideally, the email address should only be checked once. However, currently the email address is checked every time when the user leaves the email textbox and it takes up verifications. If Mendix had Session Variables, we would be able to store the email as verified and this will be checked before sending the email for verification.

    Could you please tell me how we can achieve this?

    Thanks & Regards,
    Janos

  • Andrej Koelewijn

    To create a session variable you can create an entity that is associated in the domain model with the session entity. You will be able to use this entity on every page.

  • Janos

    Thanks Andrej!