@krak-stack/auth 0.2.9 → 0.2.11

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,5 +1,5 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
2
+ import { useAtomSet, useAtomValue } from "@effect/atom-react";
3
3
  import { useNavigate, useRouter } from "@tanstack/react-router";
4
4
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
5
5
  import { Effect, Option, Schema } from "effect";
@@ -138,7 +138,6 @@ export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
138
138
  const baseUrl = auth?.baseUrl;
139
139
  const sessionAtom = authSessionAtom(baseUrl);
140
140
  const sessionResult = useAtomValue(sessionAtom);
141
- const refetchSession = useAtomRefresh(sessionAtom);
142
141
  const session = AsyncResult.match(sessionResult, {
143
142
  onInitial: () => null,
144
143
  onFailure: () => null,
@@ -159,8 +158,6 @@ export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
159
158
  const client = yield* authHttpClient(baseUrl);
160
159
  yield* client.auth.adminImpersonateUser({ payload: { userId } });
161
160
  notifyAuthChange();
162
- auth?.refreshAuth();
163
- refetchSession();
164
161
  yield* Effect.tryPromise({
165
162
  try: async () => {
166
163
  await navigate({ to: "/" });
@@ -179,8 +176,6 @@ export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
179
176
  payload: { organizationId, actorUserId, targetUserId },
180
177
  });
181
178
  notifyAuthChange();
182
- auth?.refreshAuth();
183
- refetchSession();
184
179
  yield* Effect.tryPromise({
185
180
  try: async () => {
186
181
  await navigate({ to: "/" });
@@ -1,6 +1,7 @@
1
- import { Atom } from "effect/unstable/reactivity";
1
+ import { AsyncResult, Atom } from "effect/unstable/reactivity";
2
2
  export declare const AUTH_CLIENT_CHANGE_EVENT = "krakstack-auth:change";
3
- export declare const authSessionAtom: (arg: string | undefined) => Atom.Writable<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
3
+ export declare const refreshOnAuthChange: <A>(atom: Atom.Atom<A>) => Atom.Atom<A>;
4
+ export declare const authSessionAtom: (arg: string | undefined) => Atom.Atom<AsyncResult.AsyncResult<{
4
5
  readonly session: {
5
6
  readonly id: string;
6
7
  readonly expiresAt: Date;
@@ -61,69 +62,8 @@ export declare const authSessionAtom: (arg: string | undefined) => Atom.Writable
61
62
  readonly createdAt: Date;
62
63
  readonly updatedAt: Date;
63
64
  };
64
- } | null, import("../auth/schema.js").AuthBadRequest>, Atom.Atom<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
65
- readonly session: {
66
- readonly id: string;
67
- readonly expiresAt: Date;
68
- readonly token: string;
69
- readonly createdAt: Date;
70
- readonly updatedAt: Date;
71
- readonly ipAddress?: string | null | undefined;
72
- readonly userAgent?: string | null | undefined;
73
- readonly userId: string;
74
- readonly impersonatedBy?: string | null | undefined;
75
- readonly impersonatedByOrganizationId?: string | null | undefined;
76
- readonly activeOrganizationId?: string | null | undefined;
77
- };
78
- readonly user: {
79
- readonly id: string;
80
- readonly name: string;
81
- readonly email: string;
82
- readonly emailVerified: boolean;
83
- readonly image: string | null;
84
- readonly metadata?: {
85
- readonly emails?: readonly {
86
- readonly email: string;
87
- readonly translations: readonly {
88
- readonly locale: "en" | "fr";
89
- readonly label: string;
90
- }[];
91
- }[] | undefined;
92
- readonly phones?: readonly {
93
- readonly number: string;
94
- readonly extension?: string | undefined;
95
- readonly translations: readonly {
96
- readonly locale: "en" | "fr";
97
- readonly label: string;
98
- }[];
99
- }[] | undefined;
100
- readonly websites?: readonly {
101
- readonly url: string;
102
- readonly translations: readonly {
103
- readonly locale: "en" | "fr";
104
- readonly label: string;
105
- }[];
106
- }[] | undefined;
107
- readonly socials?: readonly {
108
- readonly platform: "facebook" | "github" | "instagram" | "linkedin" | "tiktok" | "x" | "youtube";
109
- readonly url: string;
110
- readonly translations: readonly {
111
- readonly locale: "en" | "fr";
112
- readonly label: string;
113
- }[];
114
- }[] | undefined;
115
- } | null | undefined;
116
- readonly role: string | null;
117
- readonly banned: boolean | null;
118
- readonly banReason?: string | null | undefined;
119
- readonly banExpires?: Date | null | undefined;
120
- readonly twoFactorEnabled?: boolean | undefined;
121
- readonly lastLoginMethod?: string | null | undefined;
122
- readonly createdAt: Date;
123
- readonly updatedAt: Date;
124
- };
125
- } | null, import("../auth/schema.js").AuthBadRequest>, unknown>>>;
126
- export declare const authOrganizationsAtom: (arg: string | undefined) => Atom.Writable<import("effect/unstable/reactivity/AsyncResult").AsyncResult<readonly {
65
+ } | null, import("../auth/schema.js").AuthBadRequest>>;
66
+ export declare const authOrganizationsAtom: (arg: string | undefined) => Atom.Atom<AsyncResult.AsyncResult<readonly {
127
67
  readonly id: string;
128
68
  readonly name: string;
129
69
  readonly slug: string;
@@ -134,87 +74,8 @@ export declare const authOrganizationsAtom: (arg: string | undefined) => Atom.Wr
134
74
  readonly userId?: string | null | undefined;
135
75
  readonly parentId?: string | null | undefined;
136
76
  readonly createdAt: Date;
137
- }[], import("../auth/schema.js").AuthBadRequest>, Atom.Atom<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/unstable/reactivity/AsyncResult").AsyncResult<readonly {
138
- readonly id: string;
139
- readonly name: string;
140
- readonly slug: string;
141
- readonly logo?: string | null | undefined;
142
- readonly metadata?: string | {
143
- readonly [x: string]: import("effect/Schema").Json;
144
- } | null | undefined;
145
- readonly userId?: string | null | undefined;
146
- readonly parentId?: string | null | undefined;
147
- readonly createdAt: Date;
148
- }[], import("../auth/schema.js").AuthBadRequest>, unknown>>>;
149
- export declare const activeAuthOrganizationAtom: (arg: string | undefined) => (arg: string | null) => Atom.Writable<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
150
- readonly id: string;
151
- readonly name: string;
152
- readonly slug: string;
153
- readonly logo?: string | null | undefined;
154
- readonly metadata?: string | {
155
- readonly [x: string]: import("effect/Schema").Json;
156
- } | null | undefined;
157
- readonly userId?: string | null | undefined;
158
- readonly parentId?: string | null | undefined;
159
- readonly createdAt: Date;
160
- readonly members: readonly {
161
- readonly id: string;
162
- readonly organizationId: string;
163
- readonly userId: string;
164
- readonly role: string;
165
- readonly createdAt: Date;
166
- readonly user: {
167
- readonly id: string;
168
- readonly name: string;
169
- readonly email: string;
170
- readonly image?: string | null | undefined;
171
- readonly metadata?: {
172
- readonly emails?: readonly {
173
- readonly email: string;
174
- readonly translations: readonly {
175
- readonly locale: "en" | "fr";
176
- readonly label: string;
177
- }[];
178
- }[] | undefined;
179
- readonly phones?: readonly {
180
- readonly number: string;
181
- readonly extension?: string | undefined;
182
- readonly translations: readonly {
183
- readonly locale: "en" | "fr";
184
- readonly label: string;
185
- }[];
186
- }[] | undefined;
187
- readonly websites?: readonly {
188
- readonly url: string;
189
- readonly translations: readonly {
190
- readonly locale: "en" | "fr";
191
- readonly label: string;
192
- }[];
193
- }[] | undefined;
194
- readonly socials?: readonly {
195
- readonly platform: "facebook" | "github" | "instagram" | "linkedin" | "tiktok" | "x" | "youtube";
196
- readonly url: string;
197
- readonly translations: readonly {
198
- readonly locale: "en" | "fr";
199
- readonly label: string;
200
- }[];
201
- }[] | undefined;
202
- } | null | undefined;
203
- };
204
- }[];
205
- readonly invitations: readonly {
206
- readonly id: string;
207
- readonly email: string;
208
- readonly role: string;
209
- readonly organizationId: string;
210
- readonly organizationName?: string | null | undefined;
211
- readonly inviterId: string;
212
- readonly teamId?: string | null | undefined;
213
- readonly status: string;
214
- readonly expiresAt: Date;
215
- readonly createdAt?: Date | undefined;
216
- }[];
217
- } | null, import("../auth/schema.js").AuthBadRequest>, Atom.Atom<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
77
+ }[], import("../auth/schema.js").AuthBadRequest>>;
78
+ export declare const activeAuthOrganizationAtom: (arg: string | undefined) => (arg: string | null) => Atom.Atom<AsyncResult.AsyncResult<{
218
79
  readonly id: string;
219
80
  readonly name: string;
220
81
  readonly slug: string;
@@ -282,7 +143,6 @@ export declare const activeAuthOrganizationAtom: (arg: string | undefined) => (a
282
143
  readonly expiresAt: Date;
283
144
  readonly createdAt?: Date | undefined;
284
145
  }[];
285
- } | null, import("../auth/schema.js").AuthBadRequest>, unknown>>>;
146
+ } | null, import("../auth/schema.js").AuthBadRequest>>;
286
147
  export declare const getLastUsedLoginMethod: () => string | null;
287
148
  export declare const notifyAuthChange: () => void;
288
- export declare const isAuthClientStorageEvent: (event: StorageEvent) => boolean;
@@ -1,22 +1,44 @@
1
- import { Atom } from "effect/unstable/reactivity";
1
+ import { Option } from "effect";
2
+ import { AsyncResult, Atom } from "effect/unstable/reactivity";
2
3
  import { authClientApi } from "./auth-client-api.js";
3
4
  const LAST_LOGIN_METHOD_COOKIE = "krakstack-auth.last_used_login_method";
4
5
  export const AUTH_CLIENT_CHANGE_EVENT = "krakstack-auth:change";
5
- const AUTH_CLIENT_CHANGE_STORAGE_KEY = "krakstack-auth.change";
6
- export const authSessionAtom = Atom.family((baseUrl) => Atom.optimistic(authClientApi(baseUrl).query("auth", "getSession", {
6
+ const authRevalidationSignal = Atom.make((get) => {
7
+ if (globalThis.window) {
8
+ const onChange = (event) => get.setSelf(event);
9
+ window.addEventListener(AUTH_CLIENT_CHANGE_EVENT, onChange);
10
+ get.addFinalizer(() => window.removeEventListener(AUTH_CLIENT_CHANGE_EVENT, onChange));
11
+ }
12
+ return null;
13
+ });
14
+ // Each registry subscribes once; query refreshes stay inside the atom graph.
15
+ const refreshOnAuthSignal = Atom.makeRefreshOnSignal(authRevalidationSignal);
16
+ export const refreshOnAuthChange = (atom) => {
17
+ const reactive = refreshOnAuthSignal(atom);
18
+ // The built-in visibility helper is browser-only.
19
+ return globalThis.window ? Atom.refreshOnWindowFocus(reactive) : reactive;
20
+ };
21
+ export const authSessionAtom = Atom.family((baseUrl) => Atom.optimistic(authClientApi(baseUrl)
22
+ .query("auth", "getSession", {
7
23
  query: {},
8
24
  timeToLive: "1 minute",
9
25
  reactivityKeys: ["auth-session"],
10
- })));
26
+ })
27
+ .pipe(Atom.map((result) => {
28
+ const unauthorized = AsyncResult.error(result).pipe(Option.exists((error) => error._tag === "AuthUnauthorized"));
29
+ return unauthorized && !result.waiting
30
+ ? AsyncResult.success(null)
31
+ : result;
32
+ }))).pipe(refreshOnAuthChange));
11
33
  export const authOrganizationsAtom = Atom.family((baseUrl) => Atom.optimistic(authClientApi(baseUrl).query("auth", "organizationList", {
12
34
  timeToLive: "1 minute",
13
35
  reactivityKeys: ["auth-organizations"],
14
- })));
36
+ })).pipe(refreshOnAuthChange));
15
37
  export const activeAuthOrganizationAtom = Atom.family((baseUrl) => Atom.family((organizationId) => Atom.optimistic(authClientApi(baseUrl).query("auth", "organizationGetFull", {
16
38
  query: organizationId ? { organizationId } : {},
17
39
  timeToLive: "1 minute",
18
40
  reactivityKeys: ["auth-active-organization", organizationId ?? "none"],
19
- }))));
41
+ })).pipe(refreshOnAuthChange)));
20
42
  export const getLastUsedLoginMethod = () => {
21
43
  const cookies = globalThis.document?.cookie;
22
44
  if (!cookies)
@@ -36,11 +58,4 @@ export const getLastUsedLoginMethod = () => {
36
58
  };
37
59
  export const notifyAuthChange = () => {
38
60
  globalThis.window?.dispatchEvent(new Event(AUTH_CLIENT_CHANGE_EVENT));
39
- try {
40
- globalThis.localStorage?.setItem(AUTH_CLIENT_CHANGE_STORAGE_KEY, String(Date.now()));
41
- }
42
- catch {
43
- // Storage may be unavailable in privacy-restricted browser contexts.
44
- }
45
61
  };
46
- export const isAuthClientStorageEvent = (event) => event.key === AUTH_CLIENT_CHANGE_STORAGE_KEY;
@@ -2,7 +2,7 @@ import { Effect } from "effect";
2
2
  import { AtomHttpApi } from "effect/unstable/reactivity";
3
3
  import { HttpApi, HttpApiClient } from "effect/unstable/httpapi";
4
4
  import { AuthClientApi } from "../api.js";
5
- export declare const authHttpClient: (baseUrl?: string | undefined) => Effect.Effect<{
5
+ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?: (() => "en" | "fr") | undefined) => Effect.Effect<{
6
6
  readonly admin: {
7
7
  readonly createDomain: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"createDomain", "POST", "/api/auth/admin/domains", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
8
8
  readonly hostname: import("effect/Schema").NonEmptyString;
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { FetchHttpClient, HttpClient } from "effect/unstable/http";
2
+ import { FetchHttpClient, HttpClient, HttpClientRequest, } from "effect/unstable/http";
3
3
  import { AtomHttpApi } from "effect/unstable/reactivity";
4
4
  import { HttpApi, HttpApiClient } from "effect/unstable/httpapi";
5
5
  import { AuthClientApi } from "../api.js";
@@ -11,9 +11,14 @@ const authClientApiUrl = (baseUrl) => {
11
11
  const withCredentials = (client) => HttpClient.makeWith((request) => client.postprocess(request).pipe(Effect.provideService(FetchHttpClient.RequestInit, {
12
12
  credentials: "include",
13
13
  })), client.preprocess);
14
- export const authHttpClient = (baseUrl) => HttpApiClient.make(AuthClientApi, {
14
+ export const authHttpClient = (baseUrl, getLocale) => HttpApiClient.make(AuthClientApi, {
15
15
  baseUrl: authClientApiUrl(baseUrl),
16
- transformClient: withCredentials,
16
+ transformClient: (client) => withCredentials(client).pipe(HttpClient.mapRequest((request) => {
17
+ const requestLocale = getLocale?.();
18
+ return requestLocale
19
+ ? HttpClientRequest.setHeader(request, "accept-language", requestLocale)
20
+ : request;
21
+ })),
17
22
  }).pipe(Effect.provide(FetchHttpClient.layer));
18
23
  const createAuthClientApiClient = (key) => {
19
24
  class AuthClientApiClient extends AtomHttpApi.Service()(`AuthClientApi:${key}`, {
@@ -1,3 +1,4 @@
1
+ import { useNavigate } from "@tanstack/react-router";
1
2
  import { type KrakstackAuthLocale } from "./auth-provider.js";
2
3
  type AuthFormProps = {
3
4
  baseUrl?: string | undefined;
@@ -10,11 +11,10 @@ export declare const resolveInitialAuthMethod: ({ requestedMethod, lastLoginMeth
10
11
  emailPassword: boolean;
11
12
  emailOtp: boolean;
12
13
  }) => AuthMethod;
13
- export declare function Signin(props: AuthFormProps & {
14
- otpExpiryDescription?: string | undefined;
15
- }): import("react").JSX.Element;
14
+ export declare function Signin(props: AuthFormProps): import("react").JSX.Element;
16
15
  export declare function VerifyEmail(props: AuthFormProps): import("react").JSX.Element;
17
16
  export declare function ForgotPassword(props: AuthFormProps): import("react").JSX.Element;
18
17
  export declare function ResetPassword(props: AuthFormProps): import("react").JSX.Element;
19
18
  export declare function TwoFactor(props: AuthFormProps): import("react").JSX.Element;
19
+ export declare const navigateTarget: (target: string, navigate: ReturnType<typeof useNavigate>) => Promise<void>;
20
20
  export {};
@@ -6,7 +6,7 @@ import { Effect, Option, Schema } from "effect";
6
6
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
7
7
  import { REGEXP_ONLY_DIGITS } from "input-otp";
8
8
  import { KeyRound, Loader2, Mail } from "lucide-react";
9
- import { useEffect, useState } from "react";
9
+ import { useEffect, useRef, useState } from "react";
10
10
  import { Button, buttonVariants } from "@/components/ui/button";
11
11
  import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card";
12
12
  import { CheckboxField, ErrorMessage, SubmitError, TextField, effectFormMessages, } from "@krak-stack/registry/effect-form";
@@ -55,6 +55,7 @@ const defaultMessages = {
55
55
  sign_in_email_as: "Signing in as {email}",
56
56
  sign_in_email_otp_code: "Email code",
57
57
  sign_in_email_otp_error: "Unable to verify the sign-in code.",
58
+ sign_in_otp_expiry: "Your code expires 5 minutes after it's sent.",
58
59
  sign_in_email_otp_resend: "Resend code",
59
60
  sign_in_email_otp_resend_countdown: "Resend in {seconds}s",
60
61
  sign_in_email_otp_send_error: "Unable to send the sign-in code.",
@@ -109,6 +110,7 @@ const defaultMessages = {
109
110
  sign_in_email_as: "Connexion avec {email}",
110
111
  sign_in_email_otp_code: "Code courriel",
111
112
  sign_in_email_otp_error: "Impossible de vérifier le code de connexion.",
113
+ sign_in_otp_expiry: "Votre code expire 5 minutes après son envoi.",
112
114
  sign_in_email_otp_resend: "Renvoyer le code",
113
115
  sign_in_email_otp_resend_countdown: "Renvoyer dans {seconds} s",
114
116
  sign_in_email_otp_send_error: "Impossible d'envoyer le code de connexion.",
@@ -145,9 +147,16 @@ const labels = (locale) => ({
145
147
  });
146
148
  const useAuthFormOptions = ({ baseUrl, locale }) => {
147
149
  const auth = useKrakstackAuth();
150
+ const resolvedLocale = locale ?? auth?.locale ?? "en";
151
+ const localeRef = useRef(resolvedLocale);
152
+ useEffect(() => {
153
+ localeRef.current = resolvedLocale;
154
+ }, [resolvedLocale]);
148
155
  return {
149
156
  baseUrl: baseUrl ?? auth?.baseUrl,
150
- labels: labels(locale ?? auth?.locale ?? "en"),
157
+ // Form atoms retain their initial handlers; resolve the locale when sending.
158
+ locale: () => localeRef.current,
159
+ labels: labels(resolvedLocale),
151
160
  projectConfig: auth?.projectConfig,
152
161
  };
153
162
  };
@@ -204,7 +213,7 @@ export const resolveInitialAuthMethod = ({ requestedMethod, lastLoginMethod, ema
204
213
  return emailOtp ? "emailOtp" : "password";
205
214
  };
206
215
  export function Signin(props) {
207
- const { baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
216
+ const { baseUrl, locale, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
208
217
  const navigate = useNavigate();
209
218
  const searchString = useRouterState({
210
219
  select: (state) => state.location.searchStr,
@@ -263,7 +272,7 @@ export function Signin(props) {
263
272
  mode: { validation: "onSubmit" },
264
273
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
265
274
  const email = value.email.trim();
266
- const sendEmailOtp = authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
275
+ const sendEmailOtp = authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
267
276
  payload: { email, type: "sign-in" },
268
277
  })), Effect.tap(() => Effect.sync(() => {
269
278
  setAuthMethod("emailOtp");
@@ -298,7 +307,7 @@ export function Signin(props) {
298
307
  yield* sendEmailOtp;
299
308
  return;
300
309
  }
301
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.signInEmailOtp({
310
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.signInEmailOtp({
302
311
  payload: {
303
312
  email,
304
313
  otp: value.otp.trim(),
@@ -321,7 +330,7 @@ export function Signin(props) {
321
330
  password: value.password,
322
331
  callbackURL: redirectTarget,
323
332
  };
324
- const result = yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.signInEmail({ payload })));
333
+ const result = yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.signInEmail({ payload })));
325
334
  if (hasTwoFactorRedirect(result)) {
326
335
  onTwoFactorRedirect(`/2fa${oauthQuery ? `?${oauthQuery}` : `?callbackURL=${encodeURIComponent(redirectTarget)}`}`);
327
336
  return;
@@ -355,7 +364,7 @@ export function Signin(props) {
355
364
  callbackURL: socialRedirectTarget,
356
365
  errorCallbackURL: "/sign-in",
357
366
  };
358
- const result = yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.signInSocial({ payload })));
367
+ const result = yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.signInSocial({ payload })));
359
368
  notifyAuthChange();
360
369
  if (result.url)
361
370
  onNavigate(result.url);
@@ -421,7 +430,7 @@ export function Signin(props) {
421
430
  return;
422
431
  event.preventDefault();
423
432
  event.currentTarget.form?.requestSubmit();
424
- }, 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 }), props.otpExpiryDescription ? (_jsx("p", { className: "text-muted-foreground text-sm", children: props.otpExpiryDescription })) : null, _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
433
+ }, required: true })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.password, { label: m.field_password, type: "password", autoFocus: true, 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 }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.sign_in_otp_expiry }), _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
425
434
  ? text(m.sign_in_email_otp_resend_countdown, {
426
435
  seconds: String(emailOtpResendSeconds),
427
436
  })
@@ -432,7 +441,7 @@ export function Signin(props) {
432
441
  : 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] })] }));
433
442
  }
434
443
  export function VerifyEmail(props) {
435
- const { baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
444
+ const { baseUrl, locale, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
436
445
  const navigate = useNavigate();
437
446
  const searchString = useRouterState({
438
447
  select: (state) => state.location.searchStr,
@@ -447,7 +456,7 @@ export function VerifyEmail(props) {
447
456
  mode: { validation: "onSubmit" },
448
457
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
449
458
  if (action === "resend") {
450
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
459
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
451
460
  payload: {
452
461
  email: value.email.trim(),
453
462
  type: "email-verification",
@@ -456,7 +465,7 @@ export function VerifyEmail(props) {
456
465
  setResent(true);
457
466
  return;
458
467
  }
459
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.verifyEmailOtp({
468
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.verifyEmailOtp({
460
469
  payload: {
461
470
  email: value.email.trim(),
462
471
  otp: value.otp.trim(),
@@ -483,7 +492,7 @@ export function VerifyEmail(props) {
483
492
  }, 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 }) })] })] }));
484
493
  }
485
494
  export function ForgotPassword(props) {
486
- const { baseUrl, labels: m } = useAuthFormOptions(props);
495
+ const { baseUrl, locale, labels: m } = useAuthFormOptions(props);
487
496
  const searchString = useRouterState({
488
497
  select: (state) => state.location.searchStr,
489
498
  });
@@ -495,7 +504,7 @@ export function ForgotPassword(props) {
495
504
  mode: { validation: "onSubmit" },
496
505
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
497
506
  setSubmitted(false);
498
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.requestPasswordReset({
507
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.requestPasswordReset({
499
508
  payload: {
500
509
  email: value.email.trim(),
501
510
  redirectTo: `${window.location.origin}/reset-password`,
@@ -520,7 +529,7 @@ export function ResetPassword(props) {
520
529
  return token ? (_jsx(ResetPasswordForm, { ...props, token: token })) : (_jsx(ForgotPassword, { ...props }));
521
530
  }
522
531
  function ResetPasswordForm({ token, ...props }) {
523
- const { baseUrl, labels: m } = useAuthFormOptions(props);
532
+ const { baseUrl, locale, labels: m } = useAuthFormOptions(props);
524
533
  const navigate = useNavigate();
525
534
  const onSuccess = () => navigate({ to: "/sign-in" });
526
535
  const [form] = useState(() => FormReact.make(resetPasswordFormBuilder, {
@@ -528,7 +537,7 @@ function ResetPasswordForm({ token, ...props }) {
528
537
  fields: { password: TextField },
529
538
  mode: { validation: "onSubmit" },
530
539
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
531
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.resetPassword({
540
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.resetPassword({
532
541
  payload: {
533
542
  newPassword: value.password,
534
543
  token,
@@ -546,7 +555,7 @@ function ResetPasswordForm({ token, ...props }) {
546
555
  }, 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] })] }) }) })] }));
547
556
  }
548
557
  export function TwoFactor(props) {
549
- const { baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
558
+ const { baseUrl, locale, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
550
559
  const navigate = useNavigate();
551
560
  const searchString = useRouterState({
552
561
  select: (state) => state.location.searchStr,
@@ -563,7 +572,7 @@ export function TwoFactor(props) {
563
572
  mode: { validation: "onSubmit" },
564
573
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
565
574
  if (action.type === "sendEmailCode") {
566
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorSendOtp({ payload: {} })));
575
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.twoFactorSendOtp({ payload: {} })));
567
576
  setEmailCodeSent(true);
568
577
  setMode("email");
569
578
  return;
@@ -576,7 +585,7 @@ export function TwoFactor(props) {
576
585
  oauth_query: oauthQuery,
577
586
  }
578
587
  : { code, trustDevice: value.trustDevice };
579
- const result = yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => action.mode === "backup"
588
+ const result = yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => action.mode === "backup"
580
589
  ? client.auth.twoFactorVerifyBackupCode({
581
590
  payload: verification,
582
591
  })
@@ -697,22 +706,10 @@ const getDefaultAuthRedirectTarget = (_projectAuthDomain, _projectRootDomain) =>
697
706
  };
698
707
  const getSearchParam = (searchString, key) => new URLSearchParams(searchString).get(key);
699
708
  const getBrowserAuthHost = () => globalThis.window?.location.host ?? null;
700
- const navigateTarget = (target, navigate) => {
701
- if (shouldUseDocumentRedirect(target)) {
702
- navigate({ href: target });
703
- }
704
- else {
705
- navigate({ to: target });
706
- }
707
- };
708
- const shouldUseDocumentRedirect = (target) => {
709
- if (target.startsWith("/api/"))
710
- return true;
711
- if (target.startsWith("/"))
712
- return false;
713
- if (target.startsWith(window.location.origin))
714
- return true;
715
- return target.startsWith("http://") || target.startsWith("https://");
709
+ export const navigateTarget = (target, navigate) => {
710
+ // Return destinations are complete URLs, including any search and hash.
711
+ // API callbacks must reach the server rather than the client route tree.
712
+ return navigate({ href: target, reloadDocument: target.startsWith("/api/") });
716
713
  };
717
714
  const nameFromEmail = (email) => {
718
715
  const trimmed = email.trim();
@@ -17,10 +17,7 @@ export type KrakstackAuthContextValue = {
17
17
  projectConfig: ExtraProjectPublicConfig | null;
18
18
  access: ProjectAccessCatalog | null;
19
19
  accessLabels: ProjectAccessLabelCatalog | null;
20
- authRefreshVersion: number;
21
- refreshAuth: () => void;
22
20
  };
23
- export declare const listenForSessionRevalidation: (target: EventTarget, revalidate: () => void) => () => void;
24
21
  export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, access, accessLabels, }: KrakstackAuthProviderProps): import("react").JSX.Element;
25
22
  export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
26
23
  export declare const useKrakstackAuthProjectConfig: () => {