2023-06-09 18:21:18 +10:00
|
|
|
'use client';
|
|
|
|
|
|
2024-09-19 13:45:08 +10:00
|
|
|
import { useEffect, useMemo, useState } from 'react';
|
2023-08-26 12:31:40 +05:30
|
|
|
|
2024-02-22 01:57:46 +05:30
|
|
|
import Link from 'next/link';
|
2024-01-16 14:25:05 +02:00
|
|
|
import { useRouter } from 'next/navigation';
|
|
|
|
|
|
2023-06-09 18:21:18 +10:00
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
2024-08-27 20:34:39 +09:00
|
|
|
import { Trans, msg } from '@lingui/macro';
|
|
|
|
|
import { useLingui } from '@lingui/react';
|
2024-03-26 21:11:59 +08:00
|
|
|
import { browserSupportsWebAuthn, startAuthentication } from '@simplewebauthn/browser';
|
|
|
|
|
import { KeyRoundIcon } from 'lucide-react';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { signIn } from 'next-auth/react';
|
|
|
|
|
import { useForm } from 'react-hook-form';
|
2024-04-13 20:46:08 -04:00
|
|
|
import { FaIdCardClip } from 'react-icons/fa6';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { FcGoogle } from 'react-icons/fc';
|
2024-03-26 21:11:59 +08:00
|
|
|
import { match } from 'ts-pattern';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
import { useFeatureFlags } from '@documenso/lib/client-only/providers/feature-flag';
|
|
|
|
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
2023-09-05 11:29:23 +10:00
|
|
|
import { ErrorCode, isErrorCode } from '@documenso/lib/next-auth/error-codes';
|
2024-03-26 21:11:59 +08:00
|
|
|
import { trpc } from '@documenso/trpc/react';
|
2024-01-30 06:12:52 +05:30
|
|
|
import { ZCurrentPasswordSchema } from '@documenso/trpc/server/auth-router/schema';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { cn } from '@documenso/ui/lib/utils';
|
|
|
|
|
import { Button } from '@documenso/ui/primitives/button';
|
2024-01-30 17:31:27 +11:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from '@documenso/ui/primitives/dialog';
|
2023-12-02 17:54:55 +05:30
|
|
|
import {
|
|
|
|
|
Form,
|
|
|
|
|
FormControl,
|
|
|
|
|
FormField,
|
|
|
|
|
FormItem,
|
|
|
|
|
FormLabel,
|
|
|
|
|
FormMessage,
|
|
|
|
|
} from '@documenso/ui/primitives/form/form';
|
|
|
|
|
import { Input } from '@documenso/ui/primitives/input';
|
|
|
|
|
import { PasswordInput } from '@documenso/ui/primitives/password-input';
|
2024-05-24 03:31:19 +00:00
|
|
|
import { PinInput, PinInputGroup, PinInputSlot } from '@documenso/ui/primitives/pin-input';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
|
|
|
|
2023-12-01 05:52:16 +05:30
|
|
|
const ERROR_MESSAGES: Partial<Record<keyof typeof ErrorCode, string>> = {
|
2023-09-05 11:29:23 +10:00
|
|
|
[ErrorCode.CREDENTIALS_NOT_FOUND]: 'The email or password provided is incorrect',
|
|
|
|
|
[ErrorCode.INCORRECT_EMAIL_PASSWORD]: 'The email or password provided is incorrect',
|
|
|
|
|
[ErrorCode.USER_MISSING_PASSWORD]:
|
|
|
|
|
'This account appears to be using a social login method, please sign in using that method',
|
2023-12-01 05:52:16 +05:30
|
|
|
[ErrorCode.INCORRECT_TWO_FACTOR_CODE]: 'The two-factor authentication code provided is incorrect',
|
|
|
|
|
[ErrorCode.INCORRECT_TWO_FACTOR_BACKUP_CODE]: 'The backup code provided is incorrect',
|
2024-01-16 14:25:05 +02:00
|
|
|
[ErrorCode.UNVERIFIED_EMAIL]:
|
|
|
|
|
'This account has not been verified. Please verify your account before signing in.',
|
2024-12-17 13:35:59 +02:00
|
|
|
[ErrorCode.ACCOUNT_DISABLED]: 'This account has been disabled. Please contact support.',
|
2023-09-01 16:25:27 +05:30
|
|
|
};
|
|
|
|
|
|
2023-12-01 05:52:16 +05:30
|
|
|
const TwoFactorEnabledErrorCode = ErrorCode.TWO_FACTOR_MISSING_CREDENTIALS;
|
|
|
|
|
|
2023-09-12 14:29:27 +10:00
|
|
|
const LOGIN_REDIRECT_PATH = '/documents';
|
|
|
|
|
|
2023-06-09 18:21:18 +10:00
|
|
|
export const ZSignInFormSchema = z.object({
|
|
|
|
|
email: z.string().email().min(1),
|
2024-01-30 06:12:52 +05:30
|
|
|
password: ZCurrentPasswordSchema,
|
2023-12-01 05:52:16 +05:30
|
|
|
totpCode: z.string().trim().optional(),
|
|
|
|
|
backupCode: z.string().trim().optional(),
|
2023-06-09 18:21:18 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TSignInFormSchema = z.infer<typeof ZSignInFormSchema>;
|
|
|
|
|
|
|
|
|
|
export type SignInFormProps = {
|
|
|
|
|
className?: string;
|
2024-02-06 16:16:10 +11:00
|
|
|
initialEmail?: string;
|
2024-01-23 11:38:48 +05:30
|
|
|
isGoogleSSOEnabled?: boolean;
|
2024-04-13 20:46:08 -04:00
|
|
|
isOIDCSSOEnabled?: boolean;
|
2024-07-31 14:22:52 +02:00
|
|
|
oidcProviderLabel?: string;
|
2024-09-04 23:13:00 +10:00
|
|
|
returnTo?: string;
|
2023-06-09 18:21:18 +10:00
|
|
|
};
|
|
|
|
|
|
2024-04-13 20:46:08 -04:00
|
|
|
export const SignInForm = ({
|
|
|
|
|
className,
|
|
|
|
|
initialEmail,
|
|
|
|
|
isGoogleSSOEnabled,
|
|
|
|
|
isOIDCSSOEnabled,
|
2024-07-31 14:22:52 +02:00
|
|
|
oidcProviderLabel,
|
2024-09-04 23:13:00 +10:00
|
|
|
returnTo,
|
2024-04-13 20:46:08 -04:00
|
|
|
}: SignInFormProps) => {
|
2024-08-27 20:34:39 +09:00
|
|
|
const { _ } = useLingui();
|
2023-09-12 14:29:27 +10:00
|
|
|
const { toast } = useToast();
|
2024-03-26 21:11:59 +08:00
|
|
|
const { getFlag } = useFeatureFlags();
|
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
2023-12-01 05:52:16 +05:30
|
|
|
const [isTwoFactorAuthenticationDialogOpen, setIsTwoFactorAuthenticationDialogOpen] =
|
|
|
|
|
useState(false);
|
|
|
|
|
|
|
|
|
|
const [twoFactorAuthenticationMethod, setTwoFactorAuthenticationMethod] = useState<
|
|
|
|
|
'totp' | 'backup'
|
|
|
|
|
>('totp');
|
2023-09-12 14:29:27 +10:00
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
const [isPasskeyLoading, setIsPasskeyLoading] = useState(false);
|
|
|
|
|
|
|
|
|
|
const isPasskeyEnabled = getFlag('app_passkey');
|
|
|
|
|
|
2024-09-04 23:13:00 +10:00
|
|
|
const callbackUrl = useMemo(() => {
|
|
|
|
|
// Handle SSR
|
|
|
|
|
if (typeof window === 'undefined') {
|
|
|
|
|
return LOGIN_REDIRECT_PATH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let url = new URL(returnTo || LOGIN_REDIRECT_PATH, window.location.origin);
|
|
|
|
|
|
|
|
|
|
// Don't allow different origins
|
|
|
|
|
if (url.origin !== window.location.origin) {
|
|
|
|
|
url = new URL(LOGIN_REDIRECT_PATH, window.location.origin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return url.toString();
|
|
|
|
|
}, [returnTo]);
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
const { mutateAsync: createPasskeySigninOptions } =
|
|
|
|
|
trpc.auth.createPasskeySigninOptions.useMutation();
|
|
|
|
|
|
2023-12-02 17:54:55 +05:30
|
|
|
const form = useForm<TSignInFormSchema>({
|
2023-06-09 18:21:18 +10:00
|
|
|
values: {
|
2024-02-06 16:16:10 +11:00
|
|
|
email: initialEmail ?? '',
|
2023-06-09 18:21:18 +10:00
|
|
|
password: '',
|
2023-12-01 05:52:16 +05:30
|
|
|
totpCode: '',
|
|
|
|
|
backupCode: '',
|
2023-06-09 18:21:18 +10:00
|
|
|
},
|
|
|
|
|
resolver: zodResolver(ZSignInFormSchema),
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-02 17:54:55 +05:30
|
|
|
const isSubmitting = form.formState.isSubmitting;
|
|
|
|
|
|
2023-12-01 05:52:16 +05:30
|
|
|
const onCloseTwoFactorAuthenticationDialog = () => {
|
2023-12-02 17:54:55 +05:30
|
|
|
form.setValue('totpCode', '');
|
|
|
|
|
form.setValue('backupCode', '');
|
2023-12-01 05:52:16 +05:30
|
|
|
|
|
|
|
|
setIsTwoFactorAuthenticationDialogOpen(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onToggleTwoFactorAuthenticationMethodClick = () => {
|
|
|
|
|
const method = twoFactorAuthenticationMethod === 'totp' ? 'backup' : 'totp';
|
|
|
|
|
|
|
|
|
|
if (method === 'totp') {
|
2023-12-02 17:54:55 +05:30
|
|
|
form.setValue('backupCode', '');
|
2023-12-01 05:52:16 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (method === 'backup') {
|
2023-12-02 17:54:55 +05:30
|
|
|
form.setValue('totpCode', '');
|
2023-12-01 05:52:16 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTwoFactorAuthenticationMethod(method);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
const onSignInWithPasskey = async () => {
|
2024-03-31 15:49:12 +08:00
|
|
|
if (!browserSupportsWebAuthn()) {
|
2024-03-26 21:11:59 +08:00
|
|
|
toast({
|
2024-08-27 20:34:39 +09:00
|
|
|
title: _(msg`Not supported`),
|
|
|
|
|
description: _(msg`Passkeys are not supported on this browser`),
|
2024-03-26 21:11:59 +08:00
|
|
|
duration: 10000,
|
|
|
|
|
variant: 'destructive',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setIsPasskeyLoading(true);
|
|
|
|
|
|
|
|
|
|
const options = await createPasskeySigninOptions();
|
|
|
|
|
|
|
|
|
|
const credential = await startAuthentication(options);
|
|
|
|
|
|
|
|
|
|
const result = await signIn('webauthn', {
|
|
|
|
|
credential: JSON.stringify(credential),
|
2024-09-04 23:13:00 +10:00
|
|
|
callbackUrl,
|
2024-03-26 21:11:59 +08:00
|
|
|
redirect: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!result?.url || result.error) {
|
|
|
|
|
throw new AppError(result?.error ?? '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.location.href = result.url;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
setIsPasskeyLoading(false);
|
|
|
|
|
|
|
|
|
|
if (err.name === 'NotAllowedError') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const error = AppError.parseError(err);
|
|
|
|
|
|
|
|
|
|
const errorMessage = match(error.code)
|
|
|
|
|
.with(
|
|
|
|
|
AppErrorCode.NOT_SETUP,
|
|
|
|
|
() =>
|
2024-08-27 20:34:39 +09:00
|
|
|
msg`This passkey is not configured for this application. Please login and add one in the user settings.`,
|
2024-03-26 21:11:59 +08:00
|
|
|
)
|
2024-08-27 20:34:39 +09:00
|
|
|
.with(AppErrorCode.EXPIRED_CODE, () => msg`This session has expired. Please try again.`)
|
|
|
|
|
.otherwise(() => msg`Please try again later or login using your normal details`);
|
2024-03-26 21:11:59 +08:00
|
|
|
|
|
|
|
|
toast({
|
|
|
|
|
title: 'Something went wrong',
|
2024-08-27 20:34:39 +09:00
|
|
|
description: _(errorMessage),
|
2024-03-26 21:11:59 +08:00
|
|
|
duration: 10000,
|
|
|
|
|
variant: 'destructive',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-01 05:52:16 +05:30
|
|
|
const onFormSubmit = async ({ email, password, totpCode, backupCode }: TSignInFormSchema) => {
|
2023-09-26 16:17:01 +10:00
|
|
|
try {
|
2023-12-01 05:52:16 +05:30
|
|
|
const credentials: Record<string, string> = {
|
2023-09-26 16:17:01 +10:00
|
|
|
email,
|
|
|
|
|
password,
|
2023-12-01 05:52:16 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (totpCode) {
|
|
|
|
|
credentials.totpCode = totpCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (backupCode) {
|
|
|
|
|
credentials.backupCode = backupCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await signIn('credentials', {
|
|
|
|
|
...credentials,
|
2024-09-04 23:13:00 +10:00
|
|
|
callbackUrl,
|
2023-09-26 16:17:01 +10:00
|
|
|
redirect: false,
|
|
|
|
|
});
|
2023-09-05 11:29:23 +10:00
|
|
|
|
2023-09-26 16:17:01 +10:00
|
|
|
if (result?.error && isErrorCode(result.error)) {
|
2023-12-01 05:52:16 +05:30
|
|
|
if (result.error === TwoFactorEnabledErrorCode) {
|
|
|
|
|
setIsTwoFactorAuthenticationDialogOpen(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const errorMessage = ERROR_MESSAGES[result.error];
|
|
|
|
|
|
2024-01-16 14:25:05 +02:00
|
|
|
if (result.error === ErrorCode.UNVERIFIED_EMAIL) {
|
2024-01-30 12:54:48 +02:00
|
|
|
router.push(`/unverified-account`);
|
2024-01-16 14:25:05 +02:00
|
|
|
|
2024-01-30 12:54:48 +02:00
|
|
|
toast({
|
2024-08-27 20:34:39 +09:00
|
|
|
title: _(msg`Unable to sign in`),
|
|
|
|
|
description: errorMessage ?? _(msg`An unknown error occurred`),
|
2024-01-30 12:54:48 +02:00
|
|
|
});
|
2024-01-16 14:25:05 +02:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-02 11:46:12 +05:30
|
|
|
toast({
|
2024-08-27 20:34:39 +09:00
|
|
|
title: _(msg`Unable to sign in`),
|
|
|
|
|
description: errorMessage ?? _(msg`An unknown error occurred`),
|
2023-09-02 11:46:12 +05:30
|
|
|
variant: 'destructive',
|
|
|
|
|
});
|
2023-09-05 11:29:23 +10:00
|
|
|
|
2023-09-26 16:17:01 +10:00
|
|
|
return;
|
2023-09-02 11:46:12 +05:30
|
|
|
}
|
|
|
|
|
|
2023-09-26 16:17:01 +10:00
|
|
|
if (!result?.url) {
|
|
|
|
|
throw new Error('An unknown error occurred');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.location.href = result.url;
|
2023-06-09 18:21:18 +10:00
|
|
|
} catch (err) {
|
|
|
|
|
toast({
|
2024-08-27 20:34:39 +09:00
|
|
|
title: _(msg`An unknown error occurred`),
|
|
|
|
|
description: _(
|
|
|
|
|
msg`We encountered an unknown error while attempting to sign you In. Please try again later.`,
|
|
|
|
|
),
|
2023-06-09 18:21:18 +10:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSignInWithGoogleClick = async () => {
|
|
|
|
|
try {
|
2024-09-04 23:13:00 +10:00
|
|
|
await signIn('google', {
|
|
|
|
|
callbackUrl,
|
|
|
|
|
});
|
2023-06-09 18:21:18 +10:00
|
|
|
} catch (err) {
|
|
|
|
|
toast({
|
2024-08-27 20:34:39 +09:00
|
|
|
title: _(msg`An unknown error occurred`),
|
|
|
|
|
description: _(
|
|
|
|
|
msg`We encountered an unknown error while attempting to sign you In. Please try again later.`,
|
|
|
|
|
),
|
2023-06-09 18:21:18 +10:00
|
|
|
variant: 'destructive',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-13 20:46:08 -04:00
|
|
|
const onSignInWithOIDCClick = async () => {
|
|
|
|
|
try {
|
2024-09-04 23:13:00 +10:00
|
|
|
await signIn('oidc', {
|
|
|
|
|
callbackUrl,
|
|
|
|
|
});
|
2024-04-13 20:46:08 -04:00
|
|
|
} catch (err) {
|
|
|
|
|
toast({
|
2024-08-27 20:34:39 +09:00
|
|
|
title: _(msg`An unknown error occurred`),
|
|
|
|
|
description: _(
|
|
|
|
|
msg`We encountered an unknown error while attempting to sign you In. Please try again later.`,
|
|
|
|
|
),
|
2024-04-13 20:46:08 -04:00
|
|
|
variant: 'destructive',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-19 13:45:08 +10:00
|
|
|
useEffect(() => {
|
|
|
|
|
const hash = window.location.hash.slice(1);
|
|
|
|
|
|
|
|
|
|
const params = new URLSearchParams(hash);
|
|
|
|
|
|
|
|
|
|
const email = params.get('email');
|
|
|
|
|
|
|
|
|
|
if (email) {
|
|
|
|
|
form.setValue('email', email);
|
|
|
|
|
}
|
|
|
|
|
}, [form]);
|
|
|
|
|
|
2023-06-09 18:21:18 +10:00
|
|
|
return (
|
2024-02-28 14:43:09 +11:00
|
|
|
<Form {...form}>
|
|
|
|
|
<form
|
|
|
|
|
className={cn('flex w-full flex-col gap-y-4', className)}
|
|
|
|
|
onSubmit={form.handleSubmit(onFormSubmit)}
|
|
|
|
|
>
|
2024-03-26 21:11:59 +08:00
|
|
|
<fieldset
|
|
|
|
|
className="flex w-full flex-col gap-y-4"
|
|
|
|
|
disabled={isSubmitting || isPasskeyLoading}
|
|
|
|
|
>
|
2024-02-28 14:43:09 +11:00
|
|
|
<FormField
|
|
|
|
|
control={form.control}
|
|
|
|
|
name="email"
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<FormItem>
|
2024-08-27 20:34:39 +09:00
|
|
|
<FormLabel>
|
|
|
|
|
<Trans>Email</Trans>
|
|
|
|
|
</FormLabel>
|
2024-02-28 14:43:09 +11:00
|
|
|
|
|
|
|
|
<FormControl>
|
|
|
|
|
<Input type="email" {...field} />
|
|
|
|
|
</FormControl>
|
|
|
|
|
|
|
|
|
|
<FormMessage />
|
|
|
|
|
</FormItem>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<FormField
|
|
|
|
|
control={form.control}
|
|
|
|
|
name="password"
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<FormItem>
|
2024-08-27 20:34:39 +09:00
|
|
|
<FormLabel>
|
|
|
|
|
<Trans>Password</Trans>
|
|
|
|
|
</FormLabel>
|
2024-02-28 14:43:09 +11:00
|
|
|
|
|
|
|
|
<FormControl>
|
|
|
|
|
<PasswordInput {...field} />
|
|
|
|
|
</FormControl>
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
<FormMessage />
|
|
|
|
|
|
2024-02-28 14:43:09 +11:00
|
|
|
<p className="mt-2 text-right">
|
|
|
|
|
<Link
|
|
|
|
|
href="/forgot-password"
|
|
|
|
|
className="text-muted-foreground text-sm duration-200 hover:opacity-70"
|
|
|
|
|
>
|
2024-08-27 20:34:39 +09:00
|
|
|
<Trans>Forgot your password?</Trans>
|
2024-02-28 14:43:09 +11:00
|
|
|
</Link>
|
|
|
|
|
</p>
|
|
|
|
|
</FormItem>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
size="lg"
|
|
|
|
|
loading={isSubmitting}
|
|
|
|
|
className="dark:bg-documenso dark:hover:opacity-90"
|
|
|
|
|
>
|
2024-08-27 20:34:39 +09:00
|
|
|
{isSubmitting ? <Trans>Signing in...</Trans> : <Trans>Sign In</Trans>}
|
2024-03-26 21:11:59 +08:00
|
|
|
</Button>
|
2024-02-28 14:43:09 +11:00
|
|
|
|
2024-04-13 20:46:08 -04:00
|
|
|
{(isGoogleSSOEnabled || isPasskeyEnabled || isOIDCSSOEnabled) && (
|
2024-02-28 14:43:09 +11:00
|
|
|
<div className="relative flex items-center justify-center gap-x-4 py-2 text-xs uppercase">
|
|
|
|
|
<div className="bg-border h-px flex-1" />
|
2024-08-27 20:34:39 +09:00
|
|
|
<span className="text-muted-foreground bg-transparent">
|
|
|
|
|
<Trans>Or continue with</Trans>
|
|
|
|
|
</span>
|
2024-02-28 14:43:09 +11:00
|
|
|
<div className="bg-border h-px flex-1" />
|
|
|
|
|
</div>
|
2024-03-26 21:11:59 +08:00
|
|
|
)}
|
2024-02-28 14:43:09 +11:00
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
{isGoogleSSOEnabled && (
|
2024-02-28 14:43:09 +11:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
size="lg"
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="bg-background text-muted-foreground border"
|
|
|
|
|
disabled={isSubmitting}
|
|
|
|
|
onClick={onSignInWithGoogleClick}
|
|
|
|
|
>
|
|
|
|
|
<FcGoogle className="mr-2 h-5 w-5" />
|
|
|
|
|
Google
|
|
|
|
|
</Button>
|
2024-03-26 21:11:59 +08:00
|
|
|
)}
|
|
|
|
|
|
2024-04-13 20:46:08 -04:00
|
|
|
{isOIDCSSOEnabled && (
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
size="lg"
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="bg-background text-muted-foreground border"
|
|
|
|
|
disabled={isSubmitting}
|
|
|
|
|
onClick={onSignInWithOIDCClick}
|
|
|
|
|
>
|
|
|
|
|
<FaIdCardClip className="mr-2 h-5 w-5" />
|
2024-07-31 14:22:52 +02:00
|
|
|
{oidcProviderLabel || 'OIDC'}
|
2024-04-13 20:46:08 -04:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
{isPasskeyEnabled && (
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
size="lg"
|
|
|
|
|
variant="outline"
|
|
|
|
|
disabled={isSubmitting}
|
|
|
|
|
loading={isPasskeyLoading}
|
|
|
|
|
className="bg-background text-muted-foreground border"
|
|
|
|
|
onClick={onSignInWithPasskey}
|
|
|
|
|
>
|
|
|
|
|
{!isPasskeyLoading && <KeyRoundIcon className="-ml-1 mr-1 h-5 w-5" />}
|
2024-08-27 20:34:39 +09:00
|
|
|
<Trans>Passkey</Trans>
|
2024-03-26 21:11:59 +08:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</fieldset>
|
2024-02-28 14:43:09 +11:00
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<Dialog
|
|
|
|
|
open={isTwoFactorAuthenticationDialogOpen}
|
|
|
|
|
onOpenChange={onCloseTwoFactorAuthenticationDialog}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<DialogHeader>
|
2024-08-27 20:34:39 +09:00
|
|
|
<DialogTitle>
|
|
|
|
|
<Trans>Two-Factor Authentication</Trans>
|
|
|
|
|
</DialogTitle>
|
2024-02-28 14:43:09 +11:00
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
<form onSubmit={form.handleSubmit(onFormSubmit)}>
|
|
|
|
|
<fieldset disabled={isSubmitting}>
|
|
|
|
|
{twoFactorAuthenticationMethod === 'totp' && (
|
|
|
|
|
<FormField
|
|
|
|
|
control={form.control}
|
|
|
|
|
name="totpCode"
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<FormItem>
|
2024-05-24 03:31:19 +00:00
|
|
|
<FormLabel>Token</FormLabel>
|
2024-02-28 14:43:09 +11:00
|
|
|
<FormControl>
|
2024-05-24 03:31:19 +00:00
|
|
|
<PinInput {...field} value={field.value ?? ''} maxLength={6}>
|
|
|
|
|
{Array(6)
|
|
|
|
|
.fill(null)
|
|
|
|
|
.map((_, i) => (
|
|
|
|
|
<PinInputGroup key={i}>
|
|
|
|
|
<PinInputSlot index={i} />
|
|
|
|
|
</PinInputGroup>
|
|
|
|
|
))}
|
|
|
|
|
</PinInput>
|
2024-02-28 14:43:09 +11:00
|
|
|
</FormControl>
|
|
|
|
|
<FormMessage />
|
|
|
|
|
</FormItem>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2023-12-02 17:54:55 +05:30
|
|
|
)}
|
2024-02-28 14:43:09 +11:00
|
|
|
|
|
|
|
|
{twoFactorAuthenticationMethod === 'backup' && (
|
|
|
|
|
<FormField
|
|
|
|
|
control={form.control}
|
|
|
|
|
name="backupCode"
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<FormItem>
|
2024-08-27 20:34:39 +09:00
|
|
|
<FormLabel>
|
|
|
|
|
<Trans>Backup Code</Trans>
|
|
|
|
|
</FormLabel>
|
2024-02-28 14:43:09 +11:00
|
|
|
<FormControl>
|
|
|
|
|
<Input type="text" {...field} />
|
|
|
|
|
</FormControl>
|
|
|
|
|
<FormMessage />
|
|
|
|
|
</FormItem>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2023-12-02 17:54:55 +05:30
|
|
|
)}
|
2024-02-28 14:43:09 +11:00
|
|
|
|
|
|
|
|
<DialogFooter className="mt-4">
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="secondary"
|
|
|
|
|
onClick={onToggleTwoFactorAuthenticationMethodClick}
|
|
|
|
|
>
|
2024-08-27 20:34:39 +09:00
|
|
|
{twoFactorAuthenticationMethod === 'totp' ? (
|
|
|
|
|
<Trans>Use Backup Code</Trans>
|
|
|
|
|
) : (
|
|
|
|
|
<Trans>Use Authenticator</Trans>
|
|
|
|
|
)}
|
2024-02-28 14:43:09 +11:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<Button type="submit" loading={isSubmitting}>
|
2024-08-27 20:34:39 +09:00
|
|
|
{isSubmitting ? <Trans>Signing in...</Trans> : <Trans>Sign In</Trans>}
|
2024-02-28 14:43:09 +11:00
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</fieldset>
|
|
|
|
|
</form>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</Form>
|
2023-06-09 18:21:18 +10:00
|
|
|
);
|
|
|
|
|
};
|