"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { supabase } from "@/lib/supabase"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import Link from "next/link"; import { SiteLogo } from "@/components/site-logo"; import { CheckCircle2 } from "lucide-react"; import { useAuth } from "@/contexts/AuthContext"; import { updateUserProfile } from "@/app/lib/mikeApi"; export default function SignupPage() { const router = useRouter(); const { isAuthenticated, authLoading } = useAuth(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [name, setName] = useState(""); const [organisation, setOrganisation] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); useEffect(() => { if (!authLoading && isAuthenticated && !success) { router.replace("/assistant"); } }, [authLoading, isAuthenticated, router, success]); const handleSignup = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); // Validate passwords match if (password !== confirmPassword) { setError("Passwords do not match"); setLoading(false); return; } // Validate password length if (password.length < 6) { setError("Password must be at least 6 characters"); setLoading(false); return; } try { const { data, error } = await supabase.auth.signUp({ email, password, }); if (error) throw error; if (data.session) { const trimmedName = name.trim(); const trimmedOrg = organisation.trim(); if (trimmedName || trimmedOrg) { try { await updateUserProfile({ ...(trimmedName && { displayName: trimmedName }), ...(trimmedOrg && { organisation: trimmedOrg }), }); } catch (profileError) { console.error( "[signup] failed to persist profile fields", profileError, ); } } } setSuccess(true); setTimeout(() => { router.push("/assistant"); }, 2000); } catch (error: unknown) { setError( error instanceof Error ? error.message : "An error occurred during signup", ); } finally { setLoading(false); } }; // Success View if (success) { return (

Account created!

Redirecting you to the home page...

); } // Default Signup Form View return (

Create Account

Log in Sign up
setName(e.target.value)} placeholder="Your name" className="w-full" />
setOrganisation(e.target.value) } placeholder="Your organisation" className="w-full" />
setEmail(e.target.value)} placeholder="Enter your email" required className="w-full" />
setPassword(e.target.value)} placeholder="Create a password (min. 6 characters)" required className="w-full" />
setConfirmPassword(e.target.value) } placeholder="Confirm your password" required className="w-full" />
{error && (
{error}
)}
{/* Terms and Privacy */}
By signing up, you agree to our{" "} Terms of Use {" "} and{" "} Privacy Policy

Mike hosted on MikeOSS.com is currently a demo service. Please do not upload, submit, or store sensitive, confidential, privileged, client, or personally identifiable documents.

); }