Latest Posts

PowerApps Timer - Implement Auto logout functionality


In this article, we are going to implement an Auto Logout functionality using PowerApps Timer controls. Besides implementing Auto Logout, we will also go through some of the functionalities of PowerApps Timer control.



Requirement: Auto log out of the PowerApps after 10 (N) Minutes being idle on the App.

Implementation Steps:

  1. On the landing screen of your app, set a variable (LogOutTimer) for 10 Minutes (600 seconds).

Set(LogOutTimer, -600)

  1. Create a Screen called – UserLogOutCountDown
    Note:
    • If the user is idle for 10 mins, on any screen of the application, we will redirect the user to this screen to let the user stay connected to the app.
    • On this screen, we allow 30 more seconds so that if the user wants to stay signed-in, he can press the button and restart the 10 minutes counter.
    PowerApps Timer Auto log off screen
  1. Put a Timer control on this screen.
    Timer Control Name: tmr_logout
    • Duration – 30000 (Explanation: Setting the duration for 30 seconds)
    • OnTimerEnd - Exit(true) (Explanation: After 30 seconds, the user will be automatically logged out if he doesn’t choose to stay logged-In by pressing the Stay Signed In button)
    • Visible – False (Explanation: This is used for 30 seconds counter used in label control (lblLogOutText – explained below) so we don’t need to show this control to the end-user but just for better understanding, I have kept it visible.)
  2. Label Control - lblLogOutText
    • Text - "You are about to be automatically signed out in " & (30 - Round(tmr_logout.Value/1000, 0)) & " seconds"
      (Explanation: This label is used to show 30 seconds reverse counter with help of (tmr_logout) control.
  3. Button Control: btnStaySignedIn
    • Text - Stay Signed In
    • OnSelect: Below formulas

      UserLastNavigated = Now();
      (Explanation: Restart the 10 mins counter)
    • Back();
      (Explanation: After clicking, redirect the user from the screen he got logged out to this screen.)
  1. Button Control: btnSignOut
    • Text – Sign Out
    • OnSelect:
      Exit(true)
      (Explanation: User chooses to logout intentionally)
  1. On each screen of your application,
    OnVisible: Write below formulas

    Reset(tmr_logout);
    (Explanation: On the load event of each screen, resetting the timer as the user has navigated and he is active)

    Set(UserLastNavigated, Now());
    (Explanation: Every time any user comes on any screen we reset this variable to the current time. This variable will be eventually used to calculate the idle time as described in following step.)

  1. On each of the screens of your Canvas app, add a Timer Control. For the timer control, set below properties
    1. AutoStart = True (Explanation: Starts when the user arrives at the screen)
    2. Duration = 1000 (Explanation: Set the duration to 1 second so that after 1 second, OnTimerEnd Event will fire)
    3. Repeat = True (Explanation: After every 1 second this timer will repeat and because of that after every second it will keep firing OnTimerEnd event.)
    4. OnTimerEnd: Below Formula

      If(UserLastNavigated < DateAdd(Now(), LogOutTimer, Seconds), Navigate(UserLogOutCountdown))

      Explanation:
      • UserLastNavigated is the global variable and we set it to 600 seconds (10 Minutes) on each screen
      • On each screen, according to the above formula, we check if this variable exceeds LogOutTimer (which we set on starting screen), then we just redirect the user to the UserLogOutCountDown screen

Let us know if you have any difficulties implementing the PowerApps Timer Control we will try to update this article accordingly.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint