@krak-stack/auth 0.1.51 → 0.1.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,37 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAtomSuspense } from "@effect/atom-react";
2
+ import { useAtomSet, useAtomSuspense, useAtomValue } from "@effect/atom-react";
3
+ import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
3
4
  import { Link, useNavigate, useRouterState } from "@tanstack/react-router";
4
- import { Schema } from "effect";
5
+ import { Effect, Option, Schema } from "effect";
5
6
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
6
7
  import { REGEXP_ONLY_DIGITS } from "input-otp";
7
- import { KeyRound, Mail } from "lucide-react";
8
+ import { KeyRound, Loader2, Mail } from "lucide-react";
8
9
  import { useEffect, useState } from "react";
9
10
  import { Button, buttonVariants } from "@/components/ui/button";
10
11
  import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card";
12
+ import { CheckboxField, ErrorMessage, SubmitError, TextField, effectFormMessages, } from "@/components/ui/effect-form";
11
13
  import { Field, FieldLabel } from "@/components/ui/field";
12
- import { FieldError, useAppForm } from "@/components/ui/form";
13
14
  import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from "@/components/ui/input-otp";
14
15
  import { authClientApi } from "./auth-client-api";
15
16
  import { useKrakstackAuth } from "./auth-provider";
16
17
  import { cn } from "./utils";
17
18
  import { ExtraProjectPublicConfig as ExtraProjectPublicConfigSchema, } from "../extra/schema";
18
19
  const EMAIL_OTP_RESEND_COOLDOWN_SECONDS = 60;
20
+ const signinFormBuilder = FormBuilder.empty
21
+ .addField("email", Schema.String)
22
+ .addField("password", Schema.String)
23
+ .addField("otp", Schema.String);
24
+ const signupFormBuilder = FormBuilder.empty
25
+ .addField("name", Schema.String)
26
+ .addField("email", Schema.String)
27
+ .addField("password", Schema.String);
28
+ const verifyEmailFormBuilder = FormBuilder.empty
29
+ .addField("email", Schema.String)
30
+ .addField("otp", Schema.String);
31
+ const resetPasswordFormBuilder = FormBuilder.empty.addField("password", Schema.String);
32
+ const twoFactorFormBuilder = FormBuilder.empty
33
+ .addField("code", Schema.String)
34
+ .addField("trustDevice", Schema.Boolean);
19
35
  const defaultMessages = {
20
36
  en: {
21
37
  auth_continue_with_google: "Continue with Google",
@@ -67,6 +83,13 @@ const defaultMessages = {
67
83
  two_factor_verify_description: "Enter the code from your authenticator app to continue.",
68
84
  two_factor_verify_email_description: "Enter the verification code sent to your email to continue.",
69
85
  two_factor_verify_error: "Could not verify the code.",
86
+ verify_email_code: "Verification code",
87
+ verify_email_description: "Enter the one-time code sent to your email address.",
88
+ verify_email_error: "Unable to verify email.",
89
+ verify_email_resend: "Resend code",
90
+ verify_email_resend_error: "Unable to send verification code.",
91
+ verify_email_resent: "A new verification code has been sent.",
92
+ verify_email_title: "Verify your email",
70
93
  },
71
94
  fr: {
72
95
  auth_continue_with_google: "Continuer avec Google",
@@ -118,6 +141,13 @@ const defaultMessages = {
118
141
  two_factor_verify_description: "Saisissez le code de votre application d'authentification pour continuer.",
119
142
  two_factor_verify_email_description: "Saisissez le code de vérification envoyé à votre courriel pour continuer.",
120
143
  two_factor_verify_error: "Impossible de vérifier le code.",
144
+ verify_email_code: "Code de vérification",
145
+ verify_email_description: "Saisissez le code à usage unique envoyé à votre adresse courriel.",
146
+ verify_email_error: "Impossible de vérifier le courriel.",
147
+ verify_email_resend: "Renvoyer le code",
148
+ verify_email_resend_error: "Impossible d'envoyer le code de vérification.",
149
+ verify_email_resent: "Un nouveau code de vérification a été envoyé.",
150
+ verify_email_title: "Vérifier votre courriel",
121
151
  },
122
152
  };
123
153
  const labels = (locale) => ({
@@ -212,23 +242,56 @@ export function Signin(props) {
212
242
  const interval = window.setInterval(updateResendSeconds, 1000);
213
243
  return () => window.clearInterval(interval);
214
244
  }, [emailOtpResendAvailableAt]);
215
- const form = useAppForm({
216
- defaultValues: { email: "", password: "", otp: "" },
217
- onSubmit: async ({ value, formApi }) => {
218
- formApi.setErrorMap({ onSubmit: undefined });
219
- const email = value.email.trim();
220
- if (!emailSubmitted) {
221
- if (selectedAuthMethod === "emailOtp") {
222
- await sendEmailOtp(email, (message) => formApi.setErrorMap({ onSubmit: { form: message, fields: {} } }));
245
+ const [form] = useState(() => FormReact.make(signinFormBuilder, {
246
+ fields: { email: TextField, password: TextField, otp: OtpField },
247
+ mode: { validation: "onSubmit" },
248
+ onSubmit: (action, { decoded: value }) => Effect.tryPromise({
249
+ try: async () => {
250
+ const email = value.email.trim();
251
+ const sendEmailOtp = async () => {
252
+ const result = await authClient.emailOtp.sendVerificationOtp({
253
+ email,
254
+ type: "sign-in",
255
+ });
256
+ if (result.error) {
257
+ throw new Error(result.error.message ?? m.sign_in_email_otp_send_error);
258
+ }
259
+ setAuthMethod("emailOtp");
260
+ setEmailSubmitted(true);
261
+ setOtpSentTo(email);
262
+ setEmailOtpResendAvailableAt(Date.now() + EMAIL_OTP_RESEND_COOLDOWN_SECONDS * 1000);
263
+ };
264
+ if (action.type === "social") {
265
+ const result = await authClient.signIn.social({
266
+ provider: "google",
267
+ callbackURL: socialRedirectTarget,
268
+ errorCallbackURL: "/sign-in",
269
+ ...(oauthQuery
270
+ ? { additionalData: { query: oauthQuery } }
271
+ : {}),
272
+ ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
273
+ });
274
+ if (result.error) {
275
+ throw new Error(result.error.message ?? m.sign_in_error);
276
+ }
277
+ if (result.data?.url)
278
+ onNavigate(result.data.url);
279
+ return;
280
+ }
281
+ if (action.type === "sendEmailOtp") {
282
+ await sendEmailOtp();
283
+ return;
284
+ }
285
+ if (!action.emailSubmitted) {
286
+ if (action.method === "emailOtp")
287
+ await sendEmailOtp();
288
+ else
289
+ setEmailSubmitted(true);
223
290
  return;
224
291
  }
225
- setEmailSubmitted(true);
226
- return;
227
- }
228
- try {
229
- if (selectedAuthMethod === "emailOtp") {
230
- if (!otpSentTo) {
231
- await sendEmailOtp(email, (message) => formApi.setErrorMap({ onSubmit: { form: message, fields: {} } }));
292
+ if (action.method === "emailOtp") {
293
+ if (!action.otpSent) {
294
+ await sendEmailOtp();
232
295
  return;
233
296
  }
234
297
  const result = await authClient.signIn.emailOtp({
@@ -236,13 +299,7 @@ export function Signin(props) {
236
299
  otp: value.otp.trim(),
237
300
  });
238
301
  if (result.error) {
239
- formApi.setErrorMap({
240
- onSubmit: {
241
- form: result.error.message ?? m.sign_in_email_otp_error,
242
- fields: {},
243
- },
244
- });
245
- return;
302
+ throw new Error(result.error.message ?? m.sign_in_email_otp_error);
246
303
  }
247
304
  onNavigate(redirectTarget);
248
305
  return;
@@ -254,119 +311,81 @@ export function Signin(props) {
254
311
  ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
255
312
  });
256
313
  if (result.error) {
257
- formApi.setErrorMap({
258
- onSubmit: {
259
- form: result.error.message ?? m.sign_in_error,
260
- fields: {},
261
- },
262
- });
263
- return;
314
+ throw new Error(result.error.message ?? m.sign_in_error);
264
315
  }
265
316
  if (hasTwoFactorRedirect(result.data)) {
266
317
  onTwoFactorRedirect(`/2fa${oauthQuery ? `?${oauthQuery}` : `?callbackURL=${encodeURIComponent(redirectTarget)}`}`);
267
318
  return;
268
319
  }
269
320
  onNavigate(result.data?.url ?? redirectTarget);
270
- }
271
- catch {
272
- formApi.setErrorMap({
273
- onSubmit: {
274
- form: selectedAuthMethod === "emailOtp"
275
- ? m.sign_in_email_otp_error
276
- : m.sign_in_error,
277
- fields: {},
278
- },
279
- });
280
- }
281
- },
282
- });
283
- const sendEmailOtp = async (email, setError) => {
284
- try {
285
- const result = await authClient.emailOtp.sendVerificationOtp({
286
- email,
287
- type: "sign-in",
288
- });
289
- if (result.error) {
290
- setError(result.error.message ?? m.sign_in_email_otp_send_error);
291
- return;
292
- }
293
- setAuthMethod("emailOtp");
294
- setEmailSubmitted(true);
295
- setOtpSentTo(email);
296
- setEmailOtpResendAvailableAt(Date.now() + EMAIL_OTP_RESEND_COOLDOWN_SECONDS * 1000);
297
- }
298
- catch {
299
- setError(m.sign_in_email_otp_send_error);
300
- }
301
- };
321
+ },
322
+ catch: (cause) => cause instanceof Error
323
+ ? cause
324
+ : new Error(action.type === "sendEmailOtp" ||
325
+ (action.type === "submit" &&
326
+ action.method === "emailOtp" &&
327
+ (!action.emailSubmitted || !action.otpSent))
328
+ ? m.sign_in_email_otp_send_error
329
+ : action.type === "submit" && action.method === "emailOtp"
330
+ ? m.sign_in_email_otp_error
331
+ : m.sign_in_error),
332
+ }),
333
+ }));
334
+ const submit = useAtomSet(form.submit);
335
+ const submitResult = useAtomValue(form.submit);
336
+ const formValues = Option.getOrElse(useAtomValue(form.values), () => ({
337
+ email: "",
338
+ password: "",
339
+ otp: "",
340
+ }));
341
+ const resetForm = useAtomSet(form.reset);
342
+ const setEmail = useAtomSet(form.getFieldAtoms(form.fields.email).setValue);
343
+ const setPassword = useAtomSet(form.getFieldAtoms(form.fields.password).setValue);
344
+ const setOtp = useAtomSet(form.getFieldAtoms(form.fields.otp).setValue);
302
345
  const resetEmailStep = () => {
346
+ const email = formValues.email;
347
+ resetForm();
348
+ setEmail(email);
303
349
  setEmailSubmitted(false);
304
350
  setOtpSentTo("");
305
351
  setEmailOtpResendAvailableAt(0);
306
- form.setFieldValue("password", "");
307
- form.setFieldValue("otp", "");
308
- form.setErrorMap({ onSubmit: undefined });
309
352
  };
310
- const switchAuthMethod = async () => {
311
- form.setErrorMap({ onSubmit: undefined });
312
- form.setFieldValue("password", "");
313
- form.setFieldValue("otp", "");
353
+ const switchAuthMethod = () => {
354
+ setPassword("");
355
+ setOtp("");
314
356
  if (selectedAuthMethod === "emailOtp") {
357
+ resetForm();
358
+ setEmail(formValues.email);
315
359
  setAuthMethod("password");
316
360
  setOtpSentTo("");
317
361
  setEmailOtpResendAvailableAt(0);
318
362
  return;
319
363
  }
320
- await sendEmailOtp(form.state.values.email.trim(), (message) => form.setErrorMap({ onSubmit: { form: message, fields: {} } }));
321
- };
322
- const resendEmailOtp = async () => {
323
- form.setErrorMap({ onSubmit: undefined });
324
- form.setFieldValue("otp", "");
325
- await sendEmailOtp(form.state.values.email.trim(), (message) => form.setErrorMap({ onSubmit: { form: message, fields: {} } }));
364
+ submit({ type: "sendEmailOtp" });
326
365
  };
327
- const signInWithGoogle = async () => {
328
- try {
329
- const result = await authClient.signIn.social({
330
- provider: "google",
331
- callbackURL: socialRedirectTarget,
332
- errorCallbackURL: "/sign-in",
333
- ...(oauthQuery ? { additionalData: { query: oauthQuery } } : {}),
334
- ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
335
- });
336
- if (result.error) {
337
- form.setErrorMap({
338
- onSubmit: {
339
- form: result.error.message ?? m.sign_in_error,
340
- fields: {},
341
- },
342
- });
343
- return;
344
- }
345
- if (result.data?.url)
346
- onNavigate(result.data.url);
347
- }
348
- catch {
349
- form.setErrorMap({ onSubmit: { form: m.sign_in_error, fields: {} } });
350
- }
366
+ const resendEmailOtp = () => {
367
+ setOtp("");
368
+ submit({ type: "sendEmailOtp" });
351
369
  };
352
- return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.auth_sign_in }), _jsx(CardDescription, { children: !emailSubmitted ? (m.sign_in_description) : (_jsxs(_Fragment, { children: [text(m.sign_in_email_as, { email: form.state.values.email }), " ", _jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: resetEmailStep, children: m.sign_in_change_email })] })) })] }), _jsxs(CardContent, { children: [hasPrimaryAuth ? (_jsx(form.AppForm, { children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
370
+ const signInWithGoogle = () => submit({ type: "social" });
371
+ return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.auth_sign_in }), _jsx(CardDescription, { children: !emailSubmitted ? (m.sign_in_description) : (_jsxs(_Fragment, { children: [text(m.sign_in_email_as, { email: formValues.email }), " ", _jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: resetEmailStep, children: m.sign_in_change_email })] })) })] }), _jsxs(CardContent, { children: [hasPrimaryAuth ? (_jsx(form.Initialize, { defaultValues: { email: "", password: "", otp: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
353
372
  event.preventDefault();
354
373
  event.stopPropagation();
355
- form.handleSubmit();
356
- }, children: [!emailSubmitted ? (_jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", onKeyDown: (event) => {
357
- if (event.key !== "Enter")
358
- return;
359
- event.preventDefault();
360
- form.handleSubmit();
361
- }, required: true })) })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.field_password, type: "password", autoComplete: "current-password", required: true })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/forgot-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "otp", children: (field) => (_jsx(OtpInput, { field: field, label: m.sign_in_email_otp_code })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
374
+ submit({
375
+ type: "submit",
376
+ emailSubmitted,
377
+ method: selectedAuthMethod,
378
+ otpSent: Boolean(otpSentTo),
379
+ });
380
+ }, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.password, { label: m.field_password, type: "password", autoComplete: "current-password", required: true }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/forgot-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.otp, { label: m.sign_in_email_otp_code }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
362
381
  ? text(m.sign_in_email_otp_resend_countdown, {
363
382
  seconds: String(emailOtpResendSeconds),
364
383
  })
365
- : m.sign_in_email_otp_resend })) : null, canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(KeyRound, {}), m.sign_in_use_password] })) : null] })] })) : null, _jsx(form.FormError, {}), _jsx("div", { children: _jsx(form.SubmitButton, { children: !emailSubmitted
366
- ? m.sign_in_continue
367
- : selectedAuthMethod === "emailOtp"
368
- ? m.sign_in_email_otp_verify
369
- : m.auth_sign_in }) })] }) })) : null, options.google && !emailSubmitted ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [hasPrimaryAuth ? (_jsx(Divider, { label: m.auth_or_continue_with })) : null, _jsxs(Button, { type: "button", variant: "outline", className: "w-full", onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null, options.signUp ? (_jsxs("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: [m.sign_in_need_account, " ", _jsx(Link, { className: authLinkClassName, to: "/sign-up", search: searchObject(searchString), children: m.auth_sign_up })] })) : null] })] }));
384
+ : m.sign_in_email_otp_resend })) : null, canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(KeyRound, {}), m.sign_in_use_password] })) : null] })] })) : null, _jsx(SubmitError, { result: submitResult }), _jsx("div", { children: _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, !emailSubmitted
385
+ ? m.sign_in_continue
386
+ : selectedAuthMethod === "emailOtp"
387
+ ? m.sign_in_email_otp_verify
388
+ : m.auth_sign_in] }) })] }) })) : null, options.google && !emailSubmitted ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [hasPrimaryAuth ? (_jsx(Divider, { label: m.auth_or_continue_with })) : null, _jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null, options.signUp ? (_jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-up", search: searchObject(searchString), children: [m.sign_in_need_account, " ", m.auth_sign_up] }) })) : null] })] }));
370
389
  }
371
390
  export function Signup(props) {
372
391
  const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
@@ -378,23 +397,36 @@ export function Signup(props) {
378
397
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
379
398
  const authOptions = projectConfig?.authOptions;
380
399
  const onNavigate = (target) => navigate({ href: target });
381
- const onVerifyEmail = (email) => navigate({ to: "/verify-email", search: { email } });
400
+ const onVerifyEmail = (email) => navigate({
401
+ to: "/verify-email",
402
+ search: { ...searchObject(searchString), email },
403
+ });
382
404
  const options = {
383
405
  google: authOptions?.google ?? true,
384
406
  signUp: authOptions?.signUp ?? true,
385
407
  signUpName: authOptions?.signUpName ?? true,
386
408
  };
387
- const form = useAppForm({
388
- defaultValues: { name: "", email: "", password: "" },
389
- onSubmit: async ({ value, formApi }) => {
390
- formApi.setErrorMap({ onSubmit: undefined });
391
- if (!options.signUp) {
392
- formApi.setErrorMap({
393
- onSubmit: { form: m.sign_up_disabled_description, fields: {} },
394
- });
395
- return;
396
- }
397
- try {
409
+ const [form] = useState(() => FormReact.make(signupFormBuilder, {
410
+ fields: { name: TextField, email: TextField, password: TextField },
411
+ mode: { validation: "onSubmit" },
412
+ onSubmit: (action, { decoded: value }) => Effect.tryPromise({
413
+ try: async () => {
414
+ if (action === "social") {
415
+ const result = await authClient.signIn.social({
416
+ provider: "google",
417
+ callbackURL: redirectTarget,
418
+ errorCallbackURL: "/sign-up",
419
+ });
420
+ if (result.error) {
421
+ throw new Error(result.error.message ?? m.sign_up_error);
422
+ }
423
+ if (result.data?.url)
424
+ onNavigate(result.data.url);
425
+ return;
426
+ }
427
+ if (!options.signUp) {
428
+ throw new Error(m.sign_up_disabled_description);
429
+ }
398
430
  const result = await authClient.signUp.email({
399
431
  name: options.signUpName
400
432
  ? value.name.trim()
@@ -403,54 +435,78 @@ export function Signup(props) {
403
435
  password: value.password,
404
436
  });
405
437
  if (result.error) {
406
- formApi.setErrorMap({
407
- onSubmit: {
408
- form: result.error.message ?? m.sign_up_error,
409
- fields: {},
410
- },
411
- });
412
- return;
438
+ throw new Error(result.error.message ?? m.sign_up_error);
413
439
  }
414
440
  onVerifyEmail(value.email.trim());
415
- }
416
- catch {
417
- formApi.setErrorMap({
418
- onSubmit: { form: m.sign_up_error, fields: {} },
419
- });
420
- }
421
- },
422
- });
423
- const signUpWithGoogle = async () => {
424
- try {
425
- const result = await authClient.signIn.social({
426
- provider: "google",
427
- callbackURL: redirectTarget,
428
- errorCallbackURL: "/sign-up",
429
- });
430
- if (result.error) {
431
- form.setErrorMap({
432
- onSubmit: {
433
- form: result.error.message ?? m.sign_up_error,
434
- fields: {},
435
- },
436
- });
437
- return;
438
- }
439
- if (result.data?.url)
440
- onNavigate(result.data.url);
441
- }
442
- catch {
443
- form.setErrorMap({ onSubmit: { form: m.sign_up_error, fields: {} } });
444
- }
445
- };
441
+ },
442
+ catch: (cause) => cause instanceof Error ? cause : new Error(m.sign_up_error),
443
+ }),
444
+ }));
445
+ const submit = useAtomSet(form.submit);
446
+ const submitResult = useAtomValue(form.submit);
447
+ const signUpWithGoogle = () => submit("social");
446
448
  if (!options.signUp) {
447
- return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_disabled_title }), _jsx(CardDescription, { children: m.sign_up_disabled_description })] }), _jsx(CardContent, { children: _jsxs("p", { className: "text-muted-foreground text-center text-sm", children: [m.sign_up_have_account, " ", _jsx(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: m.auth_sign_in })] }) })] }));
449
+ return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_disabled_title }), _jsx(CardDescription, { children: m.sign_up_disabled_description })] }), _jsx(CardContent, { children: _jsx("p", { className: "text-muted-foreground text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: [m.sign_up_have_account, " ", m.auth_sign_in] }) }) })] }));
448
450
  }
449
- return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_title }), _jsx(CardDescription, { children: m.sign_up_description })] }), _jsxs(CardContent, { children: [_jsx(form.AppForm, { children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
451
+ return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_title }), _jsx(CardDescription, { children: m.sign_up_description })] }), _jsxs(CardContent, { children: [_jsx(form.Initialize, { defaultValues: { name: "", email: "", password: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
450
452
  event.preventDefault();
451
453
  event.stopPropagation();
452
- form.handleSubmit();
453
- }, children: [options.signUpName ? (_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.field_name, autoComplete: "name", required: true })) })) : null, _jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", required: true })) }), _jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.field_password, type: "password", autoComplete: "new-password", minLength: 8, required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }), options.google ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [_jsx(Divider, { label: m.auth_or_continue_with }), _jsxs(Button, { type: "button", variant: "outline", className: "w-full", onClick: signUpWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, _jsxs("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: [m.sign_up_have_account, " ", _jsx(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: m.auth_sign_in })] })] })] }));
454
+ submit("email");
455
+ }, children: [options.signUpName ? (_jsx(form.name, { label: m.field_name, autoComplete: "name", required: true })) : null, _jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(form.password, { label: m.field_password, type: "password", autoComplete: "new-password", minLength: 8, required: true }), _jsx(SubmitError, { result: submitResult }), _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] })] }) }), options.google ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [_jsx(Divider, { label: m.auth_or_continue_with }), _jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: signUpWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: [m.sign_up_have_account, " ", m.auth_sign_in] }) })] })] }));
456
+ }
457
+ export function VerifyEmail(props) {
458
+ const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
459
+ const navigate = useNavigate();
460
+ const searchString = useRouterState({
461
+ select: (state) => state.location.searchStr,
462
+ });
463
+ const projectConfig = useAuthProjectConfig(baseUrl, searchString, providedProjectConfig);
464
+ const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
465
+ const onNavigate = (target) => navigateTarget(target, navigate);
466
+ const [resent, setResent] = useState(false);
467
+ const [form] = useState(() => FormReact.make(verifyEmailFormBuilder, {
468
+ fields: { email: TextField, otp: OtpField },
469
+ mode: { validation: "onSubmit" },
470
+ onSubmit: (action, { decoded: value }) => Effect.tryPromise({
471
+ try: async () => {
472
+ if (action === "resend") {
473
+ const result = await authClient.emailOtp.sendVerificationOtp({
474
+ email: value.email.trim(),
475
+ type: "email-verification",
476
+ });
477
+ if (result.error) {
478
+ throw new Error(result.error.message ?? m.verify_email_resend_error);
479
+ }
480
+ setResent(true);
481
+ return;
482
+ }
483
+ const result = await authClient.emailOtp.verifyEmail({
484
+ email: value.email.trim(),
485
+ otp: value.otp.trim(),
486
+ });
487
+ if (result.error) {
488
+ throw new Error(result.error.message ?? m.verify_email_error);
489
+ }
490
+ onNavigate(redirectTarget);
491
+ },
492
+ catch: (cause) => cause instanceof Error
493
+ ? cause
494
+ : new Error(action === "resend"
495
+ ? m.verify_email_resend_error
496
+ : m.verify_email_error),
497
+ }),
498
+ }));
499
+ const submit = useAtomSet(form.submit);
500
+ const submitResult = useAtomValue(form.submit);
501
+ const resendCode = () => submit("resend");
502
+ return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.verify_email_title }), _jsx(CardDescription, { children: m.verify_email_description })] }), _jsxs(CardContent, { children: [_jsx(form.Initialize, { defaultValues: {
503
+ email: getSearchParam(searchString, "email") ?? "",
504
+ otp: "",
505
+ }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
506
+ event.preventDefault();
507
+ event.stopPropagation();
508
+ submit("verify");
509
+ }, children: [_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(form.otp, { label: m.verify_email_code }), _jsx(SubmitError, { result: submitResult }), resent ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.verify_email_resent })) : null, _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] }), _jsx(Button, { type: "button", variant: "ghost", disabled: submitResult.waiting, onClick: resendCode, children: m.verify_email_resend })] })] }) }), _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsx(Link, { className: authLinkClassName, to: "/sign-in", children: m.forgot_password_back_to_sign_in }) })] })] }));
454
510
  }
455
511
  export function ResetPassword(props) {
456
512
  const { authClient, labels: m } = useAuthFormOptions(props);
@@ -460,37 +516,32 @@ export function ResetPassword(props) {
460
516
  });
461
517
  const token = getSearchParam(searchString, "token") ?? "";
462
518
  const onSuccess = () => navigate({ to: "/sign-in" });
463
- const form = useAppForm({
464
- defaultValues: { password: "" },
465
- onSubmit: async ({ value, formApi }) => {
466
- formApi.setErrorMap({ onSubmit: undefined });
467
- if (!token) {
468
- formApi.setErrorMap({
469
- onSubmit: { form: m.reset_password_missing_token, fields: {} },
519
+ const [form] = useState(() => FormReact.make(resetPasswordFormBuilder, {
520
+ fields: { password: TextField },
521
+ mode: { validation: "onSubmit" },
522
+ onSubmit: (_, { decoded: value }) => Effect.tryPromise({
523
+ try: async () => {
524
+ if (!token)
525
+ throw new Error(m.reset_password_missing_token);
526
+ const result = await authClient.resetPassword({
527
+ newPassword: value.password,
528
+ token,
470
529
  });
471
- return;
472
- }
473
- const result = await authClient.resetPassword({
474
- newPassword: value.password,
475
- token,
476
- });
477
- if (result.error) {
478
- formApi.setErrorMap({
479
- onSubmit: {
480
- form: result.error.message ?? m.reset_password_error,
481
- fields: {},
482
- },
483
- });
484
- return;
485
- }
486
- onSuccess();
487
- },
488
- });
489
- return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.reset_password_title }), _jsx(CardDescription, { children: m.reset_password_description })] }), _jsx(CardContent, { children: _jsx(form.AppForm, { children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
530
+ if (result.error) {
531
+ throw new Error(result.error.message ?? m.reset_password_error);
532
+ }
533
+ onSuccess();
534
+ },
535
+ catch: (cause) => cause instanceof Error ? cause : new Error(m.reset_password_error),
536
+ }),
537
+ }));
538
+ const submit = useAtomSet(form.submit);
539
+ const submitResult = useAtomValue(form.submit);
540
+ return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.reset_password_title }), _jsx(CardDescription, { children: m.reset_password_description })] }), _jsx(CardContent, { children: _jsx(form.Initialize, { defaultValues: { password: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
490
541
  event.preventDefault();
491
542
  event.stopPropagation();
492
- form.handleSubmit();
493
- }, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.reset_password_new_password, type: "password", autoComplete: "new-password", minLength: 8, required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) })] }));
543
+ submit();
544
+ }, children: [_jsx(form.password, { label: m.reset_password_new_password, type: "password", autoComplete: "new-password", minLength: 8, required: true }), _jsx(SubmitError, { result: submitResult }), _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] })] }) }) })] }));
494
545
  }
495
546
  export function TwoFactor(props) {
496
547
  const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
@@ -504,72 +555,79 @@ export function TwoFactor(props) {
504
555
  const onNavigate = (target) => navigateTarget(target, navigate);
505
556
  const [mode, setMode] = useState("totp");
506
557
  const [emailCodeSent, setEmailCodeSent] = useState(false);
507
- const form = useAppForm({
508
- defaultValues: { code: "", trustDevice: true },
509
- onSubmit: async ({ value, formApi }) => {
510
- formApi.setErrorMap({ onSubmit: undefined });
511
- const code = value.code.trim();
512
- const result = mode === "backup"
513
- ? await authClient.twoFactor.verifyBackupCode({
514
- code,
515
- trustDevice: value.trustDevice,
516
- ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
517
- })
518
- : mode === "email"
519
- ? await authClient.twoFactor.verifyOtp({
558
+ const [form] = useState(() => FormReact.make(twoFactorFormBuilder, {
559
+ fields: { code: AuthCodeField, trustDevice: CheckboxField },
560
+ mode: { validation: "onSubmit" },
561
+ onSubmit: (action, { decoded: value }) => Effect.tryPromise({
562
+ try: async () => {
563
+ if (action.type === "sendEmailCode") {
564
+ const result = await authClient.twoFactor.sendOtp();
565
+ if (result.error) {
566
+ throw new Error(result.error.message ?? m.two_factor_send_email_code_error);
567
+ }
568
+ setEmailCodeSent(true);
569
+ setMode("email");
570
+ return;
571
+ }
572
+ const code = value.code.trim();
573
+ const result = action.mode === "backup"
574
+ ? await authClient.twoFactor.verifyBackupCode({
520
575
  code,
521
576
  trustDevice: value.trustDevice,
522
577
  ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
523
578
  })
524
- : await authClient.twoFactor.verifyTotp({
525
- code,
526
- trustDevice: value.trustDevice,
527
- ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
528
- });
529
- if (result.error) {
530
- formApi.setErrorMap({
531
- onSubmit: {
532
- form: result.error.message ?? m.two_factor_verify_error,
533
- fields: {},
534
- },
535
- });
536
- return;
537
- }
538
- onNavigate(getResultRedirectUrl(result.data) ?? redirectTarget);
539
- },
540
- });
541
- const sendEmailCode = async () => {
542
- form.setErrorMap({ onSubmit: undefined });
543
- const result = await authClient.twoFactor.sendOtp();
544
- if (result.error) {
545
- form.setErrorMap({
546
- onSubmit: {
547
- form: result.error.message ?? m.two_factor_send_email_code_error,
548
- fields: {},
549
- },
550
- });
551
- return;
552
- }
553
- setEmailCodeSent(true);
554
- setMode("email");
555
- };
579
+ : action.mode === "email"
580
+ ? await authClient.twoFactor.verifyOtp({
581
+ code,
582
+ trustDevice: value.trustDevice,
583
+ ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
584
+ })
585
+ : await authClient.twoFactor.verifyTotp({
586
+ code,
587
+ trustDevice: value.trustDevice,
588
+ ...(oauthQuery ? { oauth_query: oauthQuery } : {}),
589
+ });
590
+ if (result.error) {
591
+ throw new Error(result.error.message ?? m.two_factor_verify_error);
592
+ }
593
+ onNavigate(getResultRedirectUrl(result.data) ?? redirectTarget);
594
+ },
595
+ catch: (cause) => cause instanceof Error
596
+ ? cause
597
+ : new Error(action.type === "sendEmailCode"
598
+ ? m.two_factor_send_email_code_error
599
+ : m.two_factor_verify_error),
600
+ }),
601
+ }));
602
+ const submit = useAtomSet(form.submit);
603
+ const submitResult = useAtomValue(form.submit);
604
+ const sendEmailCode = () => submit({ type: "sendEmailCode" });
556
605
  return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.two_factor_title }), _jsx(CardDescription, { children: mode === "backup"
557
606
  ? m.two_factor_verify_backup_description
558
607
  : mode === "email"
559
608
  ? m.two_factor_verify_email_description
560
- : m.two_factor_verify_description })] }), _jsx(CardContent, { children: _jsx(form.AppForm, { children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
609
+ : m.two_factor_verify_description })] }), _jsx(CardContent, { children: _jsx(form.Initialize, { defaultValues: { code: "", trustDevice: true }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
561
610
  event.preventDefault();
562
611
  event.stopPropagation();
563
- form.handleSubmit();
564
- }, children: [_jsx(form.AppField, { name: "code", children: (field) => mode === "backup" ? (_jsx(field.TextField, { label: m.two_factor_backup_code, autoComplete: "one-time-code", required: true })) : (_jsx(OtpInput, { field: field, label: mode === "email"
612
+ submit({ type: "verify", mode });
613
+ }, children: [_jsx(form.code, { autoComplete: "one-time-code", label: mode === "backup"
614
+ ? m.two_factor_backup_code
615
+ : mode === "email"
565
616
  ? m.two_factor_email_code
566
- : m.two_factor_code })) }), _jsx(form.AppField, { name: "trustDevice", children: (field) => (_jsx(field.CheckboxField, { label: m.two_factor_trust_device })) }), _jsx(form.FormError, {}), emailCodeSent && mode === "email" ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.two_factor_email_code_sent })) : null, _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsx(form.SubmitButton, {}), _jsx(Button, { type: "button", variant: "ghost", onClick: sendEmailCode, children: m.two_factor_send_email_code }), _jsx(Button, { type: "button", variant: "ghost", onClick: () => setMode(mode === "backup" ? "totp" : "backup"), children: mode === "backup"
617
+ : m.two_factor_code, otp: mode !== "backup", required: true }), _jsx(form.trustDevice, { label: m.two_factor_trust_device }), _jsx(SubmitError, { result: submitResult }), emailCodeSent && mode === "email" ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.two_factor_email_code_sent })) : null, _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] }), _jsx(Button, { type: "button", variant: "ghost", disabled: submitResult.waiting, onClick: sendEmailCode, children: m.two_factor_send_email_code }), _jsx(Button, { type: "button", variant: "ghost", onClick: () => setMode(mode === "backup" ? "totp" : "backup"), children: mode === "backup"
567
618
  ? m.two_factor_use_totp
568
619
  : m.two_factor_use_backup_code })] })] }) }) })] }));
569
620
  }
570
- const OtpInput = ({ field, label }) => {
571
- const invalid = !field.state.meta.isValid;
572
- return (_jsxs(Field, { "data-invalid": invalid, children: [_jsx(FieldLabel, { htmlFor: field.name, children: label }), _jsxs(InputOTP, { id: field.name, name: field.name, maxLength: 6, value: field.state.value ?? "", onChange: (value) => field.handleChange(value), onBlur: field.handleBlur, autoComplete: "one-time-code", inputMode: "numeric", pattern: REGEXP_ONLY_DIGITS, required: true, children: [_jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 0, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 1, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 2, "aria-invalid": invalid })] }), _jsx(InputOTPSeparator, {}), _jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 3, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 4, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 5, "aria-invalid": invalid })] })] }), _jsx(FieldError, { errors: field.getMeta().errors ?? [] })] }));
621
+ const OtpField = ({ field, props, }) => {
622
+ const invalid = Option.isSome(field.error);
623
+ return (_jsxs(Field, { "data-invalid": invalid, children: [_jsx(FieldLabel, { htmlFor: field.path, children: props.label }), _jsxs(InputOTP, { id: field.path, name: field.path, maxLength: 6, value: field.value, onChange: field.onChange, onBlur: field.onBlur, autoComplete: "one-time-code", inputMode: "numeric", pattern: REGEXP_ONLY_DIGITS, required: true, children: [_jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 0, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 1, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 2, "aria-invalid": invalid })] }), _jsx(InputOTPSeparator, {}), _jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 3, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 4, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 5, "aria-invalid": invalid })] })] }), Option.isSome(field.error) ? (_jsx(ErrorMessage, { text: field.error.value })) : null] }));
624
+ };
625
+ const AuthCodeField = ({ field, props }) => {
626
+ if (props.otp) {
627
+ return _jsx(OtpField, { field: field, props: { label: props.label } });
628
+ }
629
+ const { otp: _, ...textFieldProps } = props;
630
+ return _jsx(TextField, { field: field, props: textFieldProps });
573
631
  };
574
632
  const Divider = ({ label }) => (_jsxs("div", { className: "text-muted-foreground flex items-center gap-3 text-xs", children: [_jsx("span", { className: "bg-border h-px flex-1" }), label, _jsx("span", { className: "bg-border h-px flex-1" })] }));
575
633
  const GoogleLogo = () => (_jsxs("svg", { "aria-hidden": "true", className: "size-[18px]", viewBox: "0 0 18 18", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("path", { d: "M17.64 9.204c0-.638-.057-1.252-.164-1.84H9v3.481h4.844a4.14 4.14 0 0 1-1.796 2.716v2.259h2.908c1.702-1.567 2.684-3.874 2.684-6.616Z", fill: "#4285F4" }), _jsx("path", { d: "M9 18c2.43 0 4.467-.806 5.956-2.18l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.583-5.036-3.711H.957v2.332A8.997 8.997 0 0 0 9 18Z", fill: "#34A853" }), _jsx("path", { d: "M3.964 10.71A5.41 5.41 0 0 1 3.682 9c0-.593.102-1.17.282-1.71V4.958H.957A8.996 8.996 0 0 0 0 9c0 1.452.348 2.827.957 4.042l3.007-2.332Z", fill: "#FBBC05" }), _jsx("path", { d: "M9 3.58c1.321 0 2.508.454 3.44 1.346l2.582-2.58C13.463.891 11.426 0 9 0A8.997 8.997 0 0 0 .957 4.958L3.964 7.29C4.672 5.162 6.656 3.58 9 3.58Z", fill: "#EA4335" })] }));
@@ -662,9 +720,8 @@ const shouldUseDocumentRedirect = (target) => {
662
720
  return true;
663
721
  if (target.startsWith("/"))
664
722
  return false;
665
- if (target.startsWith(window.location.origin)) {
666
- return target.slice(window.location.origin.length).startsWith("/api/");
667
- }
723
+ if (target.startsWith(window.location.origin))
724
+ return true;
668
725
  return target.startsWith("http://") || target.startsWith("https://");
669
726
  };
670
727
  const nameFromEmail = (email) => {