'use client'
import { useState } from 'react'
import { createClient } from '@/lib/supabase/client'
import Link from 'next/link'
export default function SignupPage() {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const [success, setSuccess] = useState(false)
const handleSignup = async (e: React.FormEvent) => {
e.preventDefault()
setLoading(true)
setError(null)
try {
const supabase = createClient()
const { error: signUpError } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${window.location.origin}/auth/callback`,
},
})
if (signUpError) throw signUpError
setSuccess(true)
} catch (err) {
setError(err instanceof Error ? err.message : 'An error occurred')
} finally {
setLoading(false)
}
}
if (success) {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4">
<div className="max-w-md w-full space-y-8">
<div>
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">Check your email</h2>
<p className="mt-2 text-center text-sm text-gray-600">
We've sent a confirmation link to {email}
</p>
</div>
<div className="text-center">
<Link href="/login" className="font-medium text-blue-600 hover:text-blue-500">
Back to login
</Link>
</div>
</div>
</div>
)
}
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4">
<div className="max-w-md w-full space-y-8">
<div className="text-center">
<h1 className="text-2xl font-bold text-blue-600">Hostaway MCP Dashboard</h1>
<h2 className="mt-4 text-3xl font-extrabold text-gray-900">Create your account</h2>
<p className="mt-2 text-sm text-gray-600">Get started with AI-powered property management</p>
</div>
<form className="mt-8 space-y-6" onSubmit={handleSignup}>
{error && <div className="rounded-md bg-red-50 p-4 text-sm text-red-700">{error}</div>}
<div className="space-y-4">
<input
type="email"
required
className="appearance-none relative block w-full px-3 py-2 border border-gray-300 rounded-md"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
disabled={loading}
/>
<input
type="password"
required
minLength={8}
className="appearance-none relative block w-full px-3 py-2 border border-gray-300 rounded-md"
placeholder="Password (min 8 characters)"
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={loading}
/>
</div>
<button
type="submit"
disabled={loading}
className="w-full py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 disabled:opacity-50"
>
{loading ? 'Creating...' : 'Sign up'}
</button>
<p className="text-center text-sm text-gray-600">
Already have an account?{' '}
<Link href="/login" className="font-medium text-blue-600 hover:text-blue-500">
Sign in
</Link>
</p>
</form>
</div>
</div>
)
}