import { Controller, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { createNotification } from "@app/components/notifications"; import { Button, FormControl, Switch } from "@app/components/v2"; import { useServerConfig } from "@app/context"; import { useUpdateServerConfig } from "@app/hooks/api"; import { LoginMethod } from "@app/hooks/api/admin/types"; const formSchema = z.object({ isEmailEnabled: z.boolean(), isGoogleEnabled: z.boolean(), isGithubEnabled: z.boolean(), isGitlabEnabled: z.boolean(), isSamlEnabled: z.boolean(), isLdapEnabled: z.boolean(), isOidcEnabled: z.boolean() }); type TAuthForm = z.infer; export const AuthenticationPageForm = () => { const { config } = useServerConfig(); const { enabledLoginMethods } = config; const { mutateAsync: updateServerConfig } = useUpdateServerConfig(); const { control, handleSubmit, formState: { isSubmitting, isDirty } } = useForm({ resolver: zodResolver(formSchema), // if not yet explicitly defined by the admin, all login methods should be enabled by default values: enabledLoginMethods ? { isEmailEnabled: enabledLoginMethods.includes(LoginMethod.EMAIL), isGoogleEnabled: enabledLoginMethods.includes(LoginMethod.GOOGLE), isGithubEnabled: enabledLoginMethods.includes(LoginMethod.GITHUB), isGitlabEnabled: enabledLoginMethods.includes(LoginMethod.GITLAB), isSamlEnabled: enabledLoginMethods.includes(LoginMethod.SAML), isLdapEnabled: enabledLoginMethods.includes(LoginMethod.LDAP), isOidcEnabled: enabledLoginMethods.includes(LoginMethod.OIDC) } : { isEmailEnabled: true, isGoogleEnabled: true, isGithubEnabled: true, isGitlabEnabled: true, isSamlEnabled: true, isLdapEnabled: true, isOidcEnabled: true } }); const onAuthFormSubmit = async (formData: TAuthForm) => { try { const enabledMethods: LoginMethod[] = []; if (formData.isEmailEnabled) { enabledMethods.push(LoginMethod.EMAIL); } if (formData.isGoogleEnabled) { enabledMethods.push(LoginMethod.GOOGLE); } if (formData.isGithubEnabled) { enabledMethods.push(LoginMethod.GITHUB); } if (formData.isGitlabEnabled) { enabledMethods.push(LoginMethod.GITLAB); } if (formData.isSamlEnabled) { enabledMethods.push(LoginMethod.SAML); } if (formData.isLdapEnabled) { enabledMethods.push(LoginMethod.LDAP); } if (formData.isOidcEnabled) { enabledMethods.push(LoginMethod.OIDC); } if (!enabledMethods.length) { createNotification({ type: "error", text: "At least one login method should be enabled." }); return; } await updateServerConfig({ enabledLoginMethods: enabledMethods }); createNotification({ text: "Login methods have been successfully updated.", type: "success" }); } catch (e) { console.error(e); createNotification({ type: "error", text: "Failed to update login methods." }); } }; return (
Login Methods
Select the login methods you wish to allow for all users of this instance.
{ return ( field.onChange(value)} isChecked={field.value} >

Email

); }} /> { return ( field.onChange(value)} isChecked={field.value} >

Google SSO

); }} /> { return ( field.onChange(value)} isChecked={field.value} >

Github SSO

); }} /> { return ( field.onChange(value)} isChecked={field.value} >

Gitlab SSO

); }} /> { return ( field.onChange(value)} isChecked={field.value} >

SAML SSO

); }} /> { return ( field.onChange(value)} isChecked={field.value} >

OIDC SSO

); }} />
{ return ( field.onChange(value)} isChecked={field.value} >

LDAP

); }} /> ); };