How to check if the current user is authenticated?

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

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 2; use import:

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

For Script module and WebApp/RESTApp 1; use require:

const systemUserUtil = require('SystemUserUtil');

Step 2 - Make use of the method isAnonymous()

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

Do you want to subscribe to News from Sitevision Developer team? Subscribe here!