Alokai

signIn

Sign in a customer.

It sends a request to commercetools GraphQL API to retrieve an access token through the Password Flow. The token is saved in the browser as the vsf-commercetools-token cookie automatically using the Set-Cookie response header.

The default options of the cookie can be modified through the cookie_options property in middleware.config.ts.

By default, it uses the customerSignMeInDefaultQuery GraphQL query.

Signature

declare function signIn(
	context: CommercetoolsIntegrationContext,
	draft: CustomerSignMeInDraft,
	customQuery?: CustomQuery
): Promise<CustomerSignMeInResponse>;

Parameters

NameRequiredTypeDescription
contextRequiredCommercetoolsIntegrationContext
draftRequiredCustomerSignMeInDraft
customQueryOptionalCustomQuery

Returns

Returns a representation of the CustomerSignMeInResponse.

Referenced Types

Examples

Signing a user in.

const { user } = await sdk.commerce.signIn({
  email: 'test@gmail.com',
  password: 'test123!'
});

Signing a user in and turning an anonymous cart into the customer's active cart.

import { sdk } from '~/sdk.config.ts';
import type { AnonymousCartSignInMode } from '@vsf-enterprise/commercetools-types';

const { user } = await sdk.commerce.signIn({
  email: 'test@gmail.com',
  password: 'test123!',
  activeCartSignInMode: AnonymousCartSignInMode.UseAsNewActiveCustomerCart
});

Signing a user in and merging an anonymous cart with the customer's active cart.

import { sdk } from '~/sdk.config.ts';
import type { AnonymousCartSignInMode } from '@vsf-enterprise/commercetools-types';

const { user } = await sdk.commerce.signIn({
  email: 'test@gmail.com',
  password: 'test123!',
  activeCartSignInMode: AnonymousCartSignInMode.MergeWithExistingCustomerCart
});

On this page