Returns
Boolean
– true
if the user is logged in, otherwise false
.
Returns
Boolean
– true
if the user is logged in, otherwise false
.
Scrivito.isUserLoggedIn
is reactive, whereas Scrivito.
currentUser
isn’t, meaning that isUserLoggedIn
is available immediately and guaranteed not to change during the application’s runtime, i.e., until the browser is reloaded.
In contrast, currentUser
should only be used inside Scrivito.connect
or Scrivito.load
, and first needs to load the user data. So if a React component renders while data is still being loaded, it may occur that even though isUserLoggedIn
is true, currentUser
temporarily returns null until the data has been loaded.
If the Scrivito SDK recognizes for a user that their logged-in state changed to logged out, e.g., after logging out in a different browser tab, or because the session expired, it triggers a reload of the current browser tab, so that the application is restarted with isUserLoggedIn
set to false
. This ensures that the application logic never has to wait for the result of isUserLoggedIn
, and is not required to handle the case that the value of isUserLoggedIn
may change.