import { useState } from "react"; import { useForm } from "react-hook-form"; import { Settings, ExternalLink } from "lucide-react"; import { SettingsDialog } from "@/components/settings-dialog"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { Link } from "react-router-dom"; import { useLogin, useOidcLogin } from "@/hooks/use-auth"; import { useConfig } from "@/hooks/useConfig"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { ApiError } from "@/lib/api"; import { toast } from "sonner"; import { useTranslation } from "react-i18next"; const loginSchema = z.object({ email: z.string().email("Invalid email address"), password: z.string().min(6, "Password must be at least 6 characters"), }); type LoginFormValues = z.infer; export default function LoginPage() { const { mutate: login, isPending } = useLogin(); const { data: config } = useConfig(); const { t } = useTranslation(); const startOidcLogin = useOidcLogin(); const form = useForm({ resolver: zodResolver(loginSchema), defaultValues: { email: "", password: "", }, }); const onSubmit = (data: LoginFormValues) => { login(data, { onError: (error: any) => { if (error instanceof ApiError) { toast.error(error.message); } else { toast.error(t("Failed to login")); } }, }); }; const [settingsOpen, setSettingsOpen] = useState(false); return (
{t("Welcome back")} {t("Enter your email to sign in to your account")} {/* OIDC/SSO Login Button */} {config?.oidc_enabled && ( <> {/* Divider only if both OIDC and password login are enabled */} {config?.password_login_enabled && (
{t("Or continue with")}
)} )} {/* Email/Password Form - only show if password login is enabled */} {config?.password_login_enabled !== false && (
( {t("Email")} )} /> ( {t("Password")} )} /> )}
{config?.allow_registration !== false && (

{t("Don't have an account?")}{" "} {t("Sign up")}

)}
); }