@krak-stack/auth 0.1.71 → 0.2.0

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.
Files changed (73) hide show
  1. package/README.md +4 -3
  2. package/dist/access.d.ts +4 -4
  3. package/dist/access.js +10 -4
  4. package/dist/admin/api.group.d.ts +17 -17
  5. package/dist/admin/api.group.js +2 -2
  6. package/dist/admin/schema.d.ts +18 -18
  7. package/dist/admin/schema.js +3 -3
  8. package/dist/api.d.ts +2093 -631
  9. package/dist/api.js +7 -7
  10. package/dist/auth/api.group.d.ts +793 -0
  11. package/dist/auth/api.group.js +241 -0
  12. package/dist/auth/schema.d.ts +800 -0
  13. package/dist/auth/schema.js +625 -0
  14. package/dist/components/admin-organization-form.d.ts +1 -1
  15. package/dist/components/admin-organization-form.js +16 -18
  16. package/dist/components/admin-organizations.js +52 -45
  17. package/dist/components/admin-users.js +115 -137
  18. package/dist/components/api-key-edit-form.d.ts +4 -3
  19. package/dist/components/api-key-edit-form.js +32 -27
  20. package/dist/components/api-key-permissions.d.ts +1 -1
  21. package/dist/components/api-key-rate-limit.d.ts +1 -1
  22. package/dist/components/api-key-referrers.d.ts +3 -2
  23. package/dist/components/api-key-referrers.js +2 -3
  24. package/dist/components/api-key.d.ts +0 -9
  25. package/dist/components/api-key.js +0 -39
  26. package/dist/components/auth-atoms.d.ts +178 -0
  27. package/dist/components/auth-atoms.js +46 -0
  28. package/dist/components/auth-client-api.d.ts +2474 -142
  29. package/dist/components/auth-client-api.js +14 -10
  30. package/dist/components/auth-forms.d.ts +1 -3
  31. package/dist/components/auth-forms.js +168 -195
  32. package/dist/components/auth-provider.d.ts +3 -7
  33. package/dist/components/auth-provider.js +56 -30
  34. package/dist/components/has-permission.js +1 -1
  35. package/dist/components/index.d.ts +19 -20
  36. package/dist/components/index.js +13 -13
  37. package/dist/components/member-required.d.ts +1 -3
  38. package/dist/components/member-required.js +102 -78
  39. package/dist/components/organization-switcher.d.ts +4 -6
  40. package/dist/components/organization-switcher.js +469 -323
  41. package/dist/components/project-access-matrix.d.ts +1 -1
  42. package/dist/components/project-access-matrix.js +9 -13
  43. package/dist/components/user-button.d.ts +5 -3
  44. package/dist/components/user-button.js +264 -314
  45. package/dist/components/utils.d.ts +3 -1
  46. package/dist/components/utils.js +4 -11
  47. package/dist/extra/api.group.d.ts +3 -3
  48. package/dist/extra/api.group.js +6 -6
  49. package/dist/extra/schema.js +1 -1
  50. package/dist/index.d.ts +11 -12
  51. package/dist/index.js +11 -12
  52. package/dist/query.d.ts +2 -2
  53. package/dist/roles.d.ts +5 -4
  54. package/dist/roles.js +11 -7
  55. package/dist/schema.d.ts +1 -1
  56. package/dist/schema.js +26 -19
  57. package/dist/server/actor.d.ts +20 -22
  58. package/dist/server/actor.js +14 -17
  59. package/dist/server/api.group.js +2 -2
  60. package/dist/server/index.d.ts +14 -14
  61. package/dist/server/index.js +8 -8
  62. package/dist/server/middleware.d.ts +1 -1
  63. package/dist/server/middleware.js +1 -1
  64. package/dist/server/schema.js +1 -1
  65. package/dist/service.d.ts +2043 -191
  66. package/dist/service.js +23 -16
  67. package/package.json +8 -7
  68. package/dist/better-auth/api.group.d.ts +0 -62
  69. package/dist/better-auth/api.group.js +0 -39
  70. package/dist/better-auth/schema.d.ts +0 -72
  71. package/dist/better-auth/schema.js +0 -110
  72. package/dist/components/auth-client.d.ts +0 -50
  73. package/dist/components/auth-client.js +0 -46
package/dist/service.js CHANGED
@@ -2,9 +2,9 @@ import { Cache, Context, Duration, Effect, Exit, Layer, Redacted, } from "effect
2
2
  import { FetchHttpClient, HttpClient, HttpClientRequest, } from "effect/unstable/http";
3
3
  import { HttpApiClient } from "effect/unstable/httpapi";
4
4
  import { HttpApiError } from "effect/unstable/httpapi";
5
- import { AuthServiceApi } from "./api";
6
- import { AuthClientConfig } from "./config";
7
- import { ExtraVerifiedApiKey } from "./extra/schema";
5
+ import { AuthServiceApi } from "./api.js";
6
+ import { AuthClientConfig } from "./config.js";
7
+ import { ExtraVerifiedApiKey } from "./extra/schema.js";
8
8
  const forwardedAuthHeaderNames = [
9
9
  "accept-language",
10
10
  "cookie",
@@ -46,7 +46,7 @@ const withRequiredOrganization = (authSession) => {
46
46
  })
47
47
  : Effect.fail(unauthorized());
48
48
  };
49
- const isBetterAuthSessionRequest = (request) => request.url.endsWith("/api/auth/get-session");
49
+ const isAuthSessionRequest = (request) => request.url.endsWith("/api/auth/get-session");
50
50
  class SessionLookup extends Context.Service()("@krak-stack/auth/SessionLookup") {
51
51
  }
52
52
  const sessionCache = Effect.runSync(Cache.makeWith(() => Effect.gen(function* () {
@@ -63,7 +63,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
63
63
  const apiKeyConfigId = options.apiKeyConfigId;
64
64
  const config = yield* AuthClientConfig;
65
65
  const http = yield* HttpClient.HttpClient;
66
- const httpClient = HttpClient.mapRequest(http, (request) => isBetterAuthSessionRequest(request)
66
+ const httpClient = HttpClient.mapRequest(http, (request) => isAuthSessionRequest(request)
67
67
  ? request
68
68
  : HttpClientRequest.bearerToken(request, Redacted.value(config.apiKey)));
69
69
  const api = yield* HttpApiClient.makeWith(AuthServiceApi, {
@@ -74,7 +74,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
74
74
  const apiKey = headerValue(headers, "x-api-key")?.trim();
75
75
  const organizationId = headerValue(headers, "x-organization-id")?.trim();
76
76
  const getCookieSession = () => Cache.get(sessionCache, sessionCacheKey).pipe(Effect.provideService(SessionLookup, {
77
- getSession: api.auth.getSession,
77
+ getSession: () => api.auth.getSession({ query: {} }),
78
78
  }), Effect.mapError(serviceUnavailable), Effect.map((authSession) => authSession
79
79
  ? {
80
80
  ...authSession,
@@ -103,13 +103,12 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
103
103
  .pipe(Effect.mapError(serviceUnavailable));
104
104
  };
105
105
  const getApiKeySession = (key) => Effect.gen(function* () {
106
+ const payload = { key };
107
+ const verifyPayload = apiKeyConfigId
108
+ ? { ...payload, configId: apiKeyConfigId }
109
+ : payload;
106
110
  const verified = yield* api.authExtra
107
- .verifyApiKey({
108
- payload: {
109
- key,
110
- ...(apiKeyConfigId ? { configId: apiKeyConfigId } : {}),
111
- },
112
- })
111
+ .verifyApiKey({ payload: verifyPayload })
113
112
  .pipe(Effect.mapError(serviceUnavailable));
114
113
  if (!verified.valid || !verified.key) {
115
114
  return yield* Effect.fail(unauthorized());
@@ -144,6 +143,9 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
144
143
  : Effect.fail(unauthorized())));
145
144
  const requireOrganization = () => requireSession().pipe(Effect.flatMap(withRequiredOrganization));
146
145
  const requireUserOrganization = () => requireUser().pipe(Effect.flatMap(withRequiredOrganization));
146
+ const getActiveMemberRole = (input) => api.organizations
147
+ .getActiveMember({ params: input })
148
+ .pipe(Effect.map((member) => member.role));
147
149
  return {
148
150
  ...api,
149
151
  getSession,
@@ -151,14 +153,19 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
151
153
  requireUser,
152
154
  requireOrganization,
153
155
  requireUserOrganization,
156
+ getActiveMemberRole,
154
157
  };
155
158
  }),
156
159
  }) {
157
160
  static layer = (options = {}) => {
158
161
  const headers = options.headers ?? {};
159
- return Layer.effect(this, this.make({ ...options, headers })).pipe(Layer.provide(AuthClientConfig.layer({
160
- ...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),
161
- ...(options.apiKey ? { apiKey: options.apiKey } : {}),
162
- })), Layer.provide(authHttpClientLayer(headers)));
162
+ let clientConfig = {};
163
+ if (options.baseUrl) {
164
+ clientConfig = { ...clientConfig, baseUrl: options.baseUrl };
165
+ }
166
+ if (options.apiKey) {
167
+ clientConfig = { ...clientConfig, apiKey: options.apiKey };
168
+ }
169
+ return Layer.effect(this, this.make({ ...options, headers })).pipe(Layer.provide(AuthClientConfig.layer(clientConfig)), Layer.provide(authHttpClientLayer(headers)));
163
170
  };
164
171
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.71",
3
+ "version": "0.2.0",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -47,9 +47,9 @@
47
47
  "default": "./dist/components/index.js"
48
48
  },
49
49
  "./tailwind.css": "./tailwind.css",
50
- "./better-auth": {
51
- "types": "./dist/better-auth/api.group.d.ts",
52
- "default": "./dist/better-auth/api.group.js"
50
+ "./auth": {
51
+ "types": "./dist/auth/api.group.d.ts",
52
+ "default": "./dist/auth/api.group.js"
53
53
  },
54
54
  "./extra": {
55
55
  "types": "./dist/extra/api.group.d.ts",
@@ -79,13 +79,14 @@
79
79
  "react-qr-code": "^2.2.0"
80
80
  },
81
81
  "peerDependencies": {
82
- "@better-auth/api-key": "^1.6.14",
82
+ "@effect/atom-react": "^4.0.0-beta.78",
83
+ "@lucas-barake/effect-form-react": "^0.26.0-beta.5",
83
84
  "@tanstack/react-router": "^1.170.15",
84
85
  "@tanstack/react-table": "^9.1.2",
85
- "better-auth": "^1.6.14",
86
86
  "effect": "^4.0.0-beta.78",
87
87
  "input-otp": "^1.4.2",
88
88
  "lucide-react": "^1.17.0",
89
- "react": "^19.2.7"
89
+ "react": "^19.2.7",
90
+ "sonner": "^2.0.7"
90
91
  }
91
92
  }
@@ -1,62 +0,0 @@
1
- import { HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi";
2
- import { TooManyRequests } from "./schema";
3
- export * from "./schema";
4
- export type { Session, User } from "../schema";
5
- export declare const BetterAuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndpoint.HttpApiEndpoint<"getSession", "GET", "/get-session", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
6
- readonly session: import("effect/Schema").Struct<{
7
- readonly id: import("effect/Schema").String;
8
- readonly expiresAt: import("effect/Schema").Date;
9
- readonly token: import("effect/Schema").String;
10
- readonly createdAt: import("effect/Schema").Date;
11
- readonly updatedAt: import("effect/Schema").Date;
12
- readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
13
- readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
14
- readonly userId: import("effect/Schema").String;
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>>;
17
- readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
18
- }>;
19
- readonly user: import("effect/Schema").Struct<{
20
- readonly id: import("effect/Schema").String;
21
- readonly name: import("effect/Schema").String;
22
- readonly email: import("effect/Schema").String;
23
- readonly emailVerified: import("effect/Schema").Boolean;
24
- readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
25
- readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
26
- readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
27
- readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
28
- readonly createdAt: import("effect/Schema").Date;
29
- readonly updatedAt: import("effect/Schema").Date;
30
- }>;
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.Forbidden | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never>, false>;
@@ -1,39 +0,0 @@
1
- import { OpenApi } from "effect/unstable/httpapi";
2
- import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
3
- import { GetSessionResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, TooManyRequests, } from "./schema";
4
- export * from "./schema";
5
- export const BetterAuthApiGroup = HttpApiGroup.make("auth")
6
- .add(HttpApiEndpoint.get("getSession", "/get-session", {
7
- success: GetSessionResponse,
8
- error: [
9
- HttpApiError.BadRequest,
10
- HttpApiError.Unauthorized,
11
- HttpApiError.Forbidden,
12
- HttpApiError.NotFound,
13
- TooManyRequests,
14
- HttpApiError.InternalServerError,
15
- ],
16
- }).annotateMerge(OpenApi.annotations({
17
- title: "Get session",
18
- summary: "Get current Better Auth session",
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.Forbidden,
28
- HttpApiError.NotFound,
29
- HttpApiError.InternalServerError,
30
- ],
31
- }).annotateMerge(OpenApi.annotations({
32
- title: "Organization impersonate user",
33
- summary: "Create an organization impersonation session",
34
- 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.",
35
- })))
36
- .annotateMerge(OpenApi.annotations({
37
- title: "Better Auth",
38
- description: "Better Auth-owned browser session endpoints.",
39
- }));
@@ -1,72 +0,0 @@
1
- import { Schema } from "effect";
2
- export declare const GetSessionPayload: Schema.Struct<{}>;
3
- export declare const GetSessionResponse: Schema.NullOr<Schema.Struct<{
4
- readonly session: Schema.Struct<{
5
- readonly id: Schema.String;
6
- readonly expiresAt: Schema.Date;
7
- readonly token: Schema.String;
8
- readonly createdAt: Schema.Date;
9
- readonly updatedAt: Schema.Date;
10
- readonly ipAddress: Schema.optional<Schema.NullOr<Schema.String>>;
11
- readonly userAgent: Schema.optional<Schema.NullOr<Schema.String>>;
12
- readonly userId: Schema.String;
13
- readonly impersonatedBy: Schema.optional<Schema.NullOr<Schema.String>>;
14
- readonly impersonatedByOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
15
- readonly activeOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
16
- }>;
17
- readonly user: Schema.Struct<{
18
- readonly id: Schema.String;
19
- readonly name: Schema.String;
20
- readonly email: Schema.String;
21
- readonly emailVerified: Schema.Boolean;
22
- readonly image: Schema.NullOr<Schema.String>;
23
- readonly role: Schema.NullOr<Schema.String>;
24
- readonly banned: Schema.NullOr<Schema.Boolean>;
25
- readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
26
- readonly createdAt: Schema.Date;
27
- readonly updatedAt: Schema.Date;
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
- }>;
63
- declare const TooManyRequests_base: Schema.Class<TooManyRequests, Schema.Struct<{
64
- readonly _tag: Schema.tag<"TooManyRequests">;
65
- }>, import("effect/Cause").YieldableError>;
66
- export declare class TooManyRequests extends TooManyRequests_base {
67
- }
68
- export type GetSessionResponse = typeof GetSessionResponse.Type;
69
- export type GetSessionPayload = typeof GetSessionPayload.Type;
70
- export type OrganizationImpersonateUserPayload = typeof OrganizationImpersonateUserPayload.Type;
71
- export type OrganizationImpersonateUserResponse = typeof OrganizationImpersonateUserResponse.Type;
72
- export {};
@@ -1,110 +0,0 @@
1
- import { Schema } from "effect";
2
- import { Session, User } from "../schema";
3
- export const GetSessionPayload = Schema.Struct({}).annotate({
4
- identifier: "GetSessionPayload",
5
- title: "Get session payload",
6
- description: "Empty JSON object payload for Better Auth get-session.",
7
- examples: [{}],
8
- });
9
- export const GetSessionResponse = Schema.NullOr(Schema.Struct({
10
- session: Session,
11
- user: User,
12
- })).annotate({
13
- identifier: "GetSessionResponse",
14
- title: "Get session response",
15
- description: "Current Better Auth session and user, or null when signed out.",
16
- examples: [
17
- {
18
- session: {
19
- id: "session_1",
20
- expiresAt: new Date("2026-02-01T00:00:00.000Z"),
21
- token: "session-token",
22
- createdAt: new Date("2026-01-01T00:00:00.000Z"),
23
- updatedAt: new Date("2026-01-01T00:00:00.000Z"),
24
- ipAddress: "127.0.0.1",
25
- userAgent: "Mozilla/5.0",
26
- userId: "user_1",
27
- impersonatedBy: null,
28
- impersonatedByOrganizationId: null,
29
- activeOrganizationId: "org_1",
30
- },
31
- user: {
32
- id: "user_1",
33
- name: "Ada Lovelace",
34
- email: "ada@example.com",
35
- emailVerified: true,
36
- image: null,
37
- role: "admin",
38
- banned: false,
39
- lastLoginMethod: "email-otp",
40
- createdAt: new Date("2026-01-01T00:00:00.000Z"),
41
- updatedAt: new Date("2026-01-01T00:00:00.000Z"),
42
- },
43
- },
44
- null,
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
- });
102
- export class TooManyRequests extends Schema.ErrorClass("TooManyRequests")({
103
- _tag: Schema.tag("TooManyRequests"),
104
- }, {
105
- identifier: "TooManyRequests",
106
- title: "Too many requests",
107
- description: "Rate limit exceeded. Try again later.",
108
- httpApiStatus: 429,
109
- }) {
110
- }
@@ -1,50 +0,0 @@
1
- import { apiKeyClient } from "@better-auth/api-key/client";
2
- import type { BetterAuthClientOptions } from "@better-auth/core";
3
- import { adminClient, anonymousClient, emailOTPClient, genericOAuthClient, inferAdditionalFields, lastLoginMethodClient, organizationClient, twoFactorClient } from "better-auth/client/plugins";
4
- import { type ReactAuthClient } from "better-auth/react";
5
- declare const additionalFields: {
6
- readonly session: {
7
- readonly impersonatedByOrganizationId: {
8
- readonly type: "string";
9
- readonly required: false;
10
- readonly input: false;
11
- };
12
- };
13
- };
14
- declare const organizationSchema: {
15
- readonly organization: {
16
- readonly additionalFields: {
17
- readonly userId: {
18
- readonly type: "string";
19
- readonly required: false;
20
- };
21
- readonly parentId: {
22
- readonly type: "string";
23
- readonly required: false;
24
- };
25
- };
26
- };
27
- };
28
- type AuthUiClientPlugins = [
29
- ReturnType<typeof inferAdditionalFields<never, typeof additionalFields>>,
30
- ReturnType<typeof adminClient<{}>>,
31
- ReturnType<typeof anonymousClient>,
32
- ReturnType<typeof emailOTPClient>,
33
- ReturnType<typeof lastLoginMethodClient>,
34
- ReturnType<typeof organizationClient<{
35
- schema: typeof organizationSchema;
36
- }>>,
37
- ReturnType<typeof twoFactorClient>,
38
- ReturnType<typeof apiKeyClient>,
39
- ReturnType<typeof genericOAuthClient>
40
- ];
41
- type AuthUiClientOptions = BetterAuthClientOptions & {
42
- baseURL?: string | undefined;
43
- plugins: AuthUiClientPlugins;
44
- };
45
- type CreateAuthUiClientOptions = {
46
- credentials?: RequestCredentials | undefined;
47
- };
48
- export type AuthUiClient = ReactAuthClient<AuthUiClientOptions>;
49
- export declare const createAuthUiClient: (baseUrl?: string | undefined, options?: CreateAuthUiClientOptions) => ReactAuthClient<AuthUiClientOptions>;
50
- export {};
@@ -1,46 +0,0 @@
1
- import { apiKeyClient } from "@better-auth/api-key/client";
2
- import { adminClient, anonymousClient, emailOTPClient, genericOAuthClient, inferAdditionalFields, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
3
- import { createAuthClient } from "better-auth/react";
4
- const additionalFields = {
5
- session: {
6
- impersonatedByOrganizationId: {
7
- type: "string",
8
- required: false,
9
- input: false,
10
- },
11
- },
12
- };
13
- const organizationSchema = {
14
- organization: {
15
- additionalFields: {
16
- userId: {
17
- type: "string",
18
- required: false,
19
- },
20
- parentId: {
21
- type: "string",
22
- required: false,
23
- },
24
- },
25
- },
26
- };
27
- const authUiClientPlugins = [
28
- inferAdditionalFields(additionalFields),
29
- adminClient(),
30
- anonymousClient(),
31
- emailOTPClient(),
32
- lastLoginMethodClient({
33
- cookieName: "krakstack-auth.last_used_login_method",
34
- }),
35
- organizationClient({ schema: organizationSchema }),
36
- twoFactorClient(),
37
- apiKeyClient(),
38
- genericOAuthClient(),
39
- ];
40
- export const createAuthUiClient = (baseUrl, options) => createAuthClient({
41
- ...(baseUrl ? { baseURL: baseUrl } : {}),
42
- fetchOptions: {
43
- credentials: options?.credentials ?? "include",
44
- },
45
- plugins: authUiClientPlugins,
46
- });