Update [...nextauth].ts

Added Authentik provider
Added option to disable standard login with NEXT_PUBLIC_DISABLE_LOGIN=true
This commit is contained in:
Jacq
2023-11-26 12:44:44 +01:00
parent 0f40578ca9
commit b1dd9d66b6
3 changed files with 64 additions and 0 deletions
+27
View File
@@ -13,6 +13,7 @@ interface FormData {
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);
@@ -60,10 +61,25 @@ export default function Login() {
setSubmitLoader(false);
}
async function loginUserAuthentik() {
setSubmitLoader(true);
const load = toast.loading("Authenticating...");
const res = await signIn("authentik", {});
toast.dismiss(load);
setSubmitLoader(false);
}
return (
<CenteredForm text="Sign in to your account">
<form onSubmit={loginUser}>
<div className="p-4 mx-auto flex flex-col gap-3 justify-between max-w-[30rem] min-w-80 w-full bg-slate-50 dark:bg-neutral-800 rounded-2xl shadow-md border border-sky-100 dark:border-neutral-700">
{process.env.NEXT_PUBLIC_DISABLE_LOGIN !== "true" ? (
<div>
<p className="text-3xl text-black dark:text-white text-center font-extralight">
Enter your credentials
</p>
@@ -115,6 +131,8 @@ export default function Login() {
className=" w-full text-center"
loading={submitLoader}
/>
</div>
) : undefined}
{process.env.NEXT_PUBLIC_KEYCLOAK_ENABLED === "true" ? (
<SubmitButton
type="button"
@@ -124,6 +142,15 @@ export default function Login() {
loading={submitLoader}
/>
) : undefined}
{process.env.NEXT_PUBLIC_AUTHENTIK_ENABLED === "true" ? (
<SubmitButton
type="button"
onClick={loginUserAuthentik}
label="Sign in with Authentiks"
className=" w-full text-center"
loading={submitLoader}
/>
) : undefined}
{process.env.NEXT_PUBLIC_DISABLE_REGISTRATION ===
"true" ? undefined : (
<div className="flex items-baseline gap-1 justify-center">