How can I check if a Salesforce user is currently authenticated?

  • 1
  • Question
  • Updated 1 year ago
  • Answered
I want to be able to run a function to detect if the user is still logged into Salesforce.

I have been running a check against skuid.utils.userInfo.isAuthenticated to determine if a user is logged in when the page initially loads. This has worked.

However now I am attempting to re-run the function at regular intervals (so that if a user leaves a tab open for a long time and the user is logged out of SF it will also log them out of the SKUID page they are on in a similar manner to how the SKUID Editor will log you out if you log out of Salesforce from another tab.

Problem is when checking against skuid.utils.userInfo.isAuthenticated I still get a value of true even if I have logged out from another page when it is checked subsequently. I feel like perhaps the value is cached.

Is there something else I should be doing (i.e. somehow clearing this elements cache or using a different function) in order to check if a user is logged in (when checking every 20mins etc...) to avoid getting a cached result?
Photo of Joseph Ucuzoglu

Joseph Ucuzoglu

  • 1,074 Points 1k badge 2x thumb

Posted 1 year ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Joseph, we've been in touch on this issue, but I wanted to respond on the Community as well, in case others look at this topic. When you call skuid.utils.userInfo.isAuthenticated in a snippet, it will not cause Skuid to refresh the value and check again to see whether the user is still authenticated and logged in. This value is grabbed just once on page load, and the value of isAuthenticated at that time won't be updated until the page is reloaded. So, it wouldn't be useful for checking user status on pages that remain open and unchanged for long periods of time. 

Normally, there should be a popup warning that the user has been logged out of Salesforce. If your needs aren't being met by this, or if there's a scenario that needs more frequent checks, I'd recommend that you set up a timer in your snippet that will try to load a simple model every so often. If the user has been logged out, this model's query will fail and an error message will surface on the page.