Authentication
The Unified Auth Methods are responsible for registering new customers, logging in existing ones, retrieving or updating customer information, and logging out.
Coverageri:link
Method | Commercetools | SAPCC | BigCommerce | SFCC | Magento |
---|---|---|---|---|---|
registerCustomer | ✅ | ✅ | ✅ | ✅ | ✅ |
loginCustomer | ✅ | ✅ | ✅ | ✅ | ✅ |
getCustomer | ✅ | ✅ | ✅ | ✅ | ✅ |
logoutCustomer | ✅ | ✅ | ✅ | ✅ | ✅ |
updateCustomer | ✅ | ✅ | ✅ | ✅ | ✅ |
changeCustomerPassword | ✅ | ✅ | ✅ | ✅ | ✅ |
registerCustomerri:link
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.
Usageri:link
const { customer } = await sdk.unified.registerCustomer({
email: 'johndoe@example.com',
firstName: 'John',
lastName: 'Doe',
password: 'password',
});
Typeri:link
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;
}
loginCustomerri:link
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.
Usageri:link
const { customer } = await sdk.unified.loginCustomer({
email: 'johndoe@example.com',
password: 'password',
});
Typeri:link
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;
}
getCustomerri:link
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
.
Usageri:link
const { customer } = await sdk.unified.getCustomer();
Typeri:link
export type GetCustomer = () => Promise<{
customer: Maybe<SfCustomer>;
}>;
logoutCustomerri:link
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.
Usageri:link
await sdk.unified.logoutCustomer();
Typeri:link
export type LogoutCustomer = () => Promise<void>;
updateCustomerri:link
The updateCustomer
method is used to update data of the currently authenticated customer. The method returns an SfCustomer
object with updated customer fields.
Usageri:link
const { customer} = await sdk.unified.updateCustomer({
email: 'updated-email@example.com',
firstName: 'Jonathan',
lastName: 'Smith',
})
Typeri:link
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;
}
changeCustomerPasswordri:link
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.
Usageri:link
await sdk.unified.changeCustomerPassword({
currentPassword: 'password',
newPassword: 'newPassword#1',
confirmPassword: 'newPassword#1',
});
Typeri:link
export interface ChangeCustomerPasswordArgs {
currentPassword: string;
newPassword: string;
confirmPassword: string;
}
export type ChangeCustomerPassword = (
args: ChangeCustomerPasswordArgs,
) => Promise<void>;