Users
Introduction
This section will cover the basics of fetching the user details, managing user addresses and changing the user password.
API Reference
You can find all available SAPCC module methods and their description in the API Reference.
Fetching user details
To fetch a user, you can use the getUser method.
import { sdk } from '~/sdk';
const user = await sdk.sapcc.getUser();
You can specify the fields
parameter to customize the response
import { sdk } from '~/sdk';
const user = await sdk.sapcc.getUser({ fields: 'uid,firstName' });
Updating user details
To update a user, you can use the updateUser method.
It requires a UpdateUserProps
object as a parameter. You can import the UpdateUserProps
interface from the @vsf-enterprise/sapcc-types
package.
import { UpdateUserProps } from '@vsf-enterprise/sapcc-types';
import { sdk } from '~/sdk';
const props: UpdateUserProps = {
user: {
firstName: 'John',
lastName: 'Doe'
}
};
await sdk.sapcc.updateUser(props);
Managing User Addresses
Fetching User Addresses
To fetch a user address, you can use the getUserAddresses method.
import { sdk } from '~/sdk';
const { addresses } = await sdk.commerce.getUserAddresses();
Adding a User Address
To add a user address, you can use the createUserAddress method.
It requires a CreateAddressProps
object as a parameter. You can import the CreateAddressProps
interface from the @vsf-enterprise/sapcc-types
package.
import { sdk } from '~/sdk';
import { CreateAddressProps } from '@vsf-enterprise/sapcc-types';
const props: CreateAddressProps = {
address: {
firstName: 'Integration',
lastName: 'Test',
line1: 'Test',
postalCode: '54-025',
titleCode: 'mr',
country: { isocode: 'GB' },
town: 'Radom'
}
};
const address = await sdk.sapcc.createUserAddress(props);
Updating a User Address
To update a user address, you can use the updateUserAddress method.
import { sdk } from '~/sdk';
await sdk.sapcc.updateUserAddress({
addressId: '8796879552535',
address: {
line1: 'Line 1'
}
});
Changing User Password
To change a user password, you can use the changeUserPassword method.
import { sdk } from '~/sdk';
await sdk.sapcc.changeUserPassword({
old: 'oldPassword1!',
new: 'newPassword1!'
});