"use client"; import React, { useState, useEffect } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { useAuth } from "../hooks/useAuth"; export default function LoginPage() { const [token, setToken] = useState(""); const [refreshToken, setRefreshToken] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const router = useRouter(); const searchParams = useSearchParams(); const { login, authenticated } = useAuth(); const redirectTo = searchParams.get("redirect_to") || "/"; const errorParam = searchParams.get("error"); useEffect(() => { if (authenticated) { router.push(redirectTo); } }, [authenticated, redirectTo, router]); useEffect(() => { if (errorParam) { switch (errorParam) { case "no_token": setError("No authentication token provided"); break; case "invalid_token": setError("Invalid authentication token"); break; case "auth_failed": setError("Authentication failed"); break; case "auth_check_failed": setError("Authentication check failed"); break; default: setError("An error occurred during authentication"); } } }, [errorParam]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!token.trim()) { setError("Please enter an access token"); return; } setLoading(true); setError(""); try { await login(token.trim(), refreshToken.trim() || undefined); router.push(redirectTo); } catch (err) { setError("Login failed. Please check your token and try again."); } finally { setLoading(false); } }; if (authenticated) { return
Redirecting...
; } return (

Sign in to your account

Enter your Supabase authentication token

{error && (
{error}
)}
setToken(e.target.value)} />
setRefreshToken(e.target.value)} />

You can also authenticate by visiting:{" "} /api/auth/callback?token=YOUR_TOKEN

); }