Auth
Phone-based OTP authentication. The recommended approach is the <configure-auth> web component, which handles the full flow. The SDK methods below are internal — used by the component, not called directly.
<configure-auth> Component (Recommended)
The drop-in web component that handles the complete phone OTP flow:
html
<script src="https://unpkg.com/configure/dist/configure-components.global.js"></script>
<configure-auth api-key="pk_..." agent="your-agent"></configure-auth>
<script>
document.querySelector('configure-auth')
.addEventListener('configure:authenticated', (e) => {
const { token, userId } = e.detail;
});
</script>Attributes
| Name | Type | Required | Description |
|---|---|---|---|
api-key | string | Yes | Publishable key (pk_...) — safe for client-side use. |
agent | string | Yes | Which agent is authenticating. |
theme | string | No | light or dark. Defaults to system preference. |
base-url | string | No | API base URL override for staging/local dev. |
Events
| Event | Detail | Description |
|---|---|---|
configure:authenticated | { token, userId, phone } | Fired on successful auth. |
configure:error | { message } | Fired on auth failure. |
configure:logout | {} | Fired when logout() is called. |
Methods
| Method | Returns | Description |
|---|---|---|
getToken() | string | null | Current auth token. |
getUserId() | string | null | Current user ID. |
logout() | void | Clears stored auth, resets to phone input. |
SDK Methods (Internal)
WARNING
These methods are used internally by the <configure-auth> component. Use the component instead of calling these directly.
sendOtp
typescript
auth.sendOtp(phone: string): Promise<OtpStartResponse>Send a one-time password to a phone number via SMS.
| Name | Type | Required | Description |
|---|---|---|---|
phone | string | Yes | Phone number in E.164 format (e.g., "+14155551234"). |
Returns { ok: boolean }.
verifyOtp
typescript
auth.verifyOtp(phone: string, code: string): Promise<OtpVerifyResponse>Verify a 6-digit OTP code. Returns a JWT token and user ID on success.
| Name | Type | Required | Description |
|---|---|---|---|
phone | string | Yes | Phone number in E.164 format. Must match the number used in sendOtp. |
code | string | Yes | 6-digit OTP code received via SMS. |
Returns { token: string, userId: string }.
getDemo
typescript
auth.getDemo(): Promise<string>Get a demo authentication token for development and testing. Not for production use.
Returns a demo JWT token string.