@krak-stack/auth 0.1.70 → 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.
- package/README.md +4 -3
- package/dist/access.d.ts +4 -4
- package/dist/access.js +10 -4
- package/dist/admin/api.group.d.ts +17 -17
- package/dist/admin/api.group.js +2 -2
- package/dist/admin/schema.d.ts +18 -18
- package/dist/admin/schema.js +3 -3
- package/dist/api.d.ts +2093 -631
- package/dist/api.js +7 -7
- package/dist/auth/api.group.d.ts +793 -0
- package/dist/auth/api.group.js +241 -0
- package/dist/auth/schema.d.ts +800 -0
- package/dist/auth/schema.js +625 -0
- package/dist/components/admin-organization-form.d.ts +1 -1
- package/dist/components/admin-organization-form.js +16 -18
- package/dist/components/admin-organizations.js +52 -46
- package/dist/components/admin-users.js +115 -138
- package/dist/components/api-key-edit-form.d.ts +4 -3
- package/dist/components/api-key-edit-form.js +32 -27
- package/dist/components/api-key-permissions.d.ts +1 -1
- package/dist/components/api-key-rate-limit.d.ts +1 -1
- package/dist/components/api-key-referrers.d.ts +3 -2
- package/dist/components/api-key-referrers.js +2 -3
- package/dist/components/api-key.d.ts +0 -9
- package/dist/components/api-key.js +0 -39
- package/dist/components/auth-atoms.d.ts +178 -0
- package/dist/components/auth-atoms.js +46 -0
- package/dist/components/auth-client-api.d.ts +2474 -142
- package/dist/components/auth-client-api.js +14 -10
- package/dist/components/auth-forms.d.ts +1 -3
- package/dist/components/auth-forms.js +168 -195
- package/dist/components/auth-provider.d.ts +3 -7
- package/dist/components/auth-provider.js +56 -30
- package/dist/components/has-permission.js +1 -1
- package/dist/components/index.d.ts +19 -20
- package/dist/components/index.js +13 -13
- package/dist/components/member-required.d.ts +1 -3
- package/dist/components/member-required.js +102 -78
- package/dist/components/organization-switcher.d.ts +4 -6
- package/dist/components/organization-switcher.js +469 -324
- package/dist/components/project-access-matrix.d.ts +1 -1
- package/dist/components/project-access-matrix.js +9 -13
- package/dist/components/user-button.d.ts +5 -3
- package/dist/components/user-button.js +265 -316
- package/dist/components/utils.d.ts +3 -1
- package/dist/components/utils.js +4 -11
- package/dist/extra/api.group.d.ts +3 -3
- package/dist/extra/api.group.js +6 -6
- package/dist/extra/schema.js +1 -1
- package/dist/index.d.ts +11 -12
- package/dist/index.js +11 -12
- package/dist/query.d.ts +2 -2
- package/dist/roles.d.ts +5 -4
- package/dist/roles.js +11 -7
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +26 -19
- package/dist/server/actor.d.ts +30 -32
- package/dist/server/actor.js +39 -22
- package/dist/server/api.group.js +2 -2
- package/dist/server/index.d.ts +14 -14
- package/dist/server/index.js +8 -8
- package/dist/server/middleware.d.ts +3 -3
- package/dist/server/middleware.js +10 -5
- package/dist/server/schema.js +1 -1
- package/dist/service.d.ts +2053 -201
- package/dist/service.js +32 -21
- package/package.json +10 -9
- package/dist/better-auth/api.group.d.ts +0 -62
- package/dist/better-auth/api.group.js +0 -39
- package/dist/better-auth/schema.d.ts +0 -72
- package/dist/better-auth/schema.js +0 -110
- package/dist/components/auth-client.d.ts +0 -50
- 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",
|
|
@@ -36,6 +36,7 @@ const headerValue = (headers, name) => {
|
|
|
36
36
|
return entry?.[1];
|
|
37
37
|
};
|
|
38
38
|
const unauthorized = () => new HttpApiError.Unauthorized({});
|
|
39
|
+
const serviceUnavailable = () => new HttpApiError.ServiceUnavailable({});
|
|
39
40
|
const withRequiredOrganization = (authSession) => {
|
|
40
41
|
const activeOrganizationId = authSession.session.activeOrganizationId;
|
|
41
42
|
return activeOrganizationId
|
|
@@ -45,7 +46,7 @@ const withRequiredOrganization = (authSession) => {
|
|
|
45
46
|
})
|
|
46
47
|
: Effect.fail(unauthorized());
|
|
47
48
|
};
|
|
48
|
-
const
|
|
49
|
+
const isAuthSessionRequest = (request) => request.url.endsWith("/api/auth/get-session");
|
|
49
50
|
class SessionLookup extends Context.Service()("@krak-stack/auth/SessionLookup") {
|
|
50
51
|
}
|
|
51
52
|
const sessionCache = Effect.runSync(Cache.makeWith(() => Effect.gen(function* () {
|
|
@@ -62,7 +63,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
62
63
|
const apiKeyConfigId = options.apiKeyConfigId;
|
|
63
64
|
const config = yield* AuthClientConfig;
|
|
64
65
|
const http = yield* HttpClient.HttpClient;
|
|
65
|
-
const httpClient = HttpClient.mapRequest(http, (request) =>
|
|
66
|
+
const httpClient = HttpClient.mapRequest(http, (request) => isAuthSessionRequest(request)
|
|
66
67
|
? request
|
|
67
68
|
: HttpClientRequest.bearerToken(request, Redacted.value(config.apiKey)));
|
|
68
69
|
const api = yield* HttpApiClient.makeWith(AuthServiceApi, {
|
|
@@ -71,9 +72,10 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
71
72
|
});
|
|
72
73
|
const sessionCacheKey = getSessionCacheKey(headers);
|
|
73
74
|
const apiKey = headerValue(headers, "x-api-key")?.trim();
|
|
75
|
+
const organizationId = headerValue(headers, "x-organization-id")?.trim();
|
|
74
76
|
const getCookieSession = () => Cache.get(sessionCache, sessionCacheKey).pipe(Effect.provideService(SessionLookup, {
|
|
75
|
-
getSession: api.auth.getSession,
|
|
76
|
-
}), Effect.mapError(
|
|
77
|
+
getSession: () => api.auth.getSession({ query: {} }),
|
|
78
|
+
}), Effect.mapError(serviceUnavailable), Effect.map((authSession) => authSession
|
|
77
79
|
? {
|
|
78
80
|
...authSession,
|
|
79
81
|
isSuperAdminImpersonation: false,
|
|
@@ -86,27 +88,28 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
86
88
|
}
|
|
87
89
|
return api.users
|
|
88
90
|
.getUser({ params: { id: verifiedKey.referenceId } })
|
|
89
|
-
.pipe(Effect.mapError(
|
|
91
|
+
.pipe(Effect.mapError(serviceUnavailable));
|
|
90
92
|
};
|
|
91
93
|
const activeOrganizationIdForApiKey = (verifiedKey, user) => {
|
|
92
94
|
if (verifiedKey.configId === "organization") {
|
|
93
95
|
return Effect.succeed({ id: verifiedKey.referenceId });
|
|
94
96
|
}
|
|
97
|
+
if (organizationId)
|
|
98
|
+
return Effect.succeed({ id: organizationId });
|
|
95
99
|
if (!user)
|
|
96
100
|
return Effect.succeed({ id: null });
|
|
97
101
|
return api.users
|
|
98
102
|
.getUserActiveOrganization({ params: { userId: user.id } })
|
|
99
|
-
.pipe(Effect.
|
|
103
|
+
.pipe(Effect.mapError(serviceUnavailable));
|
|
100
104
|
};
|
|
101
105
|
const getApiKeySession = (key) => Effect.gen(function* () {
|
|
106
|
+
const payload = { key };
|
|
107
|
+
const verifyPayload = apiKeyConfigId
|
|
108
|
+
? { ...payload, configId: apiKeyConfigId }
|
|
109
|
+
: payload;
|
|
102
110
|
const verified = yield* api.authExtra
|
|
103
|
-
.verifyApiKey({
|
|
104
|
-
|
|
105
|
-
key,
|
|
106
|
-
...(apiKeyConfigId ? { configId: apiKeyConfigId } : {}),
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
.pipe(Effect.mapError(unauthorized));
|
|
111
|
+
.verifyApiKey({ payload: verifyPayload })
|
|
112
|
+
.pipe(Effect.mapError(serviceUnavailable));
|
|
110
113
|
if (!verified.valid || !verified.key) {
|
|
111
114
|
return yield* Effect.fail(unauthorized());
|
|
112
115
|
}
|
|
@@ -131,7 +134,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
131
134
|
},
|
|
132
135
|
};
|
|
133
136
|
});
|
|
134
|
-
const getSession = () => apiKey ? getApiKeySession(apiKey) : getCookieSession();
|
|
137
|
+
const getSession = () => (apiKey ? getApiKeySession(apiKey) : getCookieSession());
|
|
135
138
|
const requireSession = () => getSession().pipe(Effect.flatMap((authSession) => authSession
|
|
136
139
|
? Effect.succeed(authSession)
|
|
137
140
|
: Effect.fail(unauthorized())));
|
|
@@ -140,6 +143,9 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
140
143
|
: Effect.fail(unauthorized())));
|
|
141
144
|
const requireOrganization = () => requireSession().pipe(Effect.flatMap(withRequiredOrganization));
|
|
142
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));
|
|
143
149
|
return {
|
|
144
150
|
...api,
|
|
145
151
|
getSession,
|
|
@@ -147,14 +153,19 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
147
153
|
requireUser,
|
|
148
154
|
requireOrganization,
|
|
149
155
|
requireUserOrganization,
|
|
156
|
+
getActiveMemberRole,
|
|
150
157
|
};
|
|
151
158
|
}),
|
|
152
159
|
}) {
|
|
153
160
|
static layer = (options = {}) => {
|
|
154
161
|
const headers = options.headers ?? {};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
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)));
|
|
159
170
|
};
|
|
160
171
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.
|
|
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
|
-
"./
|
|
51
|
-
"types": "./dist/
|
|
52
|
-
"default": "./dist/
|
|
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",
|
|
@@ -75,17 +75,18 @@
|
|
|
75
75
|
"type:check": "tsc -p tsconfig.json --noEmit"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@krak-stack/registry": "
|
|
78
|
+
"@krak-stack/registry": "0.1.19",
|
|
79
79
|
"react-qr-code": "^2.2.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@
|
|
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
|
-
"@tanstack/react-table": "^
|
|
85
|
-
"better-auth": "^1.6.14",
|
|
85
|
+
"@tanstack/react-table": "^9.1.2",
|
|
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
|
-
});
|