Register
Create a new customer account.
Updated
On this page
Overview
DashForDevs uses a passwordless-first approach. Customers register by verifying their email with a one-time code (OTP). No separate signup form is needed — requesting an OTP for a new email automatically creates the customer account.
Registration via OTP
Request an OTP code to be sent to the customer's email:
import dash from "@/lib/dash"
// Step 1: Request OTP — this creates the customer if they don't exist
const result = await dash.auth.requestOTP("newcustomer@example.com", {
accepts_marketing: true, // optional: opt into marketing emails
captcha_token: "...", // optional: Turnstile/reCAPTCHA token
})
// result = { message: "OTP sent", email: "newcustomer@example.com" }
Verify the Code
After the customer enters the code from their email:
// Step 2: Verify OTP
const { customer, access_token, refresh_token } = await dash.auth.verifyOTP({
email: "newcustomer@example.com",
code: "482901",
})
// Customer is now authenticated
console.log(customer)
// {
// id: "cust_abc123",
// email: "newcustomer@example.com",
// first_name: "",
// last_name: "",
// loyalty_points: 0,
// ...
// }
The SDK automatically stores the tokens internally. All subsequent requests that require authentication will include them.
Setting a Password (Optional)
After OTP registration, customers can set a password for future logins:
// Must be authenticated first
await dash.auth.setPassword("securePassword123!")
// Now the customer can use either OTP or password to log in
See Login / Logout for password-based authentication.
REST API Equivalent
| Step | Method | Endpoint |
|---|---|---|
| Request OTP | POST | /storefront/auth/request-otp |
| Verify OTP | POST | /storefront/auth/verify-otp |
| Set Password | POST | /storefront/auth/set-password |
Request Body — Request OTP
{
"email": "newcustomer@example.com",
"accepts_marketing": true,
"captcha_token": "optional_turnstile_token"
}
Request Body — Verify OTP
{
"email": "newcustomer@example.com",
"code": "482901"
}
Response — Verify OTP
{
"access_token": "eyJ...",
"refresh_token": "eyJ...",
"token_type": "Bearer",
"expires_in": 86400,
"customer": {
"id": "cust_abc123",
"email": "newcustomer@example.com",
"first_name": "",
"last_name": "",
"has_password": false,
"loyalty_points": 0
}
}
Cart Migration
If the customer had a guest cart before registering, merge it into their account immediately after authentication:
// After verifyOTP succeeds
await dash.cart.migrateToUser()
// Guest cart items are now in the customer's persistent cart
See Get Cart for more on cart migration.
Next Steps
- Login / Logout — Password-based login and session management
- Profile Management — Updating customer details after registration
- Customer Data — How customer data is stored and protected