@krak-stack/auth 0.1.8 → 0.1.10
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 +18 -14
- package/dist/better-auth/api.d.ts +53 -0
- package/dist/better-auth/api.js +27 -0
- package/dist/better-auth/index.d.ts +31 -0
- package/dist/better-auth/index.js +12 -0
- package/dist/better-auth/schema.d.ts +35 -0
- package/dist/better-auth/schema.js +53 -0
- package/dist/client.d.ts +308 -108
- package/dist/client.js +22 -9
- package/dist/components/auth-client.d.ts +10 -0
- package/dist/components/auth-client.js +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/organization-switcher.d.ts +3 -8
- package/dist/components/organization-switcher.js +25 -28
- package/dist/components/user-button.d.ts +3 -1
- package/dist/components/user-button.js +44 -65
- package/dist/extra/api.d.ts +109 -0
- package/dist/extra/api.js +70 -0
- package/dist/extra/index.d.ts +60 -0
- package/dist/{frontend → extra}/index.js +5 -4
- package/dist/extra/schema.d.ts +90 -0
- package/dist/extra/schema.js +162 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/schema.d.ts +13 -0
- package/dist/schema.js +30 -0
- package/dist/{backend → server}/api.d.ts +13 -12
- package/dist/{backend → server}/api.js +23 -17
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +2 -0
- package/dist/{backend → server}/schema.d.ts +14 -14
- package/dist/server/schema.js +81 -0
- package/package.json +11 -7
- package/dist/backend/index.d.ts +0 -4
- package/dist/backend/index.js +0 -2
- package/dist/backend/schema.js +0 -81
- package/dist/frontend/api.d.ts +0 -16
- package/dist/frontend/api.js +0 -21
- package/dist/frontend/index.d.ts +0 -14
- package/dist/frontend/schema.d.ts +0 -11
- package/dist/frontend/schema.js +0 -18
package/README.md
CHANGED
|
@@ -15,23 +15,27 @@ bun add @krak-stack/auth effect
|
|
|
15
15
|
|
|
16
16
|
## Auth Client
|
|
17
17
|
|
|
18
|
+
Better Auth:
|
|
19
|
+
|
|
20
|
+
- `getSession({ payload: {} })` - returns the current Better Auth session and user.
|
|
21
|
+
|
|
18
22
|
Users:
|
|
19
23
|
|
|
20
|
-
- `
|
|
21
|
-
- `
|
|
24
|
+
- `server.listUsersByIds({ query: { ids } })` - returns matching users and missing IDs for a comma-separated ID list.
|
|
25
|
+
- `server.getUser({ params: { id } })` - returns one user by ID.
|
|
22
26
|
|
|
23
27
|
Organizations:
|
|
24
28
|
|
|
25
|
-
- `
|
|
26
|
-
- `
|
|
27
|
-
- `
|
|
28
|
-
- `
|
|
29
|
-
- `
|
|
29
|
+
- `server.listOrganizations({ query: { ids } })` - returns matching organizations and missing IDs for a comma-separated ID list.
|
|
30
|
+
- `server.listOrganizations({ query: { userId } })` - returns organizations for one user.
|
|
31
|
+
- `server.getOrganization({ params: { id } })` - returns one organization by ID.
|
|
32
|
+
- `server.getUserActiveOrganization({ params: { userId } })` - returns the active organization ID for one user.
|
|
33
|
+
- `extra.presign({ payload })` - returns a presigned organization logo upload URL.
|
|
30
34
|
|
|
31
35
|
Members:
|
|
32
36
|
|
|
33
|
-
- `
|
|
34
|
-
- `
|
|
37
|
+
- `server.getActiveMember({ params: { organizationId, userId } })` - returns one user's membership and role in an organization.
|
|
38
|
+
- `server.listOrganizationMembers({ params: { organizationId } })` - returns organization members with user contact details.
|
|
35
39
|
|
|
36
40
|
```ts
|
|
37
41
|
import { Effect } from "effect";
|
|
@@ -39,8 +43,8 @@ import { AuthClient } from "@krak-stack/auth";
|
|
|
39
43
|
|
|
40
44
|
const users = await Effect.runPromise(
|
|
41
45
|
Effect.gen(function* () {
|
|
42
|
-
const
|
|
43
|
-
return yield*
|
|
46
|
+
const auth = yield* AuthClient;
|
|
47
|
+
return yield* auth.server.listUsersByIds({
|
|
44
48
|
query: { ids: "user_1,user_2" },
|
|
45
49
|
});
|
|
46
50
|
}).pipe(Effect.provide(AuthClient.layer)),
|
|
@@ -48,15 +52,15 @@ const users = await Effect.runPromise(
|
|
|
48
52
|
|
|
49
53
|
const organizations = await Effect.runPromise(
|
|
50
54
|
Effect.gen(function* () {
|
|
51
|
-
const
|
|
52
|
-
return yield*
|
|
55
|
+
const auth = yield* AuthClient;
|
|
56
|
+
return yield* auth.server.listOrganizations({
|
|
53
57
|
query: { userId: "user_1" },
|
|
54
58
|
});
|
|
55
59
|
}).pipe(Effect.provide(AuthClient.layer)),
|
|
56
60
|
);
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
The
|
|
63
|
+
The extra subpath also exports `ExtraApiClient` for Atom-based browser state.
|
|
60
64
|
|
|
61
65
|
## Components
|
|
62
66
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { HttpApi } from "effect/unstable/httpapi";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi";
|
|
3
|
+
import { TooManyRequests } from "./schema";
|
|
4
|
+
export declare const BetterAuthApiGroup: HttpApiGroup.HttpApiGroup<"betterAuth", HttpApiEndpoint.HttpApiEndpoint<"getSession", "POST", "/get-session", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
5
|
+
readonly session: import("effect/Schema").Struct<{
|
|
6
|
+
readonly id: import("effect/Schema").String;
|
|
7
|
+
readonly expiresAt: import("effect/Schema").Date;
|
|
8
|
+
readonly token: import("effect/Schema").String;
|
|
9
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
10
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
11
|
+
readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
12
|
+
readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
13
|
+
readonly userId: import("effect/Schema").String;
|
|
14
|
+
readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
15
|
+
readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
16
|
+
}>;
|
|
17
|
+
readonly user: import("effect/Schema").Struct<{
|
|
18
|
+
readonly id: import("effect/Schema").String;
|
|
19
|
+
readonly name: import("effect/Schema").String;
|
|
20
|
+
readonly email: import("effect/Schema").String;
|
|
21
|
+
readonly emailVerified: import("effect/Schema").Boolean;
|
|
22
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
23
|
+
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
24
|
+
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
25
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
26
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
27
|
+
}>;
|
|
28
|
+
}>>>, HttpApiEndpoint.Json<typeof TooManyRequests | typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never>, false>;
|
|
29
|
+
export declare const BetterAuthApi: HttpApi.HttpApi<"BetterAuthApi", HttpApiGroup.HttpApiGroup<"betterAuth", HttpApiEndpoint.HttpApiEndpoint<"getSession", "POST", "/api/auth/get-session", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
30
|
+
readonly session: import("effect/Schema").Struct<{
|
|
31
|
+
readonly id: import("effect/Schema").String;
|
|
32
|
+
readonly expiresAt: import("effect/Schema").Date;
|
|
33
|
+
readonly token: import("effect/Schema").String;
|
|
34
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
35
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
36
|
+
readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
37
|
+
readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
38
|
+
readonly userId: import("effect/Schema").String;
|
|
39
|
+
readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
40
|
+
readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
41
|
+
}>;
|
|
42
|
+
readonly user: import("effect/Schema").Struct<{
|
|
43
|
+
readonly id: import("effect/Schema").String;
|
|
44
|
+
readonly name: import("effect/Schema").String;
|
|
45
|
+
readonly email: import("effect/Schema").String;
|
|
46
|
+
readonly emailVerified: import("effect/Schema").Boolean;
|
|
47
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
48
|
+
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
49
|
+
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
50
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
51
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
52
|
+
}>;
|
|
53
|
+
}>>>, HttpApiEndpoint.Json<typeof TooManyRequests | typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never>, false>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HttpApi, OpenApi } from "effect/unstable/httpapi";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
|
|
3
|
+
import { GetSessionPayload, GetSessionResponse, TooManyRequests, } from "./schema";
|
|
4
|
+
export const BetterAuthApiGroup = HttpApiGroup.make("betterAuth")
|
|
5
|
+
.add(HttpApiEndpoint.post("getSession", "/get-session", {
|
|
6
|
+
payload: GetSessionPayload,
|
|
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
|
+
.annotateMerge(OpenApi.annotations({
|
|
22
|
+
title: "Better Auth",
|
|
23
|
+
description: "Better Auth-owned browser session endpoints.",
|
|
24
|
+
}));
|
|
25
|
+
export const BetterAuthApi = HttpApi.make("BetterAuthApi")
|
|
26
|
+
.add(BetterAuthApiGroup)
|
|
27
|
+
.prefix("/api/auth");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AtomHttpApi } from "effect/unstable/reactivity";
|
|
2
|
+
declare const BetterAuthApiClient_base: AtomHttpApi.AtomHttpApiClient<BetterAuthApiClient, "BetterAuthApiClient", import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"betterAuth", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getSession", "POST", "/api/auth/get-session", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
3
|
+
readonly session: import("effect/Schema").Struct<{
|
|
4
|
+
readonly id: import("effect/Schema").String;
|
|
5
|
+
readonly expiresAt: import("effect/Schema").Date;
|
|
6
|
+
readonly token: import("effect/Schema").String;
|
|
7
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
8
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
9
|
+
readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
10
|
+
readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
11
|
+
readonly userId: import("effect/Schema").String;
|
|
12
|
+
readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
13
|
+
readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
14
|
+
}>;
|
|
15
|
+
readonly user: import("effect/Schema").Struct<{
|
|
16
|
+
readonly id: import("effect/Schema").String;
|
|
17
|
+
readonly name: import("effect/Schema").String;
|
|
18
|
+
readonly email: import("effect/Schema").String;
|
|
19
|
+
readonly emailVerified: import("effect/Schema").Boolean;
|
|
20
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
21
|
+
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
22
|
+
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
23
|
+
readonly createdAt: import("effect/Schema").Date;
|
|
24
|
+
readonly updatedAt: import("effect/Schema").Date;
|
|
25
|
+
}>;
|
|
26
|
+
}>>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("./schema").TooManyRequests | 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>, never, never>, false>>;
|
|
27
|
+
export declare class BetterAuthApiClient extends BetterAuthApiClient_base {
|
|
28
|
+
}
|
|
29
|
+
export { BetterAuthApi, BetterAuthApiGroup } from "./api";
|
|
30
|
+
export * from "./schema";
|
|
31
|
+
export type { Session, User } from "../schema";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FetchHttpClient } from "effect/unstable/http";
|
|
2
|
+
import { AtomHttpApi } from "effect/unstable/reactivity";
|
|
3
|
+
import { defaultBaseUrl } from "../config";
|
|
4
|
+
import { BetterAuthApi } from "./api";
|
|
5
|
+
export class BetterAuthApiClient extends AtomHttpApi.Service()("BetterAuthApiClient", {
|
|
6
|
+
api: BetterAuthApi,
|
|
7
|
+
baseUrl: defaultBaseUrl(),
|
|
8
|
+
httpClient: FetchHttpClient.layer,
|
|
9
|
+
}) {
|
|
10
|
+
}
|
|
11
|
+
export { BetterAuthApi, BetterAuthApiGroup } from "./api";
|
|
12
|
+
export * from "./schema";
|
|
@@ -0,0 +1,35 @@
|
|
|
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 activeOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
15
|
+
}>;
|
|
16
|
+
readonly user: Schema.Struct<{
|
|
17
|
+
readonly id: Schema.String;
|
|
18
|
+
readonly name: Schema.String;
|
|
19
|
+
readonly email: Schema.String;
|
|
20
|
+
readonly emailVerified: Schema.Boolean;
|
|
21
|
+
readonly image: Schema.NullOr<Schema.String>;
|
|
22
|
+
readonly role: Schema.NullOr<Schema.String>;
|
|
23
|
+
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
24
|
+
readonly createdAt: Schema.Date;
|
|
25
|
+
readonly updatedAt: Schema.Date;
|
|
26
|
+
}>;
|
|
27
|
+
}>>;
|
|
28
|
+
declare const TooManyRequests_base: Schema.Class<TooManyRequests, Schema.Struct<{
|
|
29
|
+
readonly _tag: Schema.tag<"TooManyRequests">;
|
|
30
|
+
}>, import("effect/Cause").YieldableError>;
|
|
31
|
+
export declare class TooManyRequests extends TooManyRequests_base {
|
|
32
|
+
}
|
|
33
|
+
export type GetSessionResponse = typeof GetSessionResponse.Type;
|
|
34
|
+
export type GetSessionPayload = typeof GetSessionPayload.Type;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
activeOrganizationId: "org_1",
|
|
29
|
+
},
|
|
30
|
+
user: {
|
|
31
|
+
id: "user_1",
|
|
32
|
+
name: "Ada Lovelace",
|
|
33
|
+
email: "ada@example.com",
|
|
34
|
+
emailVerified: true,
|
|
35
|
+
image: null,
|
|
36
|
+
role: "admin",
|
|
37
|
+
banned: false,
|
|
38
|
+
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
39
|
+
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
null,
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
export class TooManyRequests extends Schema.ErrorClass("TooManyRequests")({
|
|
46
|
+
_tag: Schema.tag("TooManyRequests"),
|
|
47
|
+
}, {
|
|
48
|
+
identifier: "TooManyRequests",
|
|
49
|
+
title: "Too many requests",
|
|
50
|
+
description: "Rate limit exceeded. Try again later.",
|
|
51
|
+
httpApiStatus: 429,
|
|
52
|
+
}) {
|
|
53
|
+
}
|