import AccentSubmitButton from "@/components/AccentSubmitButton"; import TextInput from "@/components/TextInput"; import CenteredForm from "@/layouts/CenteredForm"; import { signIn } from "next-auth/react"; import Link from "next/link"; import { useState, FormEvent } from "react"; import { toast } from "react-hot-toast"; interface FormData { username: string; password: string; } const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER; const keycloakEnabled = process.env.NEXT_PUBLIC_KEYCLOAK_ENABLED; const authentikEnabled = process.env.NEXT_PUBLIC_AUTHENTIK_ENABLED; export default function Login() { const [submitLoader, setSubmitLoader] = useState(false); const [form, setForm] = useState({ username: "", password: "", }); async function loginUser(event: FormEvent) { event.preventDefault(); if (form.username !== "" && form.password !== "") { setSubmitLoader(true); const load = toast.loading("Authenticating..."); const res = await signIn("credentials", { username: form.username, password: form.password, redirect: false, }); toast.dismiss(load); setSubmitLoader(false); if (!res?.ok) { toast.error("Invalid login."); } } else { toast.error("Please fill out all the fields."); } } async function loginUserKeycloak() { setSubmitLoader(true); const load = toast.loading("Authenticating..."); const res = await signIn("keycloak", {}); toast.dismiss(load); setSubmitLoader(false); } async function loginUserAuthentik() { setSubmitLoader(true); const load = toast.loading("Authenticating..."); const res = await signIn("authentik", {}); toast.dismiss(load); setSubmitLoader(false); } return (
{process.env.NEXT_PUBLIC_DISABLE_LOGIN !== "true" ? ( <>

Enter your credentials

Username {emailEnabled ? " or Email" : undefined}

setForm({ ...form, username: e.target.value }) } />

Password

setForm({ ...form, password: e.target.value }) } /> {emailEnabled && (
Forgot Password?
)}
) : undefined} {process.env.NEXT_PUBLIC_KEYCLOAK_ENABLED === "true" ? ( ) : undefined} {process.env.NEXT_PUBLIC_AUTHENTIK_ENABLED === "true" ? ( ) : undefined} {process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" ? undefined : (

New here?

Sign Up
)}
); }