Registration & Login
Registration
Section titled “Registration”Register a new user with email and password. Optionally include a display name and custom fields.
import { useAuth } from '@aerostack/react'
function RegisterForm() { const { signUp, loading, error } = useAuth()
const handleRegister = async () => { const result = await signUp(email, password, { name: 'Jane Doe', customFields: { plan: 'free' }, })
if (result.requiresVerification) { // Show "check your email" message } }}import { AerostackClient } from '@aerostack/sdk'
const client = new AerostackClient({ projectId, apiKey })
const result = await client.auth.register({ email: 'user@example.com', password: 'securepassword', name: 'Jane Doe',})POST /v1/public/projects/{slug}/auth/register
{ "email": "user@example.com", "password": "securepassword", "name": "Jane Doe"}Response:
{ "user": { "id": "...", "email": "user@example.com", "name": "Jane Doe" }, "accessToken": "eyJ...", "refreshToken": "...", "requiresVerification": false}const { signIn, user, loading, error } = useAuth()
await signIn('user@example.com', 'password')// user is now populatedconst result = await client.auth.login({ email: 'user@example.com', password: 'password',})// result.accessToken, result.userPOST /v1/public/projects/{slug}/auth/login
{ "email": "user@example.com", "password": "password"}Sign out
Section titled “Sign out”const { signOut } = useAuth()
// Invalidates refresh token server-side + clears local stateawait signOut()Token refresh
Section titled “Token refresh”Tokens expire after 15 minutes by default. Use refreshAccessToken to silently renew:
const { refreshAccessToken, tokens } = useAuth()
// Called automatically by most SDK methods when a 401 is detected.// You can also call it manually:const newTokens = await refreshAccessToken(tokens.refreshToken)Cloudflare Turnstile
Section titled “Cloudflare Turnstile”Pass a Turnstile token to protect register and login from bots:
await signIn(email, password, turnstileToken)await signUp(email, password, { turnstileToken })See the REST API reference for the full endpoint spec.