@krak-stack/auth 0.2.10 → 0.2.12

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
@@ -114,7 +114,7 @@ export declare const AuthServiceApi: HttpApi.HttpApi<"AuthServiceApi", import("e
114
114
  readonly createdAt: import("effect/Schema").DateFromString;
115
115
  readonly updatedAt: import("effect/Schema").DateFromString;
116
116
  }>;
117
- }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
117
+ }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
118
118
  readonly session: import("effect/Schema").Struct<{
119
119
  readonly id: import("effect/Schema").String;
120
120
  readonly expiresAt: import("effect/Schema").DateFromString;
@@ -2440,7 +2440,7 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
2440
2440
  readonly createdAt: import("effect/Schema").DateFromString;
2441
2441
  readonly updatedAt: import("effect/Schema").DateFromString;
2442
2442
  }>;
2443
- }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2443
+ }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2444
2444
  readonly session: import("effect/Schema").Struct<{
2445
2445
  readonly id: import("effect/Schema").String;
2446
2446
  readonly expiresAt: import("effect/Schema").DateFromString;
@@ -117,7 +117,7 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
117
117
  readonly createdAt: Schema.DateFromString;
118
118
  readonly updatedAt: Schema.DateFromString;
119
119
  }>;
120
- }>>, Schema.toCodecJson<typeof AuthBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"adminStopImpersonating", "POST", "/admin/stop-impersonating", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
120
+ }>>, Schema.toCodecJson<typeof AuthBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"adminStopImpersonating", "POST", "/admin/stop-impersonating", never, never, Schema.toCodecJson<Schema.Struct<{}>>, never, Schema.toCodecJson<Schema.Struct<{
121
121
  readonly session: Schema.Struct<{
122
122
  readonly id: Schema.String;
123
123
  readonly expiresAt: Schema.DateFromString;
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { HttpApiEndpoint, HttpApiGroup, OpenApi, } from "effect/unstable/httpapi";
3
- import { AdminBanUserPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
3
+ import { AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
4
4
  export * from "./schema.js";
5
5
  const errors = [
6
6
  AuthBadRequest,
@@ -218,6 +218,7 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
218
218
  error: errors,
219
219
  }).annotateMerge(docs("Impersonate user", "Starts a user impersonation session.")))
220
220
  .add(HttpApiEndpoint.post("adminStopImpersonating", "/admin/stop-impersonating", {
221
+ payload: AdminStopImpersonatingPayload,
221
222
  success: AuthSessionResponse,
222
223
  error: errors,
223
224
  }).annotateMerge(docs("Stop impersonating", "Restores the administrator session.")))
@@ -1176,6 +1176,7 @@ export declare const DeleteApiKeyPayload: Schema.Struct<{
1176
1176
  export declare const AdminUserIdPayload: Schema.Struct<{
1177
1177
  readonly userId: Schema.String;
1178
1178
  }>;
1179
+ export declare const AdminStopImpersonatingPayload: Schema.Struct<{}>;
1179
1180
  export declare const AdminBanUserPayload: Schema.Struct<{
1180
1181
  readonly userId: Schema.String;
1181
1182
  readonly banReason: Schema.optional<Schema.String>;
@@ -602,6 +602,10 @@ export const AdminUserIdPayload = Schema.Struct({
602
602
  identifier: "AdminUserIdPayload",
603
603
  title: "Admin user ID payload",
604
604
  });
605
+ export const AdminStopImpersonatingPayload = Schema.Struct({}).annotate({
606
+ identifier: "AdminStopImpersonatingPayload",
607
+ title: "Stop impersonating payload",
608
+ });
605
609
  export const AdminBanUserPayload = Schema.Struct({
606
610
  userId: Schema.String,
607
611
  banReason: Schema.optional(Schema.String),
@@ -1,18 +1,21 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useAtomSet, useAtomSubscribe, useAtomValue } from "@effect/atom-react";
3
+ import { useNavigate, useRouter } from "@tanstack/react-router";
3
4
  import { Cause, Effect, Schema } from "effect";
4
5
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
5
- import { Building2, Pencil, Trash2 } from "lucide-react";
6
+ import { Building2, Pencil, Trash2, UserCog } from "lucide-react";
6
7
  import { useState } from "react";
7
8
  import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
8
9
  import { SortParamsFromString, } from "@krak-stack/registry/query";
9
10
  import { ErrorMessage } from "@krak-stack/registry/effect-form";
10
11
  import { AppBrand } from "@krak-stack/registry/app-brand";
12
+ import * as messages from "@/paraglide/messages";
11
13
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
12
14
  import { AdminOrganizationForm } from "./admin-organization-form.js";
13
15
  import { authClientApi, authHttpClient } from "./auth-client-api.js";
14
16
  import { useKrakstackAuth } from "./auth-provider.js";
15
17
  import { assetUrl, organizationBranding } from "./utils.js";
18
+ import { notifyAuthChange } from "./auth-atoms.js";
16
19
  const defaultMessages = {
17
20
  en: {
18
21
  admin_column_created: "Created",
@@ -103,6 +106,24 @@ export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search,
103
106
  const m = labels(locale);
104
107
  const baseUrl = auth?.baseUrl;
105
108
  const projectId = auth?.projectId;
109
+ const navigate = useNavigate();
110
+ const router = useRouter();
111
+ const [impersonateAtom] = useState(() => authClientApi(baseUrl).runtime.fn(({ userId, organizationId, }) => Effect.gen(function* () {
112
+ const client = yield* authHttpClient(baseUrl);
113
+ yield* client.auth.adminImpersonateUser({ payload: { userId } });
114
+ yield* client.auth
115
+ .organizationSetActive({ payload: { organizationId } })
116
+ .pipe(Effect.tapError(() => client.auth.adminStopImpersonating({ payload: {} })), Effect.ensuring(Effect.sync(notifyAuthChange)));
117
+ yield* Effect.tryPromise({
118
+ try: async () => {
119
+ await navigate({ to: "/" });
120
+ await router.invalidate();
121
+ },
122
+ catch: (cause) => cause instanceof Error ? cause : new Error(String(cause)),
123
+ });
124
+ })));
125
+ const impersonate = useAtomSet(impersonateAtom);
126
+ const impersonateResult = useAtomValue(impersonateAtom);
106
127
  const [refreshKey, setRefreshKey] = useState(0);
107
128
  const [editingOrganization, setEditingOrganization] = useState(null);
108
129
  const [deletingOrganization, setDeletingOrganization] = useState(null);
@@ -132,7 +153,7 @@ export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search,
132
153
  onFailure: () => false,
133
154
  onSuccess: () => false,
134
155
  });
135
- return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columnDefs: organizationColumns(m, locale, baseUrl), rowData: organizations, features: {
156
+ return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, AsyncResult.isFailure(impersonateResult) ? (_jsx(ErrorMessage, { text: messages.organization_impersonate_member_error({}, { locale }) })) : null, _jsx(DataTable, { columnDefs: organizationColumns(m, locale, baseUrl, impersonate, impersonateResult.waiting), rowData: organizations, features: {
136
157
  columnVisibility: true,
137
158
  export: { baseName: "organizations" },
138
159
  gallery: false,
@@ -167,7 +188,7 @@ export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search,
167
188
  setRefreshKey((current) => current + 1);
168
189
  } })) : null] }));
169
190
  }
170
- const organizationColumns = (m, locale, baseUrl) => [
191
+ const organizationColumns = (m, locale, baseUrl, impersonate, isImpersonating) => [
171
192
  {
172
193
  field: "name",
173
194
  headerName: m.admin_column_organization,
@@ -179,7 +200,29 @@ const organizationColumns = (m, locale, baseUrl) => [
179
200
  {
180
201
  field: "memberCount",
181
202
  headerName: m.admin_column_members,
182
- cellRenderer: ({ data }) => (_jsx(OrganizationMembers, { baseUrl: baseUrl, members: data.memberPreviews ?? [], total: data.memberCount ?? 0 })),
203
+ type: "list",
204
+ typeOptions: {
205
+ emptyLabel: "0",
206
+ display: "icon",
207
+ getItems: (row) => (row.memberPreviews ?? []).map((member) => ({
208
+ value: member.id,
209
+ label: member.name,
210
+ imageSrc: assetUrl(member.image, baseUrl),
211
+ })),
212
+ getTotalCount: (row) => row.memberCount ?? 0,
213
+ actionsLabel: m.admin_column_members,
214
+ itemActions: [
215
+ {
216
+ name: messages.organization_impersonate_member({}, { locale }),
217
+ icon: _jsx(UserCog, { className: "size-4" }),
218
+ disabled: () => isImpersonating,
219
+ onClick: ({ item, row }) => {
220
+ if (item.value)
221
+ impersonate({ userId: item.value, organizationId: row.id });
222
+ },
223
+ },
224
+ ],
225
+ },
183
226
  },
184
227
  {
185
228
  field: "projects",
@@ -191,7 +234,7 @@ const organizationColumns = (m, locale, baseUrl) => [
191
234
  value: project.id,
192
235
  icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
193
236
  };
194
- }), variant: "icon" })),
237
+ }), display: "icon" })),
195
238
  },
196
239
  {
197
240
  field: "createdAt",
@@ -205,16 +248,6 @@ const initials = (name) => name
205
248
  .map((part) => part[0])
206
249
  .join("")
207
250
  .toUpperCase();
208
- function OrganizationMembers({ baseUrl, members, total, }) {
209
- return (_jsx(DataTableListSummary, { emptyLabel: "0", items: members.map((member) => {
210
- const image = assetUrl(member.image, baseUrl);
211
- return {
212
- label: member.name,
213
- value: member.id,
214
- icon: image ? (_jsx("img", { alt: "", className: "size-full object-cover", src: image })) : (initials(member.name)),
215
- };
216
- }), totalCount: total, variant: "icon" }));
217
- }
218
251
  function DeleteOrganizationDialog({ baseUrl, labels: m, organization, onClose, onDeleted, }) {
219
252
  const [deleteOrganizationAtom] = useState(() => authClientApi(baseUrl).runtime.fn((id) => Effect.flatMap(authHttpClient(baseUrl), (http) => http.admin.deleteOrganization({ params: { id } }))));
220
253
  const deleteOrganization = useAtomSet(deleteOrganizationAtom);
@@ -305,7 +305,7 @@ const userColumns = (m, baseUrl) => [
305
305
  value: organization.id,
306
306
  icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(organization.name)),
307
307
  };
308
- }), variant: "icon" })),
308
+ }), display: "icon" })),
309
309
  },
310
310
  {
311
311
  field: "projects",
@@ -317,7 +317,7 @@ const userColumns = (m, baseUrl) => [
317
317
  value: project.id,
318
318
  icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
319
319
  };
320
- }), variant: "icon" })),
320
+ }), display: "icon" })),
321
321
  },
322
322
  {
323
323
  field: "emailVerified",
@@ -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;
@@ -529,7 +529,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined) => Effect.Ef
529
529
  readonly updatedAt: import("effect/Schema").DateFromString;
530
530
  }>;
531
531
  }>>, import("effect/Schema").toCodecJson<typeof import("../auth/schema.js").AuthBadRequest>, never, never>, never, never>;
532
- readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
532
+ readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
533
533
  readonly session: import("effect/Schema").Struct<{
534
534
  readonly id: import("effect/Schema").String;
535
535
  readonly expiresAt: import("effect/Schema").DateFromString;
@@ -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}`, {
@@ -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";
@@ -147,9 +147,16 @@ const labels = (locale) => ({
147
147
  });
148
148
  const useAuthFormOptions = ({ baseUrl, locale }) => {
149
149
  const auth = useKrakstackAuth();
150
+ const resolvedLocale = locale ?? auth?.locale ?? "en";
151
+ const localeRef = useRef(resolvedLocale);
152
+ useEffect(() => {
153
+ localeRef.current = resolvedLocale;
154
+ }, [resolvedLocale]);
150
155
  return {
151
156
  baseUrl: baseUrl ?? auth?.baseUrl,
152
- 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),
153
160
  projectConfig: auth?.projectConfig,
154
161
  };
155
162
  };
@@ -206,7 +213,7 @@ export const resolveInitialAuthMethod = ({ requestedMethod, lastLoginMethod, ema
206
213
  return emailOtp ? "emailOtp" : "password";
207
214
  };
208
215
  export function Signin(props) {
209
- const { baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
216
+ const { baseUrl, locale, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
210
217
  const navigate = useNavigate();
211
218
  const searchString = useRouterState({
212
219
  select: (state) => state.location.searchStr,
@@ -265,7 +272,7 @@ export function Signin(props) {
265
272
  mode: { validation: "onSubmit" },
266
273
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
267
274
  const email = value.email.trim();
268
- const sendEmailOtp = authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
275
+ const sendEmailOtp = authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
269
276
  payload: { email, type: "sign-in" },
270
277
  })), Effect.tap(() => Effect.sync(() => {
271
278
  setAuthMethod("emailOtp");
@@ -300,7 +307,7 @@ export function Signin(props) {
300
307
  yield* sendEmailOtp;
301
308
  return;
302
309
  }
303
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.signInEmailOtp({
310
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.signInEmailOtp({
304
311
  payload: {
305
312
  email,
306
313
  otp: value.otp.trim(),
@@ -323,7 +330,7 @@ export function Signin(props) {
323
330
  password: value.password,
324
331
  callbackURL: redirectTarget,
325
332
  };
326
- 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 })));
327
334
  if (hasTwoFactorRedirect(result)) {
328
335
  onTwoFactorRedirect(`/2fa${oauthQuery ? `?${oauthQuery}` : `?callbackURL=${encodeURIComponent(redirectTarget)}`}`);
329
336
  return;
@@ -357,7 +364,7 @@ export function Signin(props) {
357
364
  callbackURL: socialRedirectTarget,
358
365
  errorCallbackURL: "/sign-in",
359
366
  };
360
- 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 })));
361
368
  notifyAuthChange();
362
369
  if (result.url)
363
370
  onNavigate(result.url);
@@ -423,7 +430,7 @@ export function Signin(props) {
423
430
  return;
424
431
  event.preventDefault();
425
432
  event.currentTarget.form?.requestSubmit();
426
- }, 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 }), _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
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
427
434
  ? text(m.sign_in_email_otp_resend_countdown, {
428
435
  seconds: String(emailOtpResendSeconds),
429
436
  })
@@ -434,7 +441,7 @@ export function Signin(props) {
434
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] })] }));
435
442
  }
436
443
  export function VerifyEmail(props) {
437
- const { baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
444
+ const { baseUrl, locale, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
438
445
  const navigate = useNavigate();
439
446
  const searchString = useRouterState({
440
447
  select: (state) => state.location.searchStr,
@@ -449,7 +456,7 @@ export function VerifyEmail(props) {
449
456
  mode: { validation: "onSubmit" },
450
457
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
451
458
  if (action === "resend") {
452
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
459
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.sendVerificationOtp({
453
460
  payload: {
454
461
  email: value.email.trim(),
455
462
  type: "email-verification",
@@ -458,7 +465,7 @@ export function VerifyEmail(props) {
458
465
  setResent(true);
459
466
  return;
460
467
  }
461
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.verifyEmailOtp({
468
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.verifyEmailOtp({
462
469
  payload: {
463
470
  email: value.email.trim(),
464
471
  otp: value.otp.trim(),
@@ -485,7 +492,7 @@ export function VerifyEmail(props) {
485
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 }) })] })] }));
486
493
  }
487
494
  export function ForgotPassword(props) {
488
- const { baseUrl, labels: m } = useAuthFormOptions(props);
495
+ const { baseUrl, locale, labels: m } = useAuthFormOptions(props);
489
496
  const searchString = useRouterState({
490
497
  select: (state) => state.location.searchStr,
491
498
  });
@@ -497,7 +504,7 @@ export function ForgotPassword(props) {
497
504
  mode: { validation: "onSubmit" },
498
505
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
499
506
  setSubmitted(false);
500
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.requestPasswordReset({
507
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.requestPasswordReset({
501
508
  payload: {
502
509
  email: value.email.trim(),
503
510
  redirectTo: `${window.location.origin}/reset-password`,
@@ -522,7 +529,7 @@ export function ResetPassword(props) {
522
529
  return token ? (_jsx(ResetPasswordForm, { ...props, token: token })) : (_jsx(ForgotPassword, { ...props }));
523
530
  }
524
531
  function ResetPasswordForm({ token, ...props }) {
525
- const { baseUrl, labels: m } = useAuthFormOptions(props);
532
+ const { baseUrl, locale, labels: m } = useAuthFormOptions(props);
526
533
  const navigate = useNavigate();
527
534
  const onSuccess = () => navigate({ to: "/sign-in" });
528
535
  const [form] = useState(() => FormReact.make(resetPasswordFormBuilder, {
@@ -530,7 +537,7 @@ function ResetPasswordForm({ token, ...props }) {
530
537
  fields: { password: TextField },
531
538
  mode: { validation: "onSubmit" },
532
539
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
533
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.resetPassword({
540
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.resetPassword({
534
541
  payload: {
535
542
  newPassword: value.password,
536
543
  token,
@@ -548,7 +555,7 @@ function ResetPasswordForm({ token, ...props }) {
548
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] })] }) }) })] }));
549
556
  }
550
557
  export function TwoFactor(props) {
551
- const { baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
558
+ const { baseUrl, locale, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
552
559
  const navigate = useNavigate();
553
560
  const searchString = useRouterState({
554
561
  select: (state) => state.location.searchStr,
@@ -565,7 +572,7 @@ export function TwoFactor(props) {
565
572
  mode: { validation: "onSubmit" },
566
573
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
567
574
  if (action.type === "sendEmailCode") {
568
- yield* authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorSendOtp({ payload: {} })));
575
+ yield* authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => client.auth.twoFactorSendOtp({ payload: {} })));
569
576
  setEmailCodeSent(true);
570
577
  setMode("email");
571
578
  return;
@@ -578,7 +585,7 @@ export function TwoFactor(props) {
578
585
  oauth_query: oauthQuery,
579
586
  }
580
587
  : { code, trustDevice: value.trustDevice };
581
- 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"
582
589
  ? client.auth.twoFactorVerifyBackupCode({
583
590
  payload: verification,
584
591
  })
@@ -5,7 +5,7 @@ import { Effect, Option, Predicate, Schema } from "effect";
5
5
  import { AsyncResult, Atom } from "effect/unstable/reactivity";
6
6
  import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
7
7
  import { createContext, useContext, useEffect, useRef, useState, } from "react";
8
- import { DataTable, DataTableListSummary, DataTableRelationshipCell, } from "@krak-stack/registry/data-table";
8
+ import { DataTable, DataTableListSummary, DataTableListCell, } from "@krak-stack/registry/data-table";
9
9
  import { CheckboxField, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
10
10
  import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
11
11
  import { AppBrand } from "@krak-stack/registry/app-brand";
@@ -1367,10 +1367,10 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
1367
1367
  if (!canChangeRoles) {
1368
1368
  return (_jsx("div", { className: "flex flex-wrap gap-1", children: roleOptions.map((role) => (_jsx(Badge, { variant: "secondary", children: role.label }, role.value))) }));
1369
1369
  }
1370
- return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
1370
+ return (_jsx(DataTableListCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
1371
1371
  label: organizationRoleLabel(role, m),
1372
1372
  value: role,
1373
- })), value: roleOptions, onAdd: (value) => {
1373
+ })), items: roleOptions, onAdd: (value) => {
1374
1374
  if (!isOrganizationRole(value))
1375
1375
  return;
1376
1376
  onRoleChange(member, Array.from(new Set([...roles, value])));
@@ -500,7 +500,7 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
500
500
  const signOutResult = useAtomValue(signOutAction);
501
501
  const [stopImpersonatingAction] = useState(() => authClientApi(resolvedBaseUrl).runtime.fn((input) => Effect.gen(function* () {
502
502
  setIsStoppingImpersonation(true);
503
- yield* authHttpClient(input.baseUrl).pipe(Effect.flatMap((client) => client.auth.adminStopImpersonating()), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.tap(() => Effect.sync(input.refreshSession)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: input.currentSiteHref }))), Effect.ensuring(Effect.sync(() => setIsStoppingImpersonation(false))));
503
+ yield* authHttpClient(input.baseUrl).pipe(Effect.flatMap((client) => client.auth.adminStopImpersonating({ payload: {} })), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.tap(() => Effect.sync(input.refreshSession)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: input.currentSiteHref }))), Effect.ensuring(Effect.sync(() => setIsStoppingImpersonation(false))));
504
504
  })));
505
505
  const stopImpersonating = useAtomSet(stopImpersonatingAction);
506
506
  const stopImpersonatingResult = useAtomValue(stopImpersonatingAction);
package/dist/service.d.ts CHANGED
@@ -158,7 +158,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
158
158
  readonly updatedAt: import("effect/Schema").DateFromString;
159
159
  }>;
160
160
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never>, never, never>;
161
- readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
161
+ readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
162
162
  readonly session: import("effect/Schema").Struct<{
163
163
  readonly id: import("effect/Schema").String;
164
164
  readonly expiresAt: import("effect/Schema").DateFromString;
@@ -2181,7 +2181,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2181
2181
  readonly updatedAt: import("effect/Schema").DateFromString;
2182
2182
  }>;
2183
2183
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never>, never, never>;
2184
- readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2184
+ readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2185
2185
  readonly session: import("effect/Schema").Struct<{
2186
2186
  readonly id: import("effect/Schema").String;
2187
2187
  readonly expiresAt: import("effect/Schema").DateFromString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -76,7 +76,7 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "@effect/atom-react": "4.0.0-rc.112",
79
- "@krak-stack/registry": "^0.1.25",
79
+ "@krak-stack/registry": "^0.1.31",
80
80
  "@lucas-barake/effect-form-react": "^0.26.0-beta.5",
81
81
  "react-qr-code": "^2.2.0"
82
82
  },