User Authentication
For Consumers:
Guests vs Logged in Customers
By default any user visiting a slerp powered site is a guest and slerp supports guest checkout so does not require account creation as part of the checkout process.
In many simple e-commerce setups a guest checkout will be more than sufficient, to determine if you want to offer account creation and login first decide:
- Do you want to use Slerp's loyalty features? These require a user to have created an account (Guests cannot collect loyalty points)
- Do you want to offer a customer the option to quickly repeat previous orders? - This requires an account
- Do you want to allow customers to save data like their phone, email and address for easy completion of future orders? - This requires an account
- Do you want to collect data like birthdate on a customer? - This requires an account
If you would like to offer account creation this is how...
Creating and editing customer accounts
Creating an account:
To create an account you need to, at least, pass a name (first or last) an email and a password (+ confirmation):
Request:
mutation CreateCustomer($firstName: String!, $lastName: String!, $email: String!, $password: String!, $passwordConfirmation: String!, $merchantId: ID!, $contactNum: String!, $birthdate: String, $marketingOptIn: Boolean) {
createCustomer(firstName: $firstName, lastName: $lastName, email: $email, password: $password, passwordConfirmation: $passwordConfirmation, merchantId: $merchantId, contactNum: $contactNum, birthdate: $birthdate, marketingOptIn: $marketingOptIn) {
id
firstName
lastName
email
contactNum
salutation
apiKey
}
}
Example Variables:
{
"email": "[email protected]",
"firstName": "firstname",
"lastName": "lastname",
"birthdate": "2002-06-27", // Optional
"contactNum": "+4407777777777", // Optional
"password": "password", // must be at least 6 chars long
"passwordConfirmation": "password",
"marketingOptIn": true, // boolean, should be false unless user ticks
"merchantId": "2ba090b2-d4dc-4fd1-ba5c-9e0b73586673" // ID of merchant
}
Success:
If successful you will receive a response which contains a customer ID and apiKey. These are things you may need later for various API calls relating to the user eg: loyalty cards.
{
"data": {
"createCustomer": {
"apiKey": "cus4921c3eeb488255775333fb49c0d0ef5", //This is the customer API key, for customer specific queries like order history or loyalty you will need this so keep it in local storage.
"contactNum": "+4407777777777",
"email": "[email protected]",
"firstName": "firstname",
"id": "9807163c-3986-4c99-9d10-cf379e7c6b44",
"lastName": "lastname",
"salutation": null
}
}
}
Error:
{
"data": {
"createCustomer": null
},
"errors": [
{
"locations": [
{
"column": 0,
"line": 2
}
],
"message": "Account already exists. Please sign in.",
"path": [
"createCustomer"
]
}
]
}
Logging in a customer
Request:
query CustomerAuth($email: String!, $password: String!, $merchantId: ID!) {
customerAuth(email: $email, password: $password, merchantId: $merchantId) {
id
firstName
lastName
salutation
email
apiKey
}
}
Example Variables:
{
"email": "[email protected]",
"password": "password",
"merchantId": "2ba090b2-d4dc-4fd1-ba5c-9e0b73586673"
}
Success:
{
"data": {
"customerAuth": {
"apiKey": "cusa10a4267ab8a8981f005744a771c77a0",
"email": "[email protected]",
"firstName": "firstname",
"id": "a01ae086-dc25-4ae3-851f-01a4c6edd915",
"lastName": "lastname",
"salutation": "Mr"
}
}
}
Error:
{
"data": {
"customerAuth": null
},
"errors": [
{
"locations": [
{
"column": 0,
"line": 2
}
],
"message": "Wrong email or password",
"path": [
"customerAuth"
]
}
]
}
Editing a customer profile:
mutation EditCustomer($customerId: ID!, $firstName: String!, $lastName: String!, $email: String!, $merchantId: ID!, $currentPassword: String, $password: String, $passwordConfirmation: String, $contactNum: String, $birthdate: String) {
editCustomer(
customerId: $customerId
firstName: $firstName
lastName: $lastName
email: $email
merchantId: $merchantId
currentPassword: $currentPassword
password: $password
passwordConfirmation: $passwordConfirmation
contactNum: $contactNum
birthdate: $birthdate
) {
id
first_name
last_name
email
contact_num
birthdate
}
}
example variables:
{
"birthdate": null,
"contactNum": "+447777777777",
"customerId": "a01ae086-dc25-4ae3-851f-01a4c6edd915",
"email": "[email protected]",
"firstName": "firstname",
"lastName": "lastname",
"merchantId": "2ba090b2-d4dc-4fd1-ba5c-9e0b73586673"
}
Resetting a customer password
The easiest way to reset a user PW is to redirect them to https://${merchant.slug}.slerp.com/forget_password (or https://${merchant.slug}.slerp.com.integrations.slerp.io/forgotpassword if testing). This will then allow user to trigger a reset via their registered email.