Logotype Sitevision Developer
Log in
Log in

How to check if the current user is authenticated?

Use SystemUserUtil to check if the current user is authenticated (i.e. "logged in").

Published: 2022-07-22  |  Updated: 2024-09-26

SystemUserUtil contains methods for checking things concering, primarily, the current user. Among them is the method isAnonymous().

Step 1 - get an instance of SystemUserUtil

For WebApp/RESTApp - use import:

js
import systemUserUtil from '@sitevision/api/server/SystemUserUtil';

For Script module - use require:

js
const systemUserUtil = require('SystemUserUtil');

Step 2 - Make use of the method isAnonymous()

js
if (systemUserUtil.isAnonymous()) { // The current user is NOT authenticated } else { // The current user is authenticated }