"use client"; import { FormEvent, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { supabaseBrowser } from "@/lib/supabase/browser"; type LoginFormProps = { redirectTo: string; }; const normalizeRedirect = (redirectTo: string) => { if (!redirectTo.startsWith("/")) return "/courses"; return redirectTo; }; export default function LoginForm({ redirectTo }: LoginFormProps) { const router = useRouter(); const safeRedirect = normalizeRedirect(redirectTo); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const onSubmit = async (event: FormEvent) => { event.preventDefault(); setError(null); setLoading(true); const client = supabaseBrowser(); if (!client) { setLoading(false); setError("Supabase is not configured. Add NEXT_PUBLIC_SUPABASE_* to .env.local."); return; } const { error: signInError } = await client.auth.signInWithPassword({ email, password }); setLoading(false); if (signInError) { setError(signInError.message); return; } router.push(safeRedirect); }; return (

Login

Sign in to access protected learning routes.

{error ?

{error}

: null}

New here?{" "} Create an account

); }