Back to Kodaris

Customer

Overview

The Customer module provides access to information about the currently authenticated customer in your server-side code. It allows you to retrieve customer identity details, check authentication status, and implement role- or segment-based logic tied to the user session.

This module is essential for any feature that needs to respond to the identity, status, or privileges of the customer—such as customizing content, restricting access, or recording user-specific actions.

Note: The Customer module is globally available in the SDK environment via kd.customer.

Key Features

  1. Authentication Status: Determine if a customer is currently logged in and active.
  2. Customer Identity: Access customer details such as ID, email, name, or other profile fields.
  3. Role or Segment Checks: Determine if the customer belongs to specific roles or groups
  4. Session Context: Tie logic to the active customer session for personalization or security.

Example Use Cases

  1. Restricting certain functionality or endpoints to logged-in customers
  2. Displaying customer-specific data like orders, preferences, or history
  3. Personalizing responses based on customer identity or attributes
  4. Logging or tracking actions in association with a customer account

The kd.customer module is automatically available in any server-side context and can be safely used in middleware, route handlers, or business logic where customer context is needed.

Methods

isLoggedIn()

Checks whether a customer is currently logged in with an active session.

  1. Parameters: None
  2. Returns (Boolean): Whether
    1. true: A customer is logged in with an active session
    2. false: No customer is logged in
  3. Example
if (kd.customer.isLoggedIn()) {
  // Show personalized content
} else {
  // Show login prompt
}

hasRole(roleCode)

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

  1. Parameters:
    1. roleCode (String, required): The role code to check for the current customer.
  2. Returns (Boolean):
    1. true: The customer has the specified role
    2. false: The customer does not have the specified role or no customer is logged in
  1. Example
if (kd.customer.hasRole("companyAdmin")) {
  // Show wholesale pricing
}

get()

Retrieves the customer object for the currently logged-in user.

  1. Parameters: None
  2. Returns (Object):
    1. If a customer is logged in: Returns the customer object
    2. If no customer is logged in: Returns null
  1. Example
var customer = kd.customer.get();

/* Sample Response:
{
  customerID: "cust_123456",
  firstName: "John",
  userName: "john.doe@kodaris.com",
  // Other customer properties...
}
*/
In this article