@krak-stack/auth 0.1.64 → 0.1.66

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.
package/dist/api.d.ts CHANGED
@@ -134,8 +134,6 @@ export declare const AuthServiceApi: HttpApi.HttpApi<"AuthServiceApi", import("e
134
134
  readonly emailPassword: import("effect/Schema").Boolean;
135
135
  readonly emailOtp: import("effect/Schema").Boolean;
136
136
  readonly google: import("effect/Schema").Boolean;
137
- readonly signUp: import("effect/Schema").Boolean;
138
- readonly signUpName: import("effect/Schema").Boolean;
139
137
  }>;
140
138
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
141
139
  readonly newPassword: import("effect/Schema").NonEmptyString;
@@ -1039,8 +1037,6 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
1039
1037
  readonly emailPassword: import("effect/Schema").Boolean;
1040
1038
  readonly emailOtp: import("effect/Schema").Boolean;
1041
1039
  readonly google: import("effect/Schema").Boolean;
1042
- readonly signUp: import("effect/Schema").Boolean;
1043
- readonly signUpName: import("effect/Schema").Boolean;
1044
1040
  }>;
1045
1041
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
1046
1042
  readonly newPassword: import("effect/Schema").NonEmptyString;
@@ -517,8 +517,6 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
517
517
  readonly emailPassword: import("effect/Schema").Boolean;
518
518
  readonly emailOtp: import("effect/Schema").Boolean;
519
519
  readonly google: import("effect/Schema").Boolean;
520
- readonly signUp: import("effect/Schema").Boolean;
521
- readonly signUpName: import("effect/Schema").Boolean;
522
520
  }>;
523
521
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
524
522
  readonly newPassword: import("effect/Schema").NonEmptyString;
@@ -6,7 +6,6 @@ type AuthFormProps = {
6
6
  locale?: KrakstackAuthLocale | undefined;
7
7
  };
8
8
  export declare function Signin(props: AuthFormProps): import("react").JSX.Element;
9
- export declare function Signup(props: AuthFormProps): import("react").JSX.Element;
10
9
  export declare function VerifyEmail(props: AuthFormProps): import("react").JSX.Element;
11
10
  export declare function ForgotPassword(props: AuthFormProps): import("react").JSX.Element;
12
11
  export declare function ResetPassword(props: AuthFormProps): import("react").JSX.Element;
@@ -21,10 +21,6 @@ const signinFormBuilder = FormBuilder.empty
21
21
  .addField("email", Schema.String)
22
22
  .addField("password", Schema.String)
23
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
24
  const verifyEmailFormBuilder = FormBuilder.empty
29
25
  .addField("email", Schema.String)
30
26
  .addField("otp", Schema.String);
@@ -38,9 +34,7 @@ const defaultMessages = {
38
34
  auth_continue_with_google: "Continue with Google",
39
35
  auth_or_continue_with: "or continue with",
40
36
  auth_sign_in: "Sign in",
41
- auth_sign_up: "Sign up",
42
37
  field_email: "Email",
43
- field_name: "Name",
44
38
  field_password: "Password",
45
39
  forgot_password_back_to_sign_in: "Back to sign in",
46
40
  forgot_password_description: "Enter your email and we will send a reset link if an account exists.",
@@ -66,15 +60,8 @@ const defaultMessages = {
66
60
  sign_in_email_otp_verify: "Verify code",
67
61
  sign_in_error: "Unable to sign in.",
68
62
  sign_in_forgot_password: "Forgot your password?",
69
- sign_in_need_account: "Need an account?",
70
63
  sign_in_use_email_otp: "Use email code instead",
71
- sign_in_use_password: "Use password instead",
72
- sign_up_description: "Enter your details to create an account.",
73
- sign_up_disabled_description: "New account registration is currently disabled for this project.",
74
- sign_up_disabled_title: "Sign-up is unavailable",
75
- sign_up_error: "Unable to create account.",
76
- sign_up_have_account: "Already have an account?",
77
- sign_up_title: "Create account",
64
+ sign_in_use_password: "Use an existing password",
78
65
  two_factor_backup_code: "Backup code",
79
66
  two_factor_code: "Authentication code",
80
67
  two_factor_email_code: "Email verification code",
@@ -101,9 +88,7 @@ const defaultMessages = {
101
88
  auth_continue_with_google: "Continuer avec Google",
102
89
  auth_or_continue_with: "ou continuez avec",
103
90
  auth_sign_in: "Se connecter",
104
- auth_sign_up: "S'inscrire",
105
91
  field_email: "Courriel",
106
- field_name: "Nom",
107
92
  field_password: "Mot de passe",
108
93
  forgot_password_back_to_sign_in: "Retour à la connexion",
109
94
  forgot_password_description: "Saisissez votre courriel et nous enverrons un lien de réinitialisation si un compte existe.",
@@ -129,15 +114,8 @@ const defaultMessages = {
129
114
  sign_in_email_otp_verify: "Vérifier le code",
130
115
  sign_in_error: "Impossible de se connecter.",
131
116
  sign_in_forgot_password: "Mot de passe oublié?",
132
- sign_in_need_account: "Besoin d'un compte?",
133
117
  sign_in_use_email_otp: "Utiliser un code courriel",
134
- sign_in_use_password: "Utiliser le mot de passe",
135
- sign_up_description: "Saisissez vos informations pour créer un compte.",
136
- sign_up_disabled_description: "Les nouvelles inscriptions sont actuellement désactivées pour ce projet.",
137
- sign_up_disabled_title: "L'inscription est indisponible",
138
- sign_up_error: "Impossible de créer le compte.",
139
- sign_up_have_account: "Vous avez déjà un compte?",
140
- sign_up_title: "Créer un compte",
118
+ sign_in_use_password: "Utiliser un mot de passe existant",
141
119
  two_factor_backup_code: "Code de secours",
142
120
  two_factor_code: "Code d'authentification",
143
121
  two_factor_email_code: "Code de vérification par courriel",
@@ -204,9 +182,17 @@ const useAuthProjectConfig = (baseUrl, searchString, projectConfig) => {
204
182
  : Schema.decodeUnknownSync(ExtraProjectPublicConfigSchema)(result.value);
205
183
  };
206
184
  const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
207
- const authLinkClassName = cn(buttonVariants({ variant: "link" }), "h-auto px-0 align-baseline");
208
- const lastLoginMethodToAuthMethod = (method) => method === "email" ? "password" : "emailOtp";
185
+ const authLinkClassName = cn(buttonVariants({ variant: "link", size: null }), "h-auto align-baseline");
209
186
  const searchObject = (searchString) => Object.fromEntries(new URLSearchParams(searchString));
187
+ const authMethodSearch = (searchString, method, email) => {
188
+ const search = new URLSearchParams(searchString);
189
+ search.set("method", method);
190
+ if (email?.trim())
191
+ search.set("email", email.trim());
192
+ else if (email !== undefined)
193
+ search.delete("email");
194
+ return Object.fromEntries(search);
195
+ };
210
196
  export function Signin(props) {
211
197
  const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
212
198
  const navigate = useNavigate();
@@ -216,6 +202,7 @@ export function Signin(props) {
216
202
  const projectConfig = useAuthProjectConfig(baseUrl, searchString, providedProjectConfig);
217
203
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
218
204
  const socialRedirectTarget = getSocialRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
205
+ const initialEmail = getSearchParam(searchString, "email")?.trim() ?? "";
219
206
  const oauthQuery = getOAuthQuery(searchString);
220
207
  const authOptions = projectConfig?.authOptions;
221
208
  const onNavigate = (target) => navigateTarget(target, navigate);
@@ -224,11 +211,19 @@ export function Signin(props) {
224
211
  emailPassword: authOptions?.emailPassword ?? true,
225
212
  emailOtp: authOptions?.emailOtp ?? true,
226
213
  google: authOptions?.google ?? true,
227
- signUp: authOptions?.signUp ?? true,
228
214
  };
229
- const [emailSubmitted, setEmailSubmitted] = useState(false);
230
- const [authMethod, setAuthMethod] = useState(() => lastLoginMethodToAuthMethod(authClient.getLastUsedLoginMethod?.()));
231
- const [otpSentTo, setOtpSentTo] = useState("");
215
+ const requestedMethod = getSearchParam(searchString, "method");
216
+ const initialAuthMethod = requestedMethod === "password" && options.emailPassword
217
+ ? "password"
218
+ : requestedMethod === "emailOtp" && options.emailOtp
219
+ ? "emailOtp"
220
+ : options.emailOtp
221
+ ? "emailOtp"
222
+ : "password";
223
+ const initialMethodStep = Boolean(initialEmail) && requestedMethod === initialAuthMethod;
224
+ const [emailSubmitted, setEmailSubmitted] = useState(initialMethodStep);
225
+ const [authMethod, setAuthMethod] = useState(initialAuthMethod);
226
+ const [otpSentTo, setOtpSentTo] = useState(initialMethodStep && initialAuthMethod === "emailOtp" ? initialEmail : "");
232
227
  const [emailOtpResendAvailableAt, setEmailOtpResendAvailableAt] = useState(0);
233
228
  const [emailOtpResendSeconds, setEmailOtpResendSeconds] = useState(0);
234
229
  const selectedAuthMethod = authMethod === "password" && options.emailPassword
@@ -270,6 +265,11 @@ export function Signin(props) {
270
265
  setAuthMethod("emailOtp");
271
266
  setEmailSubmitted(true);
272
267
  setOtpSentTo(email);
268
+ navigate({
269
+ to: "/sign-in",
270
+ search: authMethodSearch(searchString, "emailOtp", email),
271
+ replace: true,
272
+ });
273
273
  setEmailOtpResendAvailableAt(Date.now() + EMAIL_OTP_RESEND_COOLDOWN_SECONDS * 1000);
274
274
  };
275
275
  if (action.type === "sendEmailOtp") {
@@ -279,8 +279,14 @@ export function Signin(props) {
279
279
  if (!action.emailSubmitted) {
280
280
  if (action.method === "emailOtp")
281
281
  await sendEmailOtp();
282
- else
282
+ else {
283
283
  setEmailSubmitted(true);
284
+ navigate({
285
+ to: "/sign-in",
286
+ search: authMethodSearch(searchString, "password", email),
287
+ replace: true,
288
+ });
289
+ }
284
290
  return;
285
291
  }
286
292
  if (action.method === "emailOtp") {
@@ -291,6 +297,7 @@ export function Signin(props) {
291
297
  const result = await authClient.signIn.emailOtp({
292
298
  email,
293
299
  otp: value.otp.trim(),
300
+ name: nameFromEmail(email),
294
301
  });
295
302
  if (result.error) {
296
303
  throw new Error(result.error.message ?? m.sign_in_email_otp_error);
@@ -362,6 +369,11 @@ export function Signin(props) {
362
369
  setEmailSubmitted(false);
363
370
  setOtpSentTo("");
364
371
  setEmailOtpResendAvailableAt(0);
372
+ navigate({
373
+ to: "/sign-in",
374
+ search: authMethodSearch(searchString, selectedAuthMethod, ""),
375
+ replace: true,
376
+ });
365
377
  };
366
378
  const switchAuthMethod = () => {
367
379
  setPassword("");
@@ -372,6 +384,11 @@ export function Signin(props) {
372
384
  setAuthMethod("password");
373
385
  setOtpSentTo("");
374
386
  setEmailOtpResendAvailableAt(0);
387
+ navigate({
388
+ to: "/sign-in",
389
+ search: authMethodSearch(searchString, "password", formValues.email),
390
+ replace: true,
391
+ });
375
392
  return;
376
393
  }
377
394
  submit({ type: "sendEmailOtp" });
@@ -381,7 +398,7 @@ export function Signin(props) {
381
398
  submit({ type: "sendEmailOtp" });
382
399
  };
383
400
  const signInWithGoogle = () => startSocialSignIn("google");
384
- 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) => {
401
+ 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: initialEmail, password: "", otp: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
385
402
  event.preventDefault();
386
403
  event.stopPropagation();
387
404
  submit({
@@ -390,12 +407,12 @@ export function Signin(props) {
390
407
  method: selectedAuthMethod,
391
408
  otpSent: Boolean(otpSentTo),
392
409
  });
393
- }, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", onKeyDown: (event) => {
410
+ }, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoFocus: true, autoComplete: "email", onKeyDown: (event) => {
394
411
  if (event.key !== "Enter")
395
412
  return;
396
413
  event.preventDefault();
397
414
  event.currentTarget.form?.requestSubmit();
398
- }, 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: "/reset-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
415
+ }, 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: "/reset-password", search: authMethodSearch(searchString, "password", formValues.email.trim()), 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
399
416
  ? text(m.sign_in_email_otp_resend_countdown, {
400
417
  seconds: String(emailOtpResendSeconds),
401
418
  })
@@ -403,78 +420,7 @@ export function Signin(props) {
403
420
  ? m.sign_in_continue
404
421
  : selectedAuthMethod === "emailOtp"
405
422
  ? m.sign_in_email_otp_verify
406
- : 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] }), _jsx(SubmitError, { result: socialSignInResult })] })) : 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] })] }));
407
- }
408
- export function Signup(props) {
409
- const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
410
- const navigate = useNavigate();
411
- const searchString = useRouterState({
412
- select: (state) => state.location.searchStr,
413
- });
414
- const projectConfig = useAuthProjectConfig(baseUrl, searchString, providedProjectConfig);
415
- const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
416
- const authOptions = projectConfig?.authOptions;
417
- const onNavigate = (target) => navigate({ href: target });
418
- const onVerifyEmail = (email) => navigate({
419
- to: "/verify-email",
420
- search: { ...searchObject(searchString), email },
421
- });
422
- const options = {
423
- google: authOptions?.google ?? true,
424
- signUp: authOptions?.signUp ?? true,
425
- signUpName: authOptions?.signUpName ?? true,
426
- };
427
- const [form] = useState(() => FormReact.make(signupFormBuilder, {
428
- fields: { name: TextField, email: TextField, password: TextField },
429
- mode: { validation: "onSubmit" },
430
- onSubmit: (_, { decoded: value }) => Effect.tryPromise({
431
- try: async () => {
432
- if (!options.signUp) {
433
- throw new Error(m.sign_up_disabled_description);
434
- }
435
- const result = await authClient.signUp.email({
436
- name: options.signUpName
437
- ? value.name.trim()
438
- : nameFromEmail(value.email),
439
- email: value.email.trim(),
440
- password: value.password,
441
- });
442
- if (result.error) {
443
- throw new Error(result.error.message ?? m.sign_up_error);
444
- }
445
- onVerifyEmail(value.email.trim());
446
- },
447
- catch: (cause) => cause instanceof Error ? cause : new Error(m.sign_up_error),
448
- }),
449
- }));
450
- const submit = useAtomSet(form.submit);
451
- const submitResult = useAtomValue(form.submit);
452
- const [socialSignUp] = useState(() => Atom.fn((provider) => Effect.tryPromise({
453
- try: async () => {
454
- const result = await authClient.signIn.social({
455
- provider,
456
- callbackURL: redirectTarget,
457
- errorCallbackURL: "/sign-up",
458
- });
459
- if (result.error) {
460
- throw new Error(result.error.message ?? m.sign_up_error);
461
- }
462
- if (result.data?.url)
463
- onNavigate(result.data.url);
464
- },
465
- catch: (cause) => cause instanceof Error ? cause : new Error(m.sign_up_error),
466
- })));
467
- const startSocialSignUp = useAtomSet(socialSignUp);
468
- const socialSignUpResult = useAtomValue(socialSignUp);
469
- const signUpWithGoogle = () => startSocialSignUp("google");
470
- if (!options.signUp) {
471
- 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] }) }) })] }));
472
- }
473
- 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) => {
474
- event.preventDefault();
475
- event.stopPropagation();
476
- submit();
477
- }, 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] }), _jsx(SubmitError, { result: socialSignUpResult })] })) : 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] }) })] })] }));
423
+ : 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] }), _jsx(SubmitError, { result: socialSignInResult })] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null] })] }));
478
424
  }
479
425
  export function VerifyEmail(props) {
480
426
  const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
@@ -535,6 +481,7 @@ export function ForgotPassword(props) {
535
481
  const searchString = useRouterState({
536
482
  select: (state) => state.location.searchStr,
537
483
  });
484
+ const initialEmail = getSearchParam(searchString, "email")?.trim() ?? "";
538
485
  const [submitted, setSubmitted] = useState(false);
539
486
  const [form] = useState(() => FormReact.make(forgotPasswordFormBuilder, {
540
487
  fields: { email: TextField },
@@ -556,7 +503,7 @@ export function ForgotPassword(props) {
556
503
  }));
557
504
  const submit = useAtomSet(form.submit);
558
505
  const submitResult = useAtomValue(form.submit);
559
- return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.forgot_password_title }), _jsx(CardDescription, { children: m.forgot_password_description })] }), _jsxs(CardContent, { children: [_jsx(form.Initialize, { defaultValues: { email: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
506
+ return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.forgot_password_title }), _jsx(CardDescription, { children: m.forgot_password_description })] }), _jsxs(CardContent, { children: [_jsx(form.Initialize, { defaultValues: { email: initialEmail }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
560
507
  event.preventDefault();
561
508
  event.stopPropagation();
562
509
  submit();
@@ -37,8 +37,6 @@ export declare const useKrakstackAuthProjectConfig: () => import("effect/Schema"
37
37
  readonly emailPassword: import("effect/Schema").Boolean;
38
38
  readonly emailOtp: import("effect/Schema").Boolean;
39
39
  readonly google: import("effect/Schema").Boolean;
40
- readonly signUp: import("effect/Schema").Boolean;
41
- readonly signUpName: import("effect/Schema").Boolean;
42
40
  }>;
43
41
  }, "Type"> | null;
44
42
  export declare const usePermissions: () => {
@@ -4,7 +4,7 @@ export { OrganizationSwitcher } from "./organization-switcher";
4
4
  export { MemberRequired } from "./member-required";
5
5
  export { HasPermission, useHasPermission } from "./has-permission";
6
6
  export { ProjectAccessMatrix } from "./project-access-matrix";
7
- export { ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
7
+ export { ForgotPassword, ResetPassword, Signin, TwoFactor, VerifyEmail, } from "./auth-forms";
8
8
  export { UserButton } from "./user-button";
9
9
  export { AdminOrganizationsTable } from "./admin-organizations";
10
10
  export { AdminOrganizationForm } from "./admin-organization-form";
@@ -4,7 +4,7 @@ export { OrganizationSwitcher } from "./organization-switcher";
4
4
  export { MemberRequired } from "./member-required";
5
5
  export { HasPermission, useHasPermission } from "./has-permission";
6
6
  export { ProjectAccessMatrix } from "./project-access-matrix";
7
- export { ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
7
+ export { ForgotPassword, ResetPassword, Signin, TwoFactor, VerifyEmail, } from "./auth-forms";
8
8
  export { UserButton } from "./user-button";
9
9
  export { AdminOrganizationsTable } from "./admin-organizations";
10
10
  export { AdminOrganizationForm } from "./admin-organization-form";
@@ -81,8 +81,6 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
81
81
  readonly emailPassword: Schema.Boolean;
82
82
  readonly emailOtp: Schema.Boolean;
83
83
  readonly google: Schema.Boolean;
84
- readonly signUp: Schema.Boolean;
85
- readonly signUpName: Schema.Boolean;
86
84
  }>;
87
85
  }>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
88
86
  readonly newPassword: Schema.NonEmptyString;
@@ -87,8 +87,6 @@ export declare const ExtraProjectAuthOptions: Schema.Struct<{
87
87
  readonly emailPassword: Schema.Boolean;
88
88
  readonly emailOtp: Schema.Boolean;
89
89
  readonly google: Schema.Boolean;
90
- readonly signUp: Schema.Boolean;
91
- readonly signUpName: Schema.Boolean;
92
90
  }>;
93
91
  export declare const ExtraProjectPublicConfig: Schema.Struct<{
94
92
  readonly projectKey: Schema.String;
@@ -101,8 +99,6 @@ export declare const ExtraProjectPublicConfig: Schema.Struct<{
101
99
  readonly emailPassword: Schema.Boolean;
102
100
  readonly emailOtp: Schema.Boolean;
103
101
  readonly google: Schema.Boolean;
104
- readonly signUp: Schema.Boolean;
105
- readonly signUpName: Schema.Boolean;
106
102
  }>;
107
103
  }>;
108
104
  export declare const ExtraOrganizationPublicProfileQuery: Schema.Struct<{
@@ -180,8 +180,6 @@ export const ExtraProjectAuthOptions = Schema.Struct({
180
180
  emailPassword: Schema.Boolean,
181
181
  emailOtp: Schema.Boolean,
182
182
  google: Schema.Boolean,
183
- signUp: Schema.Boolean,
184
- signUpName: Schema.Boolean,
185
183
  }).annotate({
186
184
  identifier: "ExtraProjectAuthOptions",
187
185
  title: "Extra project authentication options",
@@ -191,8 +189,6 @@ export const ExtraProjectAuthOptions = Schema.Struct({
191
189
  emailPassword: true,
192
190
  emailOtp: true,
193
191
  google: true,
194
- signUp: true,
195
- signUpName: true,
196
192
  },
197
193
  ],
198
194
  });
@@ -220,8 +216,6 @@ export const ExtraProjectPublicConfig = Schema.Struct({
220
216
  emailPassword: true,
221
217
  emailOtp: true,
222
218
  google: true,
223
- signUp: false,
224
- signUpName: true,
225
219
  },
226
220
  },
227
221
  ],
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
5
5
  export { AuthService, type AuthServiceLayerOptions } from "./service";
6
6
  export { AuthClientConfig } from "./config";
7
7
  export { proxyAuthRequest } from "./server/proxy";
8
- export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type MemberRequiredMessages, type MemberRequiredProps, type ProjectAccessMatrixAccess, type ProjectAccessMatrixMessages, type ProjectAccessLabels, type ProjectAccessLabelCatalog, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherFeatures, type OrganizationSwitcherProps, type UserButtonDialog, type UserButtonProps, useAuthClient, useAdminUsersTotal, } from "./components";
8
+ export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type MemberRequiredMessages, type MemberRequiredProps, type ProjectAccessMatrixAccess, type ProjectAccessMatrixMessages, type ProjectAccessLabels, type ProjectAccessLabelCatalog, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherFeatures, type OrganizationSwitcherProps, type UserButtonDialog, type UserButtonProps, useAuthClient, useAdminUsersTotal, } from "./components";
9
9
  export * as BetterAuth from "./better-auth/api.group";
10
10
  export * as Extra from "./extra/api.group";
11
11
  export * as Server from "./server";
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
5
5
  export { AuthService } from "./service";
6
6
  export { AuthClientConfig } from "./config";
7
7
  export { proxyAuthRequest } from "./server/proxy";
8
- export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
8
+ export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
9
9
  export * as BetterAuth from "./better-auth/api.group";
10
10
  export * as Extra from "./extra/api.group";
11
11
  export * as Server from "./server";
@@ -1,4 +1,5 @@
1
1
  const blockedRequestHeaders = [
2
+ "accept-encoding",
2
3
  "connection",
3
4
  "content-length",
4
5
  "forwarded",
@@ -12,6 +13,22 @@ const blockedRequestHeaders = [
12
13
  "upgrade",
13
14
  "cdn-loop",
14
15
  ];
16
+ const hostOnlyCookie = (cookie) => cookie.replace(/;\s*domain=[^;]*/gi, "");
17
+ const proxyResponse = async (response) => {
18
+ const headers = new Headers(response.headers);
19
+ const cookies = response.headers.getSetCookie();
20
+ if (cookies.length > 0) {
21
+ headers.delete("set-cookie");
22
+ for (const cookie of cookies) {
23
+ headers.append("set-cookie", hostOnlyCookie(cookie));
24
+ }
25
+ }
26
+ return new Response(response.body, {
27
+ status: response.status,
28
+ statusText: response.statusText,
29
+ headers,
30
+ });
31
+ };
15
32
  const forwardedUrl = (request) => {
16
33
  return new URL(request.url);
17
34
  };
@@ -29,7 +46,7 @@ const proxyHeaders = (request) => {
29
46
  headers.set("x-forwarded-proto", url.protocol.replace(":", ""));
30
47
  return headers;
31
48
  };
32
- export const proxyAuthRequest = (request, baseUrl) => {
49
+ export const proxyAuthRequest = async (request, baseUrl) => {
33
50
  const target = new URL(request.url);
34
51
  const authUrl = new URL(baseUrl);
35
52
  const init = {
@@ -43,5 +60,8 @@ export const proxyAuthRequest = (request, baseUrl) => {
43
60
  if (request.method !== "GET" && request.method !== "HEAD") {
44
61
  init.body = request.body;
45
62
  }
46
- return fetch(new Request(target, init), { redirect: "manual" });
63
+ const response = await fetch(new Request(target, init), {
64
+ redirect: "manual",
65
+ });
66
+ return proxyResponse(response);
47
67
  };
package/dist/service.d.ts CHANGED
@@ -194,8 +194,6 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
194
194
  readonly emailPassword: import("effect/Schema").Boolean;
195
195
  readonly emailOtp: import("effect/Schema").Boolean;
196
196
  readonly google: import("effect/Schema").Boolean;
197
- readonly signUp: import("effect/Schema").Boolean;
198
- readonly signUpName: import("effect/Schema").Boolean;
199
197
  }>;
200
198
  }, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : HttpApiError.InternalServerError | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
201
199
  readonly setPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
@@ -826,8 +824,6 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
826
824
  readonly emailPassword: import("effect/Schema").Boolean;
827
825
  readonly emailOtp: import("effect/Schema").Boolean;
828
826
  readonly google: import("effect/Schema").Boolean;
829
- readonly signUp: import("effect/Schema").Boolean;
830
- readonly signUpName: import("effect/Schema").Boolean;
831
827
  }>;
832
828
  }, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : HttpApiError.InternalServerError | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
833
829
  readonly setPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.64",
3
+ "version": "0.1.66",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [