cimplify

Authentication

OTP-based authentication -- no passwords. Supports email and phone.

TS
import { createCimplifyClient } from '@cimplify/sdk'

const client = createCimplifyClient({ publicKey: 'pk_test_...' })

// 1. Request OTP
const otp = await client.auth.requestOtp({ contact: 'jane@example.com', contact_type: 'email' })
if (!otp.ok) throw otp.error

// 2. User enters the code they received
const verify = await client.auth.verifyOtp({ contact: 'jane@example.com', contact_type: 'email', otp_code: '123456' })
if (!verify.ok) throw verify.error

console.log('Authenticated:', verify.value.customer)

// 3. Check session later
const status = await client.auth.getStatus()
if (status.ok) console.log(status.value.is_authenticated)

Cimplify uses OTP-only authentication. There are no password-based flows.

requestOtp

Sends a one-time code to the customer via email or phone.

TS
// Email
await client.auth.requestOtp({ contact: 'user@example.com', contact_type: 'email' })

// Phone
await client.auth.requestOtp({ contact: '+233200000001', contact_type: 'phone' })

verifyOtp

Validates the code and establishes a session.

TS
const result = await client.auth.verifyOtp({
  contact: 'user@example.com',
  contact_type: 'email',
  otp_code: '123456',
})

if (result.ok) {
  console.log(result.value.customer)

  // Set access token if returned (for Link integration)
  if (result.value.session_token) {
    client.setAccessToken(result.value.session_token)
  }
}

Session Methods

TS
const status = await client.auth.getStatus()       // Result<AuthStatus>
const user = await client.auth.getCurrentUser()     // Result<Customer | null>
const authed = await client.auth.isAuthenticated()  // Result<boolean>

await client.auth.logout() // ends session

updateProfile

TS
const updated = await client.auth.updateProfile({
  name: 'Jane Doe',
  email: 'jane@example.com',
  phone: '+233200000001',
})
// Result<Customer> — all fields are optional

Complete Login Flow

TS
async function login(email: string, code: string) {
  const request = await client.auth.requestOtp({ contact: email, contact_type: 'email' })
  if (!request.ok) throw request.error

  // User enters OTP...
  const verify = await client.auth.verifyOtp({ contact: email, contact_type: 'email', otp_code: code })
  if (!verify.ok) throw verify.error

  if (verify.value.session_token) {
    client.setAccessToken(verify.value.session_token)
  }
  return verify.value.customer
}

async function requireAuth() {
  const auth = await client.auth.isAuthenticated()
  if (!auth.ok || !auth.value) throw new Error('Authentication required')

  const user = await client.auth.getCurrentUser()
  if (!user.ok) throw user.error
  return user.value
}

All Methods

MethodReturns
requestOtp({ contact, contact_type })Result<void>
verifyOtp({ contact, contact_type, otp_code })Result<OtpResult>
getStatus()Result<AuthStatus>
getCurrentUser()Result<Customer | null>
isAuthenticated()Result<boolean>
logout()Result<void>
updateProfile({ name?, email?, phone? })Result<Customer>