This document outlines the steps required to configure Concurrent Session Control in an OutSystems Reactive Web Application. The goal is to ensure that each user maintains only one active session by issuing and validating session tokens.
You have a module that includes or consumes the ConcurrentSessionControl logic.
ConcurrentSessionControl
A server action named GenerateUserTokenWithSingleSession and a client action ValidateUserToken are already available.
GenerateUserTokenWithSingleSession
ValidateUserToken
In Interface > Client Variables, create a new variable:
Name: UserToken
UserToken
Data Type: Text
Description: Used to store the current authenticated user's token.
Open your DoLogin logic or the client/server action that performs user login.
After the user is successfully authenticated, call the server action:
Set the output token from this action to the UserToken client variable.
Example assignment:
outsystemSet UserToken = GenerateUserTokenWithSingleSession.Token
Set UserToken = GenerateUserTokenWithSingleSession.Token
Add a new Client Action named ValidateUserToken.
Inside this action:
Use the server action ValidateUserToken from the ConcurrentSessionControl module.
Pass the UserToken as input.
Handle the response:
If IsValid = False, display a message to the user:
IsValid = False
“Another session has been started using your account. You will now be signed out.”
Redirect the user to the logout screen.
On Application Ready
Navigate to Logic tab.
Right-click on the Client Actions folder.
Client Actions
Select Add System Event > On Application Ready.
Inside the On Application Ready logic:
Check if UserToken is not empty.
If not empty, run a timer to continuously validate the token every 10 seconds using JavaScript.
javascripvar delayInMilliseconds = 1000; // 1 second setInterval(function() { $actions.ValidateUserToken(); }, 10 * delayInMilliseconds); // Adjust interval as needed
var delayInMilliseconds = 1000; // 1 second setInterval(function() { $actions.ValidateUserToken(); }, 10 * delayInMilliseconds); // Adjust interval as needed
Check if a session exists in ExclusiveUserSession for the current user:
ExclusiveUserSession
If exists → update the token and timestamp.
If not → create a new record.
Fields:
TokenGenerationDateTime = CurrDateTime()
TokenGenerationDateTime
CurrDateTime()
TokenExpirationDateTime = CurrDateTime() + MinutesToAdd(UserTokenValidityDurationMinutes)
TokenExpirationDateTime
CurrDateTime() + MinutesToAdd(UserTokenValidityDurationMinutes)
UserTokenValidityDurationMinutes is a Site Property that controls the lifetime of the token. You can update this property from Service Center or at design time.
UserTokenValidityDurationMinutes