FeaturesAuthenticationRegistration & Login

Registration & Login

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
    }
  }
}

If email verification is enabled in your project settings, requiresVerification: true is returned and no token is issued until the user verifies their email.

Login

const { signIn, user, loading, error } = useAuth()
 
await signIn('[email protected]', 'password')
// user is now populated

Sign out

const { signOut } = useAuth()
 
// Invalidates refresh token server-side + clears local state
await signOut()

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

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.