This section will cover the basics of authentication and how to register, login and logout a user.

API Reference

You can find all available SAPCC module methods and their description in the API Reference.

Registering a user

To register a user, you can use the createUser method. This method requires a UserSignUpProps object as a parameter. You can import the UserSignUpProps interface from the @vsf-enterprise/sapcc-types package.

import { UserSignUpProps } from '@vsf-enterprise/sapcc-types';
import { sdk } from '~/sdk';

const props: UserSignUpProps = {
  titleCode: 'mr',
  firstName: 'John',
  lastName: 'Doe',
  password: 'Test1234!',
  uid: ''

const user = await sdk.sapcc.createUser(props);

Logging in

To log in as a user, you can use the signUserIn method. It returns the access token received from SAP Commerce Cloud. The token is also saved in the browser as the vsf-sap-token cookie automatically using the Set-Cookie response header. The default options of the cookie can be modified through the property in middleware.config.js

import { sdk } from '~/sdk';

const tokenResponse = await sdk.sapcc.signUserIn({
  username: '',
  password: 'test123!'

Logging out

To log out of a user, you can use the signUserOut method. Additionally, it calls the token revoke endpoint to invalidate the access token stored as the vsf-sap-token browser cookie. It also removes the cookie automatically afterward.

import { sdk } from '~/sdk';

const tokenResponse = await sdk.commerce.signUserOut();