Skip to main content

issueCustomerTokens

Returns the access and refresh tokens that POST /api/customer/tokens returns after a password check, for a customer your extension has identified another way, such as a social login on a headless storefront.

Import​

import { issueCustomerTokens } from '@evershop/evershop/customer/services';

Syntax​

issueCustomerTokens(customerId: number): Promise<{
accessToken: string;
refreshToken: string;
}>

Parameters​

customerId

Type: number

The customer_id of the account.

Return Value​

The two tokens, signed with JWT_CUSTOMER_SECRET and JWT_CUSTOMER_REFRESH_SECRET. They carry the same customer payload as the password flow, never the password. The client uses them the same way (Authorization: Bearer <accessToken>, and POST /api/customer/token/refresh with the refresh token).

It rejects with The customer does not exist or is disabled when there is no active account (status 1) with that id.

Example​

import {
getCustomerByEmail,
issueCustomerTokens
} from '@evershop/evershop/customer/services';

// After your provider returned a verified email
const customer = await getCustomerByEmail(verifiedEmail);
if (!customer || customer.status !== 1) {
response.status(401).json({ error: { message: 'Sign-in failed' } });
return;
}
response.json({ data: await issueCustomerTokens(customer.customer_id) });

Follow the social login checklist before you issue tokens.

See Also​