Skip to content

User Auth Functions

The User Auth drop-in provides API functions that enable you to programmatically control behavior, fetch data, and integrate with Adobe Commerce backend services.

Version: 4.0.0
FunctionDescription
confirmEmailCompletes the customer activation process using the supplied customerEmail and customerConfirmationKey parameters.
createCustomerCreates a customer account based on the data supplied in the forms parameter.
createCustomerAddressDefines a new customer address.
getAdobeCommerceOptimizerDataFetches Adobe Commerce Optimizer data.
getAttributesFormRetrieves EAV attributes associated with customer and customer address frontend forms.
getCustomerDataRetrieves data about the customer represented by the auth_dropin_user_token cookie value.
getCustomerRolePermissionsRetrieves customer role permissions.
getCustomerTokenHandles the sign-in operation.
getStoreConfigCalls the storeConfig query to retrieve store configuration data.
requestPasswordResetEmailInitiates the process of resetting a customer’s password.
resendConfirmationEmailResends the email confirmation to the customer using the supplied customerEmail parameter.
resetPasswordResets a customer’s password using the supplied email, resetPasswordToken, and newPassword parameters.
revokeCustomerTokenRevokes the customer’s token and clears the authentication cookie.
verifyTokenChecks the validity of the provided authentication token.

The confirmEmail function completes the customer activation process using the supplied customerEmail and customerConfirmationKey parameters. Adobe Commerce sends the confirmation key to the customer when they request to create an account. The function calls the confirmEmail mutation .

const confirmEmail = async (
{ customerEmail, customerConfirmationKey, }: confirmEmailProps
): Promise<confirmEmailResponse | undefined>
ParameterTypeReq?Description
customerEmailstringYesThe customer’s email address.
customerConfirmationKeystringYesThe confirmation key sent by Adobe Commerce.

Does not emit any drop-in events.

Returns confirmEmailResponse | undefined.

The createCustomer function creates a customer account based on the data supplied in the forms parameter. By default, the function calls the createCustomer mutation . If the apiVersion2 parameter is set to true, the function calls the createCustomerV2 mutation .

const createCustomer = async (
forms: Customer,
apiVersion2: boolean
): Promise<CustomerModel>
ParameterTypeReq?Description
formsCustomerYesCustomer account data including email, password, firstName, lastName, and optional custom attributes.
apiVersion2booleanYesWhether to use the v2 API (createCustomerV2 mutation) instead of the original createCustomer mutation.

Does not emit any drop-in events.

Returns CustomerModel.

The createCustomerAddress function defines a new customer address. The customer can subsequently designate the address for billing or shipping orders. The function calls the createCustomerAddress mutation .

const createCustomerAddress = async (
address: AddressFormProps
): Promise<string>
ParameterTypeReq?Description
addressAddressFormPropsYesThe new customer address including street, city, region, country, postal code, and optional fields like company name and phone number.

Does not emit any drop-in events.

Returns string.

The getAdobeCommerceOptimizerData function fetches Adobe Commerce Optimizer data.

const getAdobeCommerceOptimizerData = async (): Promise<AdobeCommerceOptimizerModel>

Emits the auth/adobe-commerce-optimizer event.

Returns AdobeCommerceOptimizerModel.

The getAttributesForm function retrieves entity-attribute-value (EAV) attributes associated with customer and customer address frontend forms. The function calls the attributesForm query .

const getAttributesForm = async (
formCode: string
): Promise<AttributesFormModel[]>
ParameterTypeReq?Description
formCodestringYesThe form code, one of: customer_account_create, customer_account_edit, customer_address_create, or customer_address_edit.

Does not emit any drop-in events.

Returns AttributesFormModel[].

The getCustomerData function retrieves data about the customer represented by the value of the auth_dropin_user_token cookie. The function calls the customer query .

const getCustomerData = async (
user_token: string
): Promise<CustomerModel>
ParameterTypeReq?Description
user_tokenstringYesThe customer authentication token from the auth_dropin_user_token cookie.

Does not emit any drop-in events.

Returns CustomerModel.

The getCustomerRolePermissions function retrieves customer role permissions. It caches results to minimize API calls, returning cached data immediately when available or fetching fresh data when the cache is empty.

const getCustomerRolePermissions = async (): Promise<PermissionsModel>

Emits the auth/permissions event.

Returns PermissionsModel.

The getCustomerToken function handles the sign-in operation. It requires email and password (and accepts additional optional properties on the parameter object) and performs these actions:

  1. Retrieves the customer token.
  2. Fetches customer data using the token.
  3. Sets the auth_dropin_firstname and auth_dropin_user_token cookies.
  4. Publishes an Adobe Client Data Layer (ACDL) event.
  5. Emits an “authenticated” event.

You can use the getCustomerToken function to build a custom authentication flow that remains fully integrated with other drop-in components. The function calls the generateCustomerToken mutation .

const getCustomerToken = async (
{ email, password, translations, onErrorCallback, handleSetInLineAlertProps, }: getCustomerTokenProps
): Promise<{
errorMessage: string;
userName: string;
userEmail: string;
}>
ParameterTypeReq?Description
emailstringYesThe customer’s email address (or username, depending on store configuration).
passwordstringYesThe customer’s password.

Additional optional properties on the same object may include translations, onErrorCallback, and handleSetInLineAlertProps. See getCustomerTokenProps in the drop-in source for the full type.

Does not emit any drop-in events.

Promise<{
errorMessage: string;
userName: string;
userEmail: string;
}>

The getStoreConfig function calls the storeConfig query to retrieve store configuration data.

const getStoreConfig = async (): Promise<StoreConfigModel>

Does not emit any drop-in events.

Returns StoreConfigModel.

The requestPasswordResetEmail function initiates the process of resetting a customer’s password. The function calls the requestPasswordResetEmail mutation .

const requestPasswordResetEmail = async (
email: string
): Promise<PasswordResetEmailModel>
ParameterTypeReq?Description
emailstringYesThe email address of the customer requesting a password reset.

Does not emit any drop-in events.

Returns PasswordResetEmailModel.

The resendConfirmationEmail function resends the email confirmation to the customer using the supplied customerEmail parameter. The function calls the resendConfirmationEmail mutation , which is included in the Storefront Compatibility Package.

const resendConfirmationEmail = async (
customerEmail: string
): Promise<resendConfirmationEmailResponse>
ParameterTypeReq?Description
customerEmailstringYesThe email address of the customer who needs the confirmation email resent.

Does not emit any drop-in events.

Returns resendConfirmationEmailResponse.

The resetPassword function resets a customer’s password using the supplied email, resetPasswordToken, and newPassword parameters. The function calls the resetPassword mutation .

const resetPassword = async (
email: string,
resetPasswordToken: string,
newPassword: string
): Promise<ResetPasswordModel>
ParameterTypeReq?Description
emailstringYesThe email address of the customer resetting their password.
resetPasswordTokenstringYesThe password reset token sent to the customer’s email.
newPasswordstringYesThe new password for the customer account.

Does not emit any drop-in events.

Returns ResetPasswordModel.

The revokeCustomerToken function revokes the customer’s token and clears the authentication cookie. It then publishes an ACDL event and emits an “authenticated” event. Use this function to build a custom sign-out flow that stays fully integrated with other drop-in components. The function calls the revokeCustomerToken mutation .

const revokeCustomerToken = async (): Promise<RevokeCustomerTokenModel>

Does not emit any drop-in events.

Returns RevokeCustomerTokenModel.

The verifyToken function checks the validity of the stored customer token. If valid, it emits the authenticated event with true. If the token is invalid or missing, it clears the authentication cookies and header, and emits authenticated with false.

By default, the validation query is compatible with all backends. When adobeCommerceOptimizer is set to true, the function also emits the auth/group-uid event required for Adobe Commerce Optimizer price book resolution.

const verifyToken = async (
authType = 'Authorization',
type = 'Bearer',
adobeCommerceOptimizer = false
): Promise<boolean>
ParameterTypeReq?Description
authTypestringNoThe name of the HTTP authorization header. Defaults to Authorization.
typestringNoThe credential type prefixed to the token in the authorization header (for example, Bearer <token>). Defaults to Bearer.
adobeCommerceOptimizerbooleanNoWhen true, emits the auth/group-uid event for Adobe Commerce Optimizer price book resolution. Defaults to false.

Emits the authenticated event.

When adobeCommerceOptimizer is true, also emits the auth/group-uid event.

Returns Promise<boolean>. Returns true if the token is valid, false otherwise.

Functions in this drop-in use the following data models.

The AdobeCommerceOptimizerModel object is returned by the following functions: getAdobeCommerceOptimizerData.

interface AdobeCommerceOptimizerModel {
priceBookId: string;
}

The CustomerModel object is returned by the following functions: createCustomer, getCustomerData.

interface CustomerModel {
firstName: string;
lastName: string;
email: string;
groupUid: string;
customAttributes?: Record<string, string>[];
errors?: { message: string }[];
}

The PasswordResetEmailModel object is returned by the following functions: requestPasswordResetEmail.

interface PasswordResetEmailModel {
message: string | '';
success: boolean;
}

The PermissionsModel object is returned by the following functions: getCustomerRolePermissions.

interface PermissionsModel {
all?: boolean;
admin?: boolean;
[key: string]: boolean;
}

The ResetPasswordModel object is returned by the following functions: resetPassword.

interface ResetPasswordModel {
message: string | '';
success: boolean;
}

The RevokeCustomerTokenModel object is returned by the following functions: revokeCustomerToken.

interface RevokeCustomerTokenModel {
message: string | '';
success: boolean;
}

The StoreConfigModel object is returned by the following functions: getStoreConfig.

interface StoreConfigModel {
autocompleteOnStorefront: boolean;
minLength: number;
requiredCharacterClasses: number;
createAccountConfirmation: boolean;
customerAccessTokenLifetime: number;
}