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.
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.
Checks whether a customer is currently logged in with an active session.
true: A customer is logged in with an active sessionfalse: No customer is logged inif (kd.customer.isLoggedIn()) {
// Show personalized content
} else {
// Show login prompt
}
Checks if the currently logged-in customer has a specific role.
roleCode (String, required): The role code to check for the current customer.if (kd.customer.hasRole("companyAdmin")) {
// Show wholesale pricing
}
Retrieves the customer object for the currently logged-in user.
var customer = kd.customer.get();
/* Sample Response:
{
customerID: "cust_123456",
firstName: "John",
userName: "john.doe@kodaris.com",
// Other customer properties...
}
*/