@krak-stack/auth 0.1.43 → 0.1.45

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.js CHANGED
@@ -17,5 +17,5 @@ export const AuthClientApi = HttpApi.make("AuthClientApi")
17
17
  version: "1.0.0",
18
18
  description: "Browser-facing API used by KrakStack Auth React components.",
19
19
  }))
20
- .add(ExtraApiGroup, AdminApiGroup.prefix("/auth"))
20
+ .add(BetterAuthApiGroup.prefix("/auth"), ExtraApiGroup, AdminApiGroup.prefix("/auth"))
21
21
  .prefix("/api");
@@ -13,6 +13,7 @@ export declare const BetterAuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpA
13
13
  readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
14
14
  readonly userId: import("effect/Schema").String;
15
15
  readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
16
+ readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
16
17
  readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
17
18
  }>;
18
19
  readonly user: import("effect/Schema").Struct<{
@@ -27,4 +28,35 @@ export declare const BetterAuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpA
27
28
  readonly createdAt: import("effect/Schema").Date;
28
29
  readonly updatedAt: import("effect/Schema").Date;
29
30
  }>;
30
- }>>>, HttpApiEndpoint.Json<typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError | typeof TooManyRequests>, never, never>, false>;
31
+ }>>>, HttpApiEndpoint.Json<typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError | typeof TooManyRequests>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"organizationImpersonateUser", "POST", "/organization/impersonate-user", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
32
+ readonly organizationId: import("effect/Schema").NonEmptyString;
33
+ readonly actorUserId: import("effect/Schema").NonEmptyString;
34
+ readonly targetUserId: import("effect/Schema").NonEmptyString;
35
+ readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Number>;
36
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
37
+ readonly session: import("effect/Schema").Struct<{
38
+ readonly id: import("effect/Schema").String;
39
+ readonly expiresAt: import("effect/Schema").Date;
40
+ readonly token: import("effect/Schema").String;
41
+ readonly createdAt: import("effect/Schema").Date;
42
+ readonly updatedAt: import("effect/Schema").Date;
43
+ readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
44
+ readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
45
+ readonly userId: import("effect/Schema").String;
46
+ readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
47
+ readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
48
+ readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
49
+ }>;
50
+ readonly user: import("effect/Schema").Struct<{
51
+ readonly id: import("effect/Schema").String;
52
+ readonly name: import("effect/Schema").String;
53
+ readonly email: import("effect/Schema").String;
54
+ readonly emailVerified: import("effect/Schema").Boolean;
55
+ readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
56
+ readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
57
+ readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
58
+ readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
59
+ readonly createdAt: import("effect/Schema").Date;
60
+ readonly updatedAt: import("effect/Schema").Date;
61
+ }>;
62
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never>, false>;
@@ -1,6 +1,6 @@
1
1
  import { OpenApi } from "effect/unstable/httpapi";
2
2
  import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
3
- import { GetSessionResponse, TooManyRequests } from "./schema";
3
+ import { GetSessionResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, TooManyRequests, } from "./schema";
4
4
  export * from "./schema";
5
5
  export const BetterAuthApiGroup = HttpApiGroup.make("auth")
6
6
  .add(HttpApiEndpoint.get("getSession", "/get-session", {
@@ -17,6 +17,20 @@ export const BetterAuthApiGroup = HttpApiGroup.make("auth")
17
17
  title: "Get session",
18
18
  summary: "Get current Better Auth session",
19
19
  description: "Auth required. Returns the current Better Auth session and user. This endpoint is implemented directly by Better Auth.",
20
+ })))
21
+ .add(HttpApiEndpoint.post("organizationImpersonateUser", "/organization/impersonate-user", {
22
+ payload: OrganizationImpersonateUserPayload,
23
+ success: OrganizationImpersonateUserResponse,
24
+ error: [
25
+ HttpApiError.BadRequest,
26
+ HttpApiError.Unauthorized,
27
+ HttpApiError.NotFound,
28
+ HttpApiError.InternalServerError,
29
+ ],
30
+ }).annotateMerge(OpenApi.annotations({
31
+ title: "Organization impersonate user",
32
+ summary: "Create an organization impersonation session",
33
+ description: "Service API key and actor session cookie required. Creates a target user session marked with the actor user and impersonating organization. The response includes the Better Auth session Set-Cookie header plus the restore cookie used by /auth/admin/stop-impersonating.",
20
34
  })))
21
35
  .annotateMerge(OpenApi.annotations({
22
36
  title: "Better Auth",
@@ -11,6 +11,7 @@ export declare const GetSessionResponse: Schema.NullOr<Schema.Struct<{
11
11
  readonly userAgent: Schema.optional<Schema.NullOr<Schema.String>>;
12
12
  readonly userId: Schema.String;
13
13
  readonly impersonatedBy: Schema.optional<Schema.NullOr<Schema.String>>;
14
+ readonly impersonatedByOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
14
15
  readonly activeOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
15
16
  }>;
16
17
  readonly user: Schema.Struct<{
@@ -26,6 +27,39 @@ export declare const GetSessionResponse: Schema.NullOr<Schema.Struct<{
26
27
  readonly updatedAt: Schema.Date;
27
28
  }>;
28
29
  }>>;
30
+ export declare const OrganizationImpersonateUserPayload: Schema.Struct<{
31
+ readonly organizationId: Schema.NonEmptyString;
32
+ readonly actorUserId: Schema.NonEmptyString;
33
+ readonly targetUserId: Schema.NonEmptyString;
34
+ readonly expiresInSeconds: Schema.optional<Schema.Number>;
35
+ }>;
36
+ export declare const OrganizationImpersonateUserResponse: Schema.Struct<{
37
+ readonly session: Schema.Struct<{
38
+ readonly id: Schema.String;
39
+ readonly expiresAt: Schema.Date;
40
+ readonly token: Schema.String;
41
+ readonly createdAt: Schema.Date;
42
+ readonly updatedAt: Schema.Date;
43
+ readonly ipAddress: Schema.optional<Schema.NullOr<Schema.String>>;
44
+ readonly userAgent: Schema.optional<Schema.NullOr<Schema.String>>;
45
+ readonly userId: Schema.String;
46
+ readonly impersonatedBy: Schema.optional<Schema.NullOr<Schema.String>>;
47
+ readonly impersonatedByOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
48
+ readonly activeOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
49
+ }>;
50
+ readonly user: Schema.Struct<{
51
+ readonly id: Schema.String;
52
+ readonly name: Schema.String;
53
+ readonly email: Schema.String;
54
+ readonly emailVerified: Schema.Boolean;
55
+ readonly image: Schema.NullOr<Schema.String>;
56
+ readonly role: Schema.NullOr<Schema.String>;
57
+ readonly banned: Schema.NullOr<Schema.Boolean>;
58
+ readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
59
+ readonly createdAt: Schema.Date;
60
+ readonly updatedAt: Schema.Date;
61
+ }>;
62
+ }>;
29
63
  declare const TooManyRequests_base: Schema.Class<TooManyRequests, Schema.Struct<{
30
64
  readonly _tag: Schema.tag<"TooManyRequests">;
31
65
  }>, import("effect/Cause").YieldableError>;
@@ -33,4 +67,6 @@ export declare class TooManyRequests extends TooManyRequests_base {
33
67
  }
34
68
  export type GetSessionResponse = typeof GetSessionResponse.Type;
35
69
  export type GetSessionPayload = typeof GetSessionPayload.Type;
70
+ export type OrganizationImpersonateUserPayload = typeof OrganizationImpersonateUserPayload.Type;
71
+ export type OrganizationImpersonateUserResponse = typeof OrganizationImpersonateUserResponse.Type;
36
72
  export {};
@@ -25,6 +25,7 @@ export const GetSessionResponse = Schema.NullOr(Schema.Struct({
25
25
  userAgent: "Mozilla/5.0",
26
26
  userId: "user_1",
27
27
  impersonatedBy: null,
28
+ impersonatedByOrganizationId: null,
28
29
  activeOrganizationId: "org_1",
29
30
  },
30
31
  user: {
@@ -43,6 +44,61 @@ export const GetSessionResponse = Schema.NullOr(Schema.Struct({
43
44
  null,
44
45
  ],
45
46
  });
47
+ export const OrganizationImpersonateUserPayload = Schema.Struct({
48
+ organizationId: Schema.NonEmptyString,
49
+ actorUserId: Schema.NonEmptyString,
50
+ targetUserId: Schema.NonEmptyString,
51
+ expiresInSeconds: Schema.optional(Schema.Number),
52
+ }).annotate({
53
+ identifier: "OrganizationImpersonateUserPayload",
54
+ title: "Organization impersonate user payload",
55
+ description: "Server-to-server payload for creating an organization-scoped impersonation session. The request must include a service API key and the actor's current Better Auth session cookie.",
56
+ examples: [
57
+ {
58
+ organizationId: "org_1",
59
+ actorUserId: "user_admin",
60
+ targetUserId: "user_learner",
61
+ expiresInSeconds: 3600,
62
+ },
63
+ ],
64
+ });
65
+ export const OrganizationImpersonateUserResponse = Schema.Struct({
66
+ session: Session,
67
+ user: User,
68
+ }).annotate({
69
+ identifier: "OrganizationImpersonateUserResponse",
70
+ title: "Organization impersonate user response",
71
+ description: "Created Better Auth session and target user. The HTTP response also includes the impersonation session Set-Cookie header and restore cookie for /auth/admin/stop-impersonating.",
72
+ examples: [
73
+ {
74
+ session: {
75
+ id: "session_1",
76
+ expiresAt: new Date("2026-01-01T01:00:00.000Z"),
77
+ token: "session-token",
78
+ createdAt: new Date("2026-01-01T00:00:00.000Z"),
79
+ updatedAt: new Date("2026-01-01T00:00:00.000Z"),
80
+ ipAddress: "127.0.0.1",
81
+ userAgent: "Kokobi/1.0",
82
+ userId: "user_learner",
83
+ impersonatedBy: "user_admin",
84
+ impersonatedByOrganizationId: "org_1",
85
+ activeOrganizationId: "org_1",
86
+ },
87
+ user: {
88
+ id: "user_learner",
89
+ name: "Grace Hopper",
90
+ email: "grace@example.com",
91
+ emailVerified: true,
92
+ image: null,
93
+ role: null,
94
+ banned: false,
95
+ lastLoginMethod: null,
96
+ createdAt: new Date("2026-01-01T00:00:00.000Z"),
97
+ updatedAt: new Date("2026-01-01T00:00:00.000Z"),
98
+ },
99
+ },
100
+ ],
101
+ });
46
102
  export class TooManyRequests extends Schema.ErrorClass("TooManyRequests")({
47
103
  _tag: Schema.tag("TooManyRequests"),
48
104
  }, {
@@ -3,5 +3,5 @@ import { type TableParams } from "@/components/ui/data-table";
3
3
  export declare function AdminOrganizationsTable({ from, reloadKey, search, }: {
4
4
  from?: ValidateFromPath;
5
5
  reloadKey?: number;
6
- search: TableParams;
6
+ search?: TableParams;
7
7
  }): import("react").JSX.Element;
@@ -8,26 +8,21 @@ import { useState } from "react";
8
8
  import { DataTable } from "@/components/ui/data-table";
9
9
  import { ErrorMessage } from "@/components/ui/form";
10
10
  import { AppBrand } from "@/components/ui/app-brand";
11
- import { Badge } from "@/components/ui/badge";
12
11
  import { authClientApi } from "./auth-client-api";
13
12
  import { useKrakstackAuth } from "./auth-provider";
14
13
  import { assetUrl, organizationBranding } from "./utils";
15
14
  const defaultMessages = {
16
15
  en: {
17
16
  admin_column_created: "Created",
17
+ admin_column_members: "Members",
18
18
  admin_column_organization: "Organization",
19
- admin_none: "None",
20
- oauth_client_logo_configured: "Configured",
21
19
  organization_fetch_error: "Unable to load organizations.",
22
- organization_field_logo_url: "Logo",
23
20
  },
24
21
  fr: {
25
22
  admin_column_created: "Créé",
23
+ admin_column_members: "Membres",
26
24
  admin_column_organization: "Organisation",
27
- admin_none: "Aucun",
28
- oauth_client_logo_configured: "Configuré",
29
25
  organization_fetch_error: "Impossible de charger les organisations.",
30
- organization_field_logo_url: "Logo",
31
26
  },
32
27
  };
33
28
  const labels = (locale) => ({
@@ -72,11 +67,15 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
72
67
  const baseUrl = auth?.baseUrl;
73
68
  const projectId = auth?.projectId;
74
69
  const [refreshKey, setRefreshKey] = useState(0);
70
+ const [localSearch, setLocalSearch] = useState({
71
+ globalFilter: "",
72
+ });
73
+ const tableSearch = search ?? localSearch;
75
74
  const result = useAtomValue(organizationsAtom({
76
75
  baseUrl,
77
76
  projectId,
78
77
  reloadKey: reloadKey + refreshKey,
79
- search,
78
+ search: tableSearch,
80
79
  }));
81
80
  const organizations = AsyncResult.match(result, {
82
81
  onInitial: () => [],
@@ -98,7 +97,13 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
98
97
  onFailure: () => false,
99
98
  onSuccess: () => false,
100
99
  });
101
- return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations, exportFileName: "organizations.csv", features: { gallery: false }, ...(from ? { from } : {}), isLoading: isLoading, onRefresh: () => setRefreshKey((current) => current + 1), serverPagination: { rowCount: total } })] }));
100
+ return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations, exportFileName: "organizations.csv", features: { gallery: false }, ...(from ? { from } : {}), ...(!search
101
+ ? {
102
+ search: tableSearch,
103
+ onSearchChange: setLocalSearch,
104
+ searchState: "local",
105
+ }
106
+ : {}), isLoading: isLoading, onRefresh: () => setRefreshKey((current) => current + 1), serverPagination: { rowCount: total } })] }));
102
107
  }
103
108
  const organizationColumns = (m, locale, baseUrl) => [
104
109
  {
@@ -110,9 +115,9 @@ const organizationColumns = (m, locale, baseUrl) => [
110
115
  },
111
116
  },
112
117
  {
113
- accessorKey: "logo",
114
- header: m.organization_field_logo_url,
115
- cell: ({ row }) => row.original.logo ? (_jsx(Badge, { variant: "outline", children: m.oauth_client_logo_configured })) : (_jsx("span", { className: "text-muted-foreground text-sm", children: m.admin_none })),
118
+ accessorKey: "memberCount",
119
+ header: m.admin_column_members,
120
+ cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm tabular-nums", children: (row.original.memberCount ?? 0).toLocaleString() })),
116
121
  },
117
122
  {
118
123
  accessorKey: "createdAt",
@@ -3,6 +3,6 @@ import { type TableParams } from "@/components/ui/data-table";
3
3
  export declare function AdminUsersTable({ from, reloadKey, search, }: {
4
4
  from?: ValidateFromPath;
5
5
  reloadKey?: number;
6
- search: TableParams;
6
+ search?: TableParams;
7
7
  }): import("react").JSX.Element;
8
8
  export declare function useAdminUsersTotal(search: TableParams): number;
@@ -1,10 +1,10 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // @ts-nocheck
3
- import { useAtomValue } from "@effect/atom-react";
4
- import { useNavigate } from "@tanstack/react-router";
3
+ import { useAtomSet, useAtomValue } from "@effect/atom-react";
4
+ import { useNavigate, useRouter, } from "@tanstack/react-router";
5
5
  import {} from "@tanstack/react-table";
6
6
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
7
- import { Ban, Loader2, ShieldOff, UserCog, UserIcon } from "lucide-react";
7
+ import { Ban, Building2, Loader2, ShieldOff, UserCog, UserIcon, } from "lucide-react";
8
8
  import { useState } from "react";
9
9
  import { DataTable } from "@/components/ui/data-table";
10
10
  import { ErrorMessage } from "@/components/ui/form";
@@ -18,10 +18,12 @@ const defaultMessages = {
18
18
  en: {
19
19
  admin_action_ban: "Ban",
20
20
  admin_action_impersonate: "Impersonate",
21
+ admin_action_impersonate_organization: "Impersonate as organization",
21
22
  admin_action_unban: "Unban",
22
23
  admin_ban_description: "Are you sure you want to ban {name} ({email})? They will not be able to sign in.",
23
24
  admin_ban_title: "Ban user",
24
25
  admin_column_created: "Created",
26
+ admin_column_last_signed_in: "Last signed in",
25
27
  admin_column_role: "Role",
26
28
  admin_column_status: "Status",
27
29
  admin_column_unverified: "Unverified",
@@ -30,6 +32,8 @@ const defaultMessages = {
30
32
  admin_error_access_required: "Admin access is required.",
31
33
  admin_error_ban: "Unable to ban user.",
32
34
  admin_error_impersonate: "Unable to impersonate user.",
35
+ admin_error_impersonate_organization: "Unable to impersonate user as organization.",
36
+ admin_error_organization_required: "Select an active organization first.",
33
37
  admin_error_unban: "Unable to unban user.",
34
38
  admin_status_active: "Active",
35
39
  admin_status_banned: "Banned",
@@ -41,10 +45,12 @@ const defaultMessages = {
41
45
  fr: {
42
46
  admin_action_ban: "Bannir",
43
47
  admin_action_impersonate: "Emprunter l'identité",
48
+ admin_action_impersonate_organization: "Emprunter l'identité pour l'organisation",
44
49
  admin_action_unban: "Débannir",
45
50
  admin_ban_description: "Êtes-vous sûr de vouloir bannir {name} ({email}) ? Il ne pourra plus se connecter.",
46
51
  admin_ban_title: "Bannir l'utilisateur",
47
52
  admin_column_created: "Créé",
53
+ admin_column_last_signed_in: "Dernière connexion",
48
54
  admin_column_role: "Rôle",
49
55
  admin_column_status: "Statut",
50
56
  admin_column_unverified: "Non vérifié",
@@ -53,6 +59,8 @@ const defaultMessages = {
53
59
  admin_error_access_required: "Accès administrateur requis.",
54
60
  admin_error_ban: "Impossible de bannir l'utilisateur.",
55
61
  admin_error_impersonate: "Impossible d'emprunter l'identité de l'utilisateur.",
62
+ admin_error_impersonate_organization: "Impossible d'emprunter l'identité pour l'organisation.",
63
+ admin_error_organization_required: "Sélectionnez d'abord une organisation active.",
56
64
  admin_error_unban: "Impossible de débannir l'utilisateur.",
57
65
  admin_status_active: "Actif",
58
66
  admin_status_banned: "Banni",
@@ -106,20 +114,34 @@ const impersonateUser = async (authClient, userId, m) => {
106
114
  if (result.error)
107
115
  throw new Error(result.error.message ?? m.admin_error_impersonate);
108
116
  };
117
+ const activeOrganizationId = (session) => {
118
+ const value = session?.session?.activeOrganizationId;
119
+ return typeof value === "string" && value ? value : null;
120
+ };
109
121
  export function AdminUsersTable({ from, reloadKey = 0, search, }) {
110
122
  const navigate = useNavigate();
123
+ const router = useRouter();
111
124
  const auth = useKrakstackAuth();
112
125
  const m = labels(auth?.locale ?? "en");
113
126
  const authClient = auth?.authClient;
114
127
  const baseUrl = auth?.baseUrl;
128
+ const { data: session, refetch: refetchSession } = authClient?.useSession() ?? {
129
+ data: null,
130
+ refetch: async () => undefined,
131
+ };
132
+ const impersonateOrganizationUser = useAtomSet(authClientApi(baseUrl).mutation("auth", "organizationImpersonateUser"), { mode: "promise" });
115
133
  const projectId = auth?.projectId;
116
134
  const [impersonatingUserId, setImpersonatingUserId] = useState(null);
117
135
  const [impersonateError, setImpersonateError] = useState("");
118
136
  const [refreshKey, setRefreshKey] = useState(0);
137
+ const [localSearch, setLocalSearch] = useState({
138
+ globalFilter: "",
139
+ });
140
+ const tableSearch = search ?? localSearch;
119
141
  const result = useAtomValue(usersAtom({
120
142
  baseUrl,
121
143
  projectId,
122
- search,
144
+ search: tableSearch,
123
145
  reloadKey: reloadKey + refreshKey,
124
146
  }));
125
147
  const [banningUser, setBanningUser] = useState(null);
@@ -144,7 +166,19 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
144
166
  onFailure: () => false,
145
167
  onSuccess: () => false,
146
168
  });
147
- return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m), data: users, exportFileName: "users.csv", features: { gallery: false }, ...(from ? { from } : {}), isLoading: isLoading, onRefresh: () => setRefreshKey((current) => current + 1), serverPagination: { rowCount: total }, rowActions: [
169
+ const refreshSessionAndNavigate = async () => {
170
+ auth?.refreshAuth();
171
+ await refetchSession();
172
+ await navigate({ to: "/" });
173
+ await router.invalidate();
174
+ };
175
+ return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m), data: users, exportFileName: "users.csv", features: { gallery: false }, ...(from ? { from } : {}), ...(!search
176
+ ? {
177
+ search: tableSearch,
178
+ onSearchChange: setLocalSearch,
179
+ searchState: "local",
180
+ }
181
+ : {}), isLoading: isLoading, onRefresh: () => setRefreshKey((current) => current + 1), serverPagination: { rowCount: total }, rowActions: [
148
182
  {
149
183
  name: m.admin_action_impersonate,
150
184
  icon: impersonatingUserId ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(UserCog, { className: "size-4" })),
@@ -155,7 +189,7 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
155
189
  if (!authClient)
156
190
  throw new Error(m.admin_error_access_required);
157
191
  await impersonateUser(authClient, user.id, m);
158
- await navigate({ to: "/" });
192
+ await refreshSessionAndNavigate();
159
193
  }
160
194
  catch (cause) {
161
195
  setImpersonateError(cause instanceof Error
@@ -168,6 +202,40 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
168
202
  },
169
203
  visible: (user) => !user.banned,
170
204
  },
205
+ {
206
+ name: m.admin_action_impersonate_organization,
207
+ icon: impersonatingUserId ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Building2, { className: "size-4" })),
208
+ onClick: async (user) => {
209
+ setImpersonateError("");
210
+ setImpersonatingUserId(user.id);
211
+ try {
212
+ if (!session?.user?.id) {
213
+ throw new Error(m.admin_error_access_required);
214
+ }
215
+ const organizationId = activeOrganizationId(session);
216
+ if (!organizationId) {
217
+ throw new Error(m.admin_error_organization_required);
218
+ }
219
+ await impersonateOrganizationUser({
220
+ payload: {
221
+ organizationId,
222
+ actorUserId: session.user.id,
223
+ targetUserId: user.id,
224
+ },
225
+ });
226
+ await refreshSessionAndNavigate();
227
+ }
228
+ catch (cause) {
229
+ setImpersonateError(cause instanceof Error
230
+ ? cause.message
231
+ : m.admin_error_impersonate_organization);
232
+ }
233
+ finally {
234
+ setImpersonatingUserId(null);
235
+ }
236
+ },
237
+ visible: (user) => !user.banned,
238
+ },
171
239
  {
172
240
  name: m.admin_action_ban,
173
241
  icon: _jsx(Ban, { className: "size-4" }),
@@ -226,6 +294,13 @@ const userColumns = (m) => [
226
294
  header: m.admin_column_status,
227
295
  cell: ({ row }) => row.original.banned ? (_jsx(Badge, { variant: "destructive", children: m.admin_status_banned })) : (_jsx(Badge, { variant: "outline", children: m.admin_status_active })),
228
296
  },
297
+ {
298
+ accessorKey: "lastSignedIn",
299
+ header: m.admin_column_last_signed_in,
300
+ cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: row.original.lastSignedIn
301
+ ? new Date(row.original.lastSignedIn).toLocaleString()
302
+ : "-" })),
303
+ },
229
304
  {
230
305
  accessorKey: "createdAt",
231
306
  header: m.admin_column_created,