@krak-stack/auth 0.1.44 → 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/README.md CHANGED
@@ -66,7 +66,15 @@ The extra subpath also exports `ExtraApiClient` for Atom-based browser state.
66
66
 
67
67
  ```tsx
68
68
  import { OrganizationSwitcher, UserButton } from "@krak-stack/auth";
69
-
70
- <OrganizationSwitcher side="bottom" />
69
+ import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
70
+
71
+ <OrganizationSwitcher
72
+ menuActions={
73
+ <DropdownMenuItem render={<a href="/organization" />}>
74
+ Dashboard
75
+ </DropdownMenuItem>
76
+ }
77
+ side="bottom"
78
+ />
71
79
  <UserButton signOutRedirect="/" side="bottom" />
72
80
  ```
@@ -143,19 +143,19 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
143
143
  }>>, Schema.String, never, never>, never, never>>;
144
144
  readonly projectId: Schema.optional<Schema.String>;
145
145
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
146
- readonly data: Schema.$Array<Schema.Schema<Schema.Struct.ReadonlySide<{
147
- readonly id: Schema.String;
148
- readonly name: Schema.String;
149
- readonly email: Schema.String;
150
- readonly emailVerified: Schema.Boolean;
151
- readonly image: Schema.NullOr<Schema.String>;
152
- readonly createdAt: Schema.Date;
153
- readonly lastSignedIn: Schema.NullOr<Schema.Date>;
154
- readonly role: Schema.NullOr<Schema.String>;
155
- readonly banned: Schema.NullOr<Schema.Boolean>;
156
- readonly banReason: Schema.NullOr<Schema.String>;
157
- readonly banExpires: Schema.NullOr<Schema.Date>;
158
- }, "Type">>>;
146
+ readonly data: Schema.$Array<Schema.Schema<{
147
+ readonly id: string;
148
+ readonly name: string;
149
+ readonly email: string;
150
+ readonly emailVerified: boolean;
151
+ readonly image: string | null;
152
+ readonly createdAt: Date;
153
+ readonly lastSignedIn: Date | null;
154
+ readonly role: string | null;
155
+ readonly banned: boolean | null;
156
+ readonly banReason: string | null;
157
+ readonly banExpires: Date | null;
158
+ }>>;
159
159
  readonly meta: Schema.Struct<{
160
160
  readonly page: Schema.Int;
161
161
  readonly pageSize: Schema.Int;
@@ -86,19 +86,19 @@ export declare const DashboardStatsResponse: Schema.Struct<{
86
86
  }>>;
87
87
  }>;
88
88
  export declare const PaginatedAdminUsers: Schema.Struct<{
89
- readonly data: Schema.$Array<Schema.Schema<Schema.Struct.ReadonlySide<{
90
- readonly id: Schema.String;
91
- readonly name: Schema.String;
92
- readonly email: Schema.String;
93
- readonly emailVerified: Schema.Boolean;
94
- readonly image: Schema.NullOr<Schema.String>;
95
- readonly createdAt: Schema.Date;
96
- readonly lastSignedIn: Schema.NullOr<Schema.Date>;
97
- readonly role: Schema.NullOr<Schema.String>;
98
- readonly banned: Schema.NullOr<Schema.Boolean>;
99
- readonly banReason: Schema.NullOr<Schema.String>;
100
- readonly banExpires: Schema.NullOr<Schema.Date>;
101
- }, "Type">>>;
89
+ readonly data: Schema.$Array<Schema.Schema<{
90
+ readonly id: string;
91
+ readonly name: string;
92
+ readonly email: string;
93
+ readonly emailVerified: boolean;
94
+ readonly image: string | null;
95
+ readonly createdAt: Date;
96
+ readonly lastSignedIn: Date | null;
97
+ readonly role: string | null;
98
+ readonly banned: boolean | null;
99
+ readonly banReason: string | null;
100
+ readonly banExpires: Date | null;
101
+ }>>;
102
102
  readonly meta: Schema.Struct<{
103
103
  readonly page: Schema.Int;
104
104
  readonly pageSize: Schema.Int;
package/dist/api.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare const AuthServiceApi: HttpApi.HttpApi<"AuthServiceApi", import("e
10
10
  readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
11
11
  readonly userId: import("effect/Schema").String;
12
12
  readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
13
+ readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
13
14
  readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
14
15
  }>;
15
16
  readonly user: import("effect/Schema").Struct<{
@@ -24,7 +25,38 @@ export declare const AuthServiceApi: HttpApi.HttpApi<"AuthServiceApi", import("e
24
25
  readonly createdAt: import("effect/Schema").Date;
25
26
  readonly updatedAt: import("effect/Schema").Date;
26
27
  }>;
27
- }>>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").BadRequest | typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./better-auth/schema").TooManyRequests>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"authExtra", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"createApiKey", "POST", "/api/auth/create-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
28
+ }>>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").BadRequest | typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./better-auth/schema").TooManyRequests>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"organizationImpersonateUser", "POST", "/api/auth/organization/impersonate-user", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
29
+ readonly organizationId: import("effect/Schema").NonEmptyString;
30
+ readonly actorUserId: import("effect/Schema").NonEmptyString;
31
+ readonly targetUserId: import("effect/Schema").NonEmptyString;
32
+ readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Number>;
33
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
34
+ readonly session: import("effect/Schema").Struct<{
35
+ readonly id: import("effect/Schema").String;
36
+ readonly expiresAt: import("effect/Schema").Date;
37
+ readonly token: import("effect/Schema").String;
38
+ readonly createdAt: import("effect/Schema").Date;
39
+ readonly updatedAt: import("effect/Schema").Date;
40
+ readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
41
+ readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
42
+ readonly userId: import("effect/Schema").String;
43
+ readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
44
+ readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
45
+ readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
46
+ }>;
47
+ readonly user: import("effect/Schema").Struct<{
48
+ readonly id: import("effect/Schema").String;
49
+ readonly name: import("effect/Schema").String;
50
+ readonly email: import("effect/Schema").String;
51
+ readonly emailVerified: import("effect/Schema").Boolean;
52
+ readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
53
+ readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
54
+ readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
55
+ readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
56
+ readonly createdAt: import("effect/Schema").Date;
57
+ readonly updatedAt: import("effect/Schema").Date;
58
+ }>;
59
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").BadRequest | typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"authExtra", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"createApiKey", "POST", "/api/auth/create-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
28
60
  readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
29
61
  readonly name: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
30
62
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -424,19 +456,19 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
424
456
  }>>, import("effect/Schema").String, never, never>, never, never>>;
425
457
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
426
458
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
427
- readonly data: import("effect/Schema").$Array<import("effect/Schema").Schema<import("effect/Schema").Struct.ReadonlySide<{
428
- readonly id: import("effect/Schema").String;
429
- readonly name: import("effect/Schema").String;
430
- readonly email: import("effect/Schema").String;
431
- readonly emailVerified: import("effect/Schema").Boolean;
432
- readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
433
- readonly createdAt: import("effect/Schema").Date;
434
- readonly lastSignedIn: import("effect/Schema").NullOr<import("effect/Schema").Date>;
435
- readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
436
- readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
437
- readonly banReason: import("effect/Schema").NullOr<import("effect/Schema").String>;
438
- readonly banExpires: import("effect/Schema").NullOr<import("effect/Schema").Date>;
439
- }, "Type">>>;
459
+ readonly data: import("effect/Schema").$Array<import("effect/Schema").Schema<{
460
+ readonly id: string;
461
+ readonly name: string;
462
+ readonly email: string;
463
+ readonly emailVerified: boolean;
464
+ readonly image: string | null;
465
+ readonly createdAt: Date;
466
+ readonly lastSignedIn: Date | null;
467
+ readonly role: string | null;
468
+ readonly banned: boolean | null;
469
+ readonly banReason: string | null;
470
+ readonly banExpires: Date | null;
471
+ }>>;
440
472
  readonly meta: import("effect/Schema").Struct<{
441
473
  readonly page: import("effect/Schema").Int;
442
474
  readonly pageSize: import("effect/Schema").Int;
@@ -480,7 +512,64 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
480
512
  readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
481
513
  readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
482
514
  readonly createdAt: import("effect/Schema").Date;
483
- }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"authExtra", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"createApiKey", "POST", "/api/auth/create-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
515
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"auth", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getSession", "GET", "/api/auth/get-session", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
516
+ readonly session: import("effect/Schema").Struct<{
517
+ readonly id: import("effect/Schema").String;
518
+ readonly expiresAt: import("effect/Schema").Date;
519
+ readonly token: import("effect/Schema").String;
520
+ readonly createdAt: import("effect/Schema").Date;
521
+ readonly updatedAt: import("effect/Schema").Date;
522
+ readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
523
+ readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
524
+ readonly userId: import("effect/Schema").String;
525
+ readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
526
+ readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
527
+ readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
528
+ }>;
529
+ readonly user: import("effect/Schema").Struct<{
530
+ readonly id: import("effect/Schema").String;
531
+ readonly name: import("effect/Schema").String;
532
+ readonly email: import("effect/Schema").String;
533
+ readonly emailVerified: import("effect/Schema").Boolean;
534
+ readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
535
+ readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
536
+ readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
537
+ readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
538
+ readonly createdAt: import("effect/Schema").Date;
539
+ readonly updatedAt: import("effect/Schema").Date;
540
+ }>;
541
+ }>>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").BadRequest | typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./better-auth/schema").TooManyRequests>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"organizationImpersonateUser", "POST", "/api/auth/organization/impersonate-user", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
542
+ readonly organizationId: import("effect/Schema").NonEmptyString;
543
+ readonly actorUserId: import("effect/Schema").NonEmptyString;
544
+ readonly targetUserId: import("effect/Schema").NonEmptyString;
545
+ readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Number>;
546
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
547
+ readonly session: import("effect/Schema").Struct<{
548
+ readonly id: import("effect/Schema").String;
549
+ readonly expiresAt: import("effect/Schema").Date;
550
+ readonly token: import("effect/Schema").String;
551
+ readonly createdAt: import("effect/Schema").Date;
552
+ readonly updatedAt: import("effect/Schema").Date;
553
+ readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
554
+ readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
555
+ readonly userId: import("effect/Schema").String;
556
+ readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
557
+ readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
558
+ readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
559
+ }>;
560
+ readonly user: import("effect/Schema").Struct<{
561
+ readonly id: import("effect/Schema").String;
562
+ readonly name: import("effect/Schema").String;
563
+ readonly email: import("effect/Schema").String;
564
+ readonly emailVerified: import("effect/Schema").Boolean;
565
+ readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
566
+ readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
567
+ readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
568
+ readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
569
+ readonly createdAt: import("effect/Schema").Date;
570
+ readonly updatedAt: import("effect/Schema").Date;
571
+ }>;
572
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").BadRequest | typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"authExtra", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"createApiKey", "POST", "/api/auth/create-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
484
573
  readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
485
574
  readonly name: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
486
575
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
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
  }, {
@@ -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,6 +18,7 @@ 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",
@@ -31,6 +32,8 @@ const defaultMessages = {
31
32
  admin_error_access_required: "Admin access is required.",
32
33
  admin_error_ban: "Unable to ban user.",
33
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.",
34
37
  admin_error_unban: "Unable to unban user.",
35
38
  admin_status_active: "Active",
36
39
  admin_status_banned: "Banned",
@@ -42,6 +45,7 @@ const defaultMessages = {
42
45
  fr: {
43
46
  admin_action_ban: "Bannir",
44
47
  admin_action_impersonate: "Emprunter l'identité",
48
+ admin_action_impersonate_organization: "Emprunter l'identité pour l'organisation",
45
49
  admin_action_unban: "Débannir",
46
50
  admin_ban_description: "Êtes-vous sûr de vouloir bannir {name} ({email}) ? Il ne pourra plus se connecter.",
47
51
  admin_ban_title: "Bannir l'utilisateur",
@@ -55,6 +59,8 @@ const defaultMessages = {
55
59
  admin_error_access_required: "Accès administrateur requis.",
56
60
  admin_error_ban: "Impossible de bannir l'utilisateur.",
57
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.",
58
64
  admin_error_unban: "Impossible de débannir l'utilisateur.",
59
65
  admin_status_active: "Actif",
60
66
  admin_status_banned: "Banni",
@@ -108,12 +114,22 @@ const impersonateUser = async (authClient, userId, m) => {
108
114
  if (result.error)
109
115
  throw new Error(result.error.message ?? m.admin_error_impersonate);
110
116
  };
117
+ const activeOrganizationId = (session) => {
118
+ const value = session?.session?.activeOrganizationId;
119
+ return typeof value === "string" && value ? value : null;
120
+ };
111
121
  export function AdminUsersTable({ from, reloadKey = 0, search, }) {
112
122
  const navigate = useNavigate();
123
+ const router = useRouter();
113
124
  const auth = useKrakstackAuth();
114
125
  const m = labels(auth?.locale ?? "en");
115
126
  const authClient = auth?.authClient;
116
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" });
117
133
  const projectId = auth?.projectId;
118
134
  const [impersonatingUserId, setImpersonatingUserId] = useState(null);
119
135
  const [impersonateError, setImpersonateError] = useState("");
@@ -150,6 +166,12 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
150
166
  onFailure: () => false,
151
167
  onSuccess: () => false,
152
168
  });
169
+ const refreshSessionAndNavigate = async () => {
170
+ auth?.refreshAuth();
171
+ await refetchSession();
172
+ await navigate({ to: "/" });
173
+ await router.invalidate();
174
+ };
153
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
154
176
  ? {
155
177
  search: tableSearch,
@@ -167,7 +189,7 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
167
189
  if (!authClient)
168
190
  throw new Error(m.admin_error_access_required);
169
191
  await impersonateUser(authClient, user.id, m);
170
- await navigate({ to: "/" });
192
+ await refreshSessionAndNavigate();
171
193
  }
172
194
  catch (cause) {
173
195
  setImpersonateError(cause instanceof Error
@@ -180,6 +202,40 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
180
202
  },
181
203
  visible: (user) => !user.banned,
182
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
+ },
183
239
  {
184
240
  name: m.admin_action_ban,
185
241
  icon: _jsx(Ban, { className: "size-4" }),