DashForDevsDocs
DocsNewsAPI v1
dashfordevs.comSign in

© 2026 DashForDevs

DocsNewsdashfordevs.comLegalStatus
DocsAuthenticationLogin / Logout
Introduction
Getting Started
Authentication
RegisterLogin / LogoutPassword ResetProfile Management
Products
Categories
Cart
Checkout
Blog
Reviews
Webhooks
Customers
Orders
Inventory
Shipping
Discounts
Affiliates
Email
Media & Files
Analytics & Tracking
Locations
Tax
Global Data
SEO
Error Handling
Geography
Finance
Automations
Page Types
Surveys
Billing & Subscriptions
Storefront Payments
SDK Reference
REST API
Storefront Architecture
Notifications
Security
Team & Permissions
Migrations & Import
Calendar & Appointments
Contact Forms
AI Bots
Dashboard API
Deployment
Changelog
Troubleshooting
Recipes
CLI & Deployment
Image Pipeline
White-label Platforms
Records Engine
Platform Modules
Platform Security
Site Keys & Client Sites
Use Cases
Operations

Login / Logout

Authenticate customers and manage sessions.

Updated March 29, 2026

On this page
  • Login with OTP
  • Login with Password
  • Token Management
  • Persisting Sessions
  • Logout
  • REST API Endpoints
  • Check Ban Status
  • Next Steps

Login with OTP

The primary login method is OTP (one-time password via email). This works for both new and existing customers:

typescript
import dash from "@/lib/dash"

// Step 1: Request OTP
await dash.auth.requestOTP("customer@example.com")

// Step 2: Customer enters the code from their email
const { customer, access_token } = await dash.auth.verifyOTP({
  email: "customer@example.com",
  code: "384710",
})

Login with Password

Customers who have set a password can also log in directly:

typescript
const { customer, access_token, refresh_token } = await dash.auth.login({
  email: "customer@example.com",
  password: "securePassword123!",
  captcha_token: "optional_turnstile_token",
})

Token Management

After login, the SDK stores tokens internally. Access tokens expire after 24 hours. The SDK handles refresh automatically, but you can also manage tokens manually:

typescript
// Check authentication state
console.log(dash.auth.isAuthenticated) // true
console.log(dash.auth.token)           // "eyJ..."
console.log(dash.auth.customer)        // { id, email, ... }

// Restore session from stored tokens (e.g., on page reload)
dash.auth.setToken(storedAccessToken, storedRefreshToken)

// Manually refresh an expired token
const { access_token } = await dash.auth.refreshAccessToken()

Persisting Sessions

For Next.js apps, store tokens in cookies or localStorage and restore them on mount:

typescript
"use client"
import { useEffect } from "react"
import dash from "@/lib/dash"

export function AuthProvider({ children }) {
  useEffect(() => {
    const token = localStorage.getItem("dash_token")
    const refresh = localStorage.getItem("dash_refresh")
    if (token) dash.auth.setToken(token, refresh)
  }, [])

  return children
}

Logout

Clear the session and invalidate tokens:

typescript
await dash.auth.logout()
// Tokens are cleared, customer is null
console.log(dash.auth.isAuthenticated) // false

The SDK clears all local state including the customer object and tokens. If you stored tokens in cookies or localStorage, remove them after logout.

REST API Endpoints

ActionMethodEndpoint
Request OTPPOST/storefront/auth/request-otp
Verify OTPPOST/storefront/auth/verify-otp
Password LoginPOST/storefront/auth/login
Refresh TokenPOST/storefront/auth/refresh
LogoutPOST/storefront/auth/logout

Check Ban Status

Before or after login, you can check if the customer or IP is banned:

typescript
const { banned, reason } = await dash.auth.checkBan()
if (banned) {
  // Redirect to a banned page or show a message
  console.log("Banned:", reason)
}

Next Steps

  • Password Reset — Handling forgotten passwords
  • Profile Management — Updating customer info
  • API Key Security — Securing your authentication flow
PreviousRegisterNextPassword Reset

On this page

  • Login with OTP
  • Login with Password
  • Token Management
  • Persisting Sessions
  • Logout
  • REST API Endpoints
  • Check Ban Status
  • Next Steps