"use client" import Link from "next/link" import { useRouter } from "next/navigation" import { useState } from "react" import { authClient } from "@/lib/auth-client" import { useSession } from "@/components/SessionProvider" export default function RegisterPage() { const router = useRouter() const { refreshSession } = useSession() const [error, setError] = useState("") const [loading, setLoading] = useState(false) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setLoading(true) setError("") const formData = new FormData(e.currentTarget) const name = formData.get("name") as string const email = formData.get("email") as string const password = formData.get("password") as string try { console.log("Attempting signup..."); const result = await authClient.signUp.email({ email, password, name, }) console.log("Signup result:", result); if (result.error) { console.error("Signup error:", result.error); setError(result.error.message || "Failed to create account") } else { console.log("Signup successful, redirecting..."); console.log("Result data:", result.data); // Refresh the session after successful registration try { await refreshSession(); console.log("Session refreshed successfully"); } catch (err) { console.error("Failed to refresh session:", err); } // Redirect to admin page which will redirect to profile if not admin console.log("About to redirect to /admin"); router.push("/admin"); console.log("Redirect initiated"); } } catch (err) { console.error("Signup exception:", err); setError("An unexpected error occurred") } finally { setLoading(false) } } return (

Create your account

{error && (
{error}
)}
Already have an account? Sign in
) }