Alokai
You are reading the documentation for SDK v2, which is no longer the latest version. Switch to current

signIn

Method signing a customer in.

This method sends a POST request to the customerSignMeIn endpoint of the Vue Storefront API Middleware. 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.js.

The default GraphQL query used by this method can be found here. You might also want to see the signOut method.

Signature

export declare function signIn<Res extends PartialCustomerSignMeInResponse = CustomerSignMeInResponse>(
	params: CustomerSignMeInParams,
	options?: MethodOptions<CustomQuery<"customerSignMeIn">>
): Promise<Res>;

Parameters

NameRequiredTypeDescription
paramsRequiredCustomerSignMeInParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.
optionsOptionalMethodOptions<CustomQuery<"customerSignMeIn">>Options that can be passed to additionally configure the request or customize the logic in a plugin.

Returns

Returns a representation of the CustomerSignMeInResponse.

Referenced Types

Examples

Signing a user in.

import { sdk } from '~/sdk.config.ts';

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. Read more about commercetools cart merging strategies here.

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. Read more about commercetools cart merging strategies here.

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