Back to Kodaris

Employee

Overview

The Employee module provides access to information about the currently authenticated employee within the server-side execution context. It includes methods for checking authentication status, retrieving employee identity, and evaluating role-based permissions.

This module is essential for implementing secure logic based on the identity and privileges of the employee making the request - such as controlling access to admin-only features or conditionally executing code based on assigned roles or permissions.

Note: The Employee module is globally available in the SDK environment via kd.employee.

Key Features

  1. Authentication Status - Determine whether an employee is currently logged in.
  2. Identity Access - Retrieve details about the logged-in employee (e.g., ID, name, email).
  3. Role & Permission Checks - Verify if the employee has specific roles or permissions, enabling fine-grained access control.
  4. Session Context - Use employee information to personalize or restrict logic based on who's using the system.

Example Use Cases

  1. Restricting access to certain routes or functions for admin-level employees.
  2. Customizing behavior or output based on employee roles (e.g., support, manager, sales).
  3. Validating whether the current session is authenticated before proceeding with sensitive operations.

The kd.employee module is available in any server-side context or middleware, making it easy to integrate secure employee-specific logic throughout your Kodaris platform.

Methods

isLoggedIn()

Checks whether an employee user is currently logged in with an active session.

  1. Parameters: None
  2. Returns (Boolean):
    1. true: An employee is logged in with an active session
    2. false: No employee is logged in
  3. Example:
if (kd.employee.isLoggedIn()) {
  // Perform employee-only operations
} else {
  // Handle unauthorized access
}

get()

Retrieves the employee object for the currently logged-in employee.

  1. Parameters: None
  2. Returns (Object):
    1. If an employee is logged in: Returns the employee object containing employee information
    2. If no employee is logged in: Returns null
  3. Example:
// Get the current employee's information
var employee = kd.employee.get();

/* Sample Response:
{
  administratorID: 123456,
  firstName: "Jane",
  userName: "jane.smith@kodaris.com"
}
*/

hasRole()

Checks if the currently logged-in employee has a specific role.

  1. Parameters:
    1. roleCode (String, required): The role code to check for the current employee.
  2. Returns (Boolean):
    1. true: The employee has the specified role
    2. false: The employee does not have the specified role or no employee is logged in
  1. Example:
// Check if the current employee has the ADMIN role
var isSuperuser = kd.employee.hasRole("superuser");

/* Sample Response:
true  // Employee has the superuser role
*/

// Using role verification for conditional operations
if (kd.employee.hasRole("contentEdit")) {
  // Allow content management operations
} else {
  // Show unauthorized message or hide content management features
}
In this article