Signup Form Example

A complete signup form with email, password confirmation, and terms acceptance.

Schema Definition

{
  "type": "signup",
  "title": "Create your account",
  "description": "Get started with your free account today",
  "fields": [
    {
      "name": "name",
      "type": "text",
      "label": "Full Name",
      "placeholder": "John Doe",
      "required": true
    },
    {
      "name": "email",
      "type": "email",
      "label": "Email Address",
      "placeholder": "you@example.com",
      "required": true
    },
    {
      "name": "password",
      "type": "password",
      "label": "Password",
      "placeholder": "Create a strong password",
      "required": true,
      "minLength": 8
    },
    {
      "name": "confirmPassword",
      "type": "password",
      "label": "Confirm Password",
      "placeholder": "Re-enter your password",
      "required": true,
      "matchField": "password"
    },
    {
      "name": "terms",
      "type": "checkbox",
      "label": "I agree to the Terms of Service and Privacy Policy",
      "required": true
    }
  ],
  "submit": "Create Account",
  "footer": {
    "text": "Already have an account?",
    "link": {
      "text": "Sign in",
      "href": "/login"
    }
  }
}

Implementation

import { AuthForm } from "declarative-auth-forms"
import signupSchema from "./signup-schema.json"

export default function SignupPage() {
  const handleSignup = async (data: any) => {
    // Handle signup with Better Auth
    const response = await fetch("/api/auth/signup", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(data),
    })
    
    if (response.ok) {
      // Redirect to dashboard or login
      window.location.href = "/dashboard"
    }
  }

  return (
    <div className="min-h-screen flex items-center justify-center p-4">
      <AuthForm 
        schema={signupSchema} 
        onSubmit={handleSignup}
      />
    </div>
  )
}

Features

  • Full name collection for personalization
  • Email validation with proper format checking
  • Password strength requirements (minimum 8 characters)
  • Password confirmation to prevent typos
  • Terms and conditions acceptance checkbox
  • Link to login page for existing users

Customization

You can customize the signup form by:

  • Adding additional fields like phone number or company name
  • Adjusting password requirements (length, complexity)
  • Customizing error messages
  • Adding social signup options
  • Implementing email verification flow