Vue Storefront is now Alokai! Learn More
Authentication

Authentication

The Unified Auth Methods are responsible for registering new customers, logging in existing ones, retrieving or updating customer information, and logging out.

Coverage

MethodCommercetoolsSAPCCBigCommerceSFCCMagento
registerCustomer✅✅✅✅✅
loginCustomer✅✅✅✅✅
getCustomer✅✅✅✅✅
logoutCustomer✅✅✅✅✅
updateCustomer✅✅✅✅✅
changeCustomerPassword✅✅✅✅✅

registerCustomer

The registerCustomer method allows you to register a new customer by providing their email, first name, last name, and password. Upon successful registration, the method logs in the new customer and returns an SfCustomer object.

Usage

const { customer } = await sdk.unified.registerCustomer({
  email: 'johndoe@example.com',
  firstName: 'John',
  lastName: 'Doe',
  password: 'password', 
});

Type

export interface RegisterCustomerArgs {
  email: string;
  firstName: string;
  lastName: string;
  password: string;
}

export type RegisterCustomer = (args: RegisterCustomerArgs) => Promise<{
  customer: SfCustomer;
}>;

export interface SfCustomer {
  id: SfId;
  email: string;
  firstName: string;
  lastName: string;
}

loginCustomer

With the loginCustomer method, existing customers can log in by providing their email and password. Upon successful authentication, the method returns an SfCustomer object representing the logged-in customer.

Usage

const { customer } = await sdk.unified.loginCustomer({
  email: 'johndoe@example.com',
  password: 'password',
});

Type

export interface LoginCustomerArgs {
  email: string;
  password: string;
}

export type LoginCustomer = (args: LoginCustomerArgs) => Promise<{
  customer: SfCustomer;
}>;

export interface SfCustomer {
  id: SfId;
  email: string;
  firstName: string;
  lastName: string;
}

getCustomer

The getCustomer method allows you to fetch information about the currently logged-in customer. It returns an SfCustomer object containing the customer's details. If no customer is currently logged in, the method returns null.

Usage

const { customer } = await sdk.unified.getCustomer();

Type

export type GetCustomer = () => Promise<{
  customer: Maybe<SfCustomer>;
}>;

logoutCustomer

The LogoutCustomer method is used to log out the currently authenticated customer. It doesn't require any arguments and simply terminates the customer's session.

Usage

await sdk.unified.logoutCustomer();

Type

export type LogoutCustomer = () => Promise<void>;

updateCustomer

The updateCustomer method is used to update data of the currently authenticated customer. The method returns an SfCustomer object with updated customer fields.

Usage

const { customer} = await sdk.unified.updateCustomer({
  email: 'updated-email@example.com',
  firstName: 'Jonathan',
  lastName: 'Smith',
})

Type

export interface UpdateCustomerArgs {
  email?: string;
  firstName?: string;
  lastName?: string;
}

export type UpdateCustomer = (args: UpdateCustomerArgs) => Promise<{
  customer: SfCustomer;
}>;

export interface SfCustomer {
  id: SfId;
  email: string;
  firstName: string;
  lastName: string;
}

changeCustomerPassword

The changeCustomerPassword method allows an authenticated customer to change their password.

The new password must meet the following complexity requirements:

  • at least one uppercase letter,
  • one digit,
  • and one special character (!@#$%^*();:,.)).

The customer must also confirm the new password. By providing the current password, new password, and confirmation, the customer can update their login credentials.

If the current password is incorrect, the new password does not meet the complexity requirements, or the new password and confirmation do not match, the method will throw an error.

Usage

await sdk.unified.changeCustomerPassword({
  currentPassword: 'password',
  newPassword: 'newPassword#1',
  confirmPassword: 'newPassword#1',
});

Type

export interface ChangeCustomerPasswordArgs {
  currentPassword: string;
  newPassword: string;
  confirmPassword: string;
}

export type ChangeCustomerPassword = (
  args: ChangeCustomerPasswordArgs,
) => Promise<void>;