@shivaedev/identity 0.4.0 → 0.5.1
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 +19 -13
- package/dist/identity.d.ts +19 -6
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +9 -1
- package/dist/identity.js.map +1 -1
- package/dist/middleware.d.ts +2 -0
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +5 -4
- package/dist/middleware.js.map +1 -1
- package/dist/permission.d.ts +7 -8
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +4 -12
- package/dist/permission.js.map +1 -1
- package/dist/server/adapters/betterAuthSessions.d.ts +1 -1
- package/dist/server/adapters/betterAuthSessions.d.ts.map +1 -1
- package/dist/server/adapters/betterAuthSessions.js +4 -7
- package/dist/server/adapters/betterAuthSessions.js.map +1 -1
- package/dist/server/better-auth/admittedSessions.d.ts +14 -0
- package/dist/server/better-auth/admittedSessions.d.ts.map +1 -0
- package/dist/server/better-auth/admittedSessions.js +32 -0
- package/dist/server/better-auth/admittedSessions.js.map +1 -0
- package/dist/server/better-auth/clientIp.d.ts.map +1 -1
- package/dist/server/better-auth/clientIp.js +2 -1
- package/dist/server/better-auth/clientIp.js.map +1 -1
- package/dist/server/better-auth/mount.d.ts +8 -7
- package/dist/server/better-auth/mount.d.ts.map +1 -1
- package/dist/server/better-auth/mount.js +6 -24
- package/dist/server/better-auth/mount.js.map +1 -1
- package/dist/server/better-auth/mountRoutes.d.ts.map +1 -1
- package/dist/server/better-auth/mountRoutes.js +6 -6
- package/dist/server/better-auth/mountRoutes.js.map +1 -1
- package/dist/server/better-auth/mountedSessions.d.ts +9 -5
- package/dist/server/better-auth/mountedSessions.d.ts.map +1 -1
- package/dist/server/better-auth/mountedSessions.js +5 -5
- package/dist/server/better-auth/mountedSessions.js.map +1 -1
- package/dist/server/better-auth/sessionPermissions.d.ts +2 -1
- package/dist/server/better-auth/sessionPermissions.d.ts.map +1 -1
- package/dist/server/better-auth/sessionPermissions.js +6 -5
- package/dist/server/better-auth/sessionPermissions.js.map +1 -1
- package/dist/server/better-auth/signInGate.d.ts +1 -1
- package/dist/server/better-auth/signInGate.d.ts.map +1 -1
- package/dist/server/better-auth/signInGate.js +2 -3
- package/dist/server/better-auth/signInGate.js.map +1 -1
- package/dist/server/better-auth/userProfiles.d.ts +1 -1
- package/dist/server/better-auth/userProfiles.d.ts.map +1 -1
- package/dist/server/better-auth/userProfiles.js +2 -3
- package/dist/server/better-auth/userProfiles.js.map +1 -1
- package/dist/server/commandChanges.d.ts.map +1 -1
- package/dist/server/commandChanges.js +11 -6
- package/dist/server/commandChanges.js.map +1 -1
- package/dist/server/local.d.ts +4 -3
- package/dist/server/local.d.ts.map +1 -1
- package/dist/server/local.js +0 -4
- package/dist/server/local.js.map +1 -1
- package/dist/server/lookupSession.d.ts +8 -0
- package/dist/server/lookupSession.d.ts.map +1 -0
- package/dist/server/lookupSession.js +23 -0
- package/dist/server/lookupSession.js.map +1 -0
- package/dist/server/origin.d.ts +7 -2
- package/dist/server/origin.d.ts.map +1 -1
- package/dist/server/origin.js +14 -5
- package/dist/server/origin.js.map +1 -1
- package/dist/server/permissions.d.ts +1 -1
- package/dist/server/permissions.d.ts.map +1 -1
- package/dist/server/permissions.js +9 -9
- package/dist/server/permissions.js.map +1 -1
- package/dist/server/providerFailure.d.ts +4 -0
- package/dist/server/providerFailure.d.ts.map +1 -0
- package/dist/server/providerFailure.js +10 -0
- package/dist/server/providerFailure.js.map +1 -0
- package/dist/server/recheckSession.d.ts +5 -0
- package/dist/server/recheckSession.d.ts.map +1 -0
- package/dist/server/recheckSession.js +11 -0
- package/dist/server/recheckSession.js.map +1 -0
- package/dist/server/resolveRole.d.ts +4 -5
- package/dist/server/resolveRole.d.ts.map +1 -1
- package/dist/server/resolveRole.js +1 -2
- package/dist/server/resolveRole.js.map +1 -1
- package/dist/server/revalidateStream.d.ts.map +1 -1
- package/dist/server/revalidateStream.js +2 -2
- package/dist/server/revalidateStream.js.map +1 -1
- package/dist/server/session.d.ts +2 -2
- package/dist/server/session.d.ts.map +1 -1
- package/dist/server/session.js +13 -23
- package/dist/server/session.js.map +1 -1
- package/dist/server/socketSession.d.ts +23 -0
- package/dist/server/socketSession.d.ts.map +1 -0
- package/dist/server/socketSession.js +32 -0
- package/dist/server/socketSession.js.map +1 -0
- package/dist/server/tracing.d.ts.map +1 -1
- package/dist/server/tracing.js +6 -2
- package/dist/server/tracing.js.map +1 -1
- package/dist/server/trustedProxy.d.ts +0 -1
- package/dist/server/trustedProxy.d.ts.map +1 -1
- package/dist/server/trustedProxy.js +1 -4
- package/dist/server/trustedProxy.js.map +1 -1
- package/package.json +8 -8
- package/src/identity.ts +10 -8
- package/src/middleware.ts +7 -4
- package/src/permission.ts +5 -17
- package/src/server/adapters/betterAuthSessions.ts +4 -10
- package/src/server/better-auth/admittedSessions.ts +38 -0
- package/src/server/better-auth/clientIp.ts +2 -1
- package/src/server/better-auth/mount.ts +8 -38
- package/src/server/better-auth/mountRoutes.ts +6 -10
- package/src/server/better-auth/mountedSessions.ts +19 -10
- package/src/server/better-auth/sessionPermissions.ts +10 -6
- package/src/server/better-auth/signInGate.ts +3 -10
- package/src/server/better-auth/userProfiles.ts +3 -10
- package/src/server/commandChanges.ts +46 -33
- package/src/server/local.ts +5 -7
- package/src/server/lookupSession.ts +30 -0
- package/src/server/origin.ts +23 -6
- package/src/server/permissions.ts +20 -16
- package/src/server/providerFailure.ts +13 -0
- package/src/server/recheckSession.ts +13 -0
- package/src/server/resolveRole.ts +4 -2
- package/src/server/revalidateStream.ts +2 -2
- package/src/server/session.ts +14 -22
- package/src/server/socketSession.ts +61 -0
- package/src/server/tracing.ts +8 -2
- package/src/server/trustedProxy.ts +1 -5
- package/dist/server/sessionProfile.d.ts +0 -3
- package/dist/server/sessionProfile.d.ts.map +0 -1
- package/dist/server/sessionProfile.js +0 -4
- package/dist/server/sessionProfile.js.map +0 -1
- package/src/server/sessionProfile.ts +0 -5
package/README.md
CHANGED
|
@@ -84,6 +84,8 @@ export const sessions = {
|
|
|
84
84
|
|
|
85
85
|
`trustedOrigins({ allow, missing })` accepts an exact allowlist and supports `missing: "reject"` or `"allow"`; a custom `OriginPolicy` can decide from the RPC name or transport headers. A denied policy fails with `Forbidden` before provider lookup. The host's HTTP guard also checks Origin against the local request's Host.
|
|
86
86
|
|
|
87
|
+
To also accept the transport guard's same-origin requests, pass `sameOrigin: { trustedProxy }`, with the same proxy IP addresses or CIDR ranges as the host. This admits direct loopback HTTP and the forwarded HTTP or HTTPS authority only from a matching transport peer. Session resolution supplies that peer from the HTTP request, including the WebSocket upgrade; RPC message headers cannot supply it. Missing Origins still follow `missing`. Leave `sameOrigin` absent when an explicit public-origin allowlist should be the only authority.
|
|
88
|
+
|
|
87
89
|
The application's `auth` owns its storage and session configuration. A null lookup becomes a missing session. A thrown or rejected lookup is logged in redacted form and fails with the generic `AuthUnavailable` message. It remains a failure even on an RPC with optional authentication.
|
|
88
90
|
|
|
89
91
|
### Mount Better Auth
|
|
@@ -133,7 +135,7 @@ const mounted = yield* betterAuthMount(
|
|
|
133
135
|
);
|
|
134
136
|
const sessions = {
|
|
135
137
|
origin: trustedOrigins({ allow: [publicOrigin, ...nativeOrigins], missing: "allow" }),
|
|
136
|
-
provider:
|
|
138
|
+
provider: mounted.admittedSessions((headers) => mounted.auth.api.getSession({ headers })),
|
|
137
139
|
};
|
|
138
140
|
const host = appHost({ group, handlers, routes: mounted.routes, sessions, nativeOrigins });
|
|
139
141
|
```
|
|
@@ -158,7 +160,6 @@ Give the mount a sign-in policy as its second argument, and resolve RPC sessions
|
|
|
158
160
|
import { Config, Effect } from "effect";
|
|
159
161
|
import { allowedAccounts } from "@shivaedev/identity/server/better-auth/allowedAccounts.ts";
|
|
160
162
|
import { authDatabase, betterAuthMount } from "@shivaedev/identity/server/better-auth/mount.ts";
|
|
161
|
-
import { betterAuthSessions } from "@shivaedev/identity/server/adapters/betterAuthSessions.ts";
|
|
162
163
|
import { trustedOrigins } from "@shivaedev/identity/server/origin.ts";
|
|
163
164
|
|
|
164
165
|
const authentication = Effect.gen(function* () {
|
|
@@ -170,7 +171,7 @@ const authentication = Effect.gen(function* () {
|
|
|
170
171
|
yield* mounted.revokeUnadmitted;
|
|
171
172
|
const sessions = {
|
|
172
173
|
origin: trustedOrigins({ allow: ["https://app.example"], missing: "reject" }),
|
|
173
|
-
provider:
|
|
174
|
+
provider: mounted.admittedSessions((headers) => mounted.auth.api.getSession({ headers })),
|
|
174
175
|
};
|
|
175
176
|
return { ...mounted, sessions };
|
|
176
177
|
});
|
|
@@ -186,7 +187,7 @@ A removal takes effect on the user's next request through `admittedSessions`: th
|
|
|
186
187
|
|
|
187
188
|
`revokeUnadmitted` checks every stored user against the current policy, deletes the sessions of each user it no longer admits and succeeds with `{ users, sessions }`, the number of users and sessions it revoked. Run it at startup, as above, or from an administrative command. It fails with the rule's error or with a `ConfigError`.
|
|
188
189
|
|
|
189
|
-
Without `signIn`, the mount installs no sign-in policy hooks and `revokeUnadmitted` revokes nothing.
|
|
190
|
+
Without `signIn`, the mount installs no sign-in policy hooks and `revokeUnadmitted` revokes nothing. `admittedSessions(lookup)` returns an Effect `SessionProvider`; use it directly as `sessions.provider`. Its policy check runs in the request fiber, preserving request spans, log annotations and interruption. `mounted.sessions` supplies this provider with the mount's roles and the default Better Auth lookup. Supply the application's Config provider to the server Layer so request-time account checks read the same configuration as startup.
|
|
190
191
|
|
|
191
192
|
### Once per feature: identity and typed refusals
|
|
192
193
|
|
|
@@ -221,7 +222,7 @@ The same module exports `loopbackOnly(handler)` for local page routes and `sameO
|
|
|
221
222
|
|
|
222
223
|
`trustedProxyPeer(trustedProxy?)` compiles the guard's proxy address list into an `(address: string) => boolean` predicate. Use it with the transport's remote address when another route needs the same proxy trust decision. It supports the same IP addresses, CIDR ranges and IPv4-mapped IPv6 peers as `appHost`; absent or malformed configuration matches no peer. It does not read forwarded headers.
|
|
223
224
|
|
|
224
|
-
`trustedProxyRanges(trustedProxy?)` returns the equivalent IP addresses and CIDR ranges used by that matcher. Mapped IPv6 addresses and CIDRs become IPv4 entries: `::ffff:127.0.0.0/104` becomes `127.0.0.0/8`, including hexadecimal mapped forms. Broader IPv6 ranges retain both native IPv6 and mapped IPv4 coverage. Missing or malformed configuration returns an empty list. Pass these ranges to a forwarded-header integration after checking the transport with `trustedProxyPeer`.
|
|
225
|
+
`trustedProxyRanges(trustedProxy?)` from `@shivaedev/identity/server/trustedProxyRanges.ts` returns the equivalent IP addresses and CIDR ranges used by that matcher. Mapped IPv6 addresses and CIDRs become IPv4 entries: `::ffff:127.0.0.0/104` becomes `127.0.0.0/8`, including hexadecimal mapped forms. Broader IPv6 ranges retain both native IPv6 and mapped IPv4 coverage. Missing or malformed configuration returns an empty list. Pass these ranges to a forwarded-header integration after checking the transport with `trustedProxyPeer`.
|
|
225
226
|
|
|
226
227
|
Declare expected refusals with the shared tagged error schemas from [`@shivaedev/errors`](https://github.com/ShivaeDev/platform/tree/main/packages/errors#readme). They work with native RPC without authentication middleware.
|
|
227
228
|
|
|
@@ -310,7 +311,7 @@ const mounted = yield* betterAuthMount(authOptions, { roles: Access });
|
|
|
310
311
|
const sessions = { ...mounted.sessions, origin: trustedOrigins({ allow: ["https://app.example.com"], missing: "reject" }) };
|
|
311
312
|
```
|
|
312
313
|
|
|
313
|
-
For another session provider, put `roles: Access` alongside `provider` and `origin` in the host's existing `sessions` policy. The provider must read the current stored role on every invocation. `betterAuthMount`'s returned provider and its existing `/api/auth/get-session` endpoint bypass the cookie cache. That endpoint adds `user.permissions`, an array of `{ name, strength }` grants, and the request-local `SessionUser` exposes the same decoded role and grants. An undeclared stored role fails
|
|
314
|
+
For another session provider, put `roles: Access` alongside `provider` and `origin` in the host's existing `sessions` policy. The provider must read the current stored role on every invocation. `betterAuthMount`'s returned provider and its existing `/api/auth/get-session` endpoint bypass the cookie cache. That endpoint adds `user.permissions`, an array of `{ name, strength }` grants, and the request-local `SessionUser` exposes the same decoded role and grants. An undeclared stored role fails as a defect naming that role. RPC request tracing logs it as a defect; `/api/auth/get-session` returns HTTP 500. Correct the stored role or restore its application declaration. Provider outages remain `AuthUnavailable`.
|
|
314
315
|
|
|
315
316
|
Declare a native middleware service for each required permission and provide its Layer beside the handlers:
|
|
316
317
|
|
|
@@ -328,7 +329,7 @@ const handlers = Tools.toLayer({ tools: () => Effect.map(SessionUser, (user) =>
|
|
|
328
329
|
);
|
|
329
330
|
```
|
|
330
331
|
|
|
331
|
-
The middleware resolves and checks the session on every request before invoking the handler. It provides `Identity` and `SessionUser`, rejects signed-out callers with `Unauthorized`, and rejects missing grants with `Forbidden` in its declared error channel.
|
|
332
|
+
The middleware resolves and checks the session on every request before invoking the handler. It provides `Identity` and `SessionUser`, rejects signed-out callers with `Unauthorized`, and rejects missing grants with `Forbidden` in its declared error channel. Access evaluates an exact permission name: an `any` grant covers an `own` check, while an `own` grant does not cover an `any` check. Open streams recheck their required permission at the session revalidation interval and end with `Forbidden` after its removal.
|
|
332
333
|
|
|
333
334
|
For HTTP routes, use `permissionRoute(sessions, UseTools)` around the handler. It uses the same transport session and Origin policy, returns 401 for missing sessions, 403 for missing grants or refused Origins, and 503 for `AuthUnavailable`. Those rejections carry `Cache-Control: private, no-store`. The handler's response and typed failures pass through unchanged.
|
|
334
335
|
|
|
@@ -345,7 +346,7 @@ const routes = HttpRouter.use((router) =>
|
|
|
345
346
|
);
|
|
346
347
|
```
|
|
347
348
|
|
|
348
|
-
An operation on one record reads that record's owner and uses the application's access policy. With a request-local user, `const { role } = yield* Access.resolve(user.role)` recovers the application's closed role type; `yield* Access.requireAccess({ id: user.id, role }, UseTools, record.ownerId)` then permits an explicit `any` grant or an `own` grant for that owner. Keep these resource decisions in the handler or domain service. Browser interfaces can use `hasPermission(user, permission)` from `@shivaedev/identity/permission.ts` over the client session's grants; the server always resolves its own grants.
|
|
349
|
+
An operation on one record reads that record's owner and uses the application's access policy. With a request-local user, `const { role } = yield* Access.resolve(user.role)` recovers the application's closed role type; `yield* Access.requireAccess({ id: user.id, role }, UseTools, record.ownerId)` then permits an explicit `any` grant or an `own` grant for that owner. Keep these resource decisions in the handler or domain service. Browser interfaces can use `hasPermission(user, permission)` from `@shivaedev/identity/permission.ts` over the client session's grants; the server always resolves its own grants. To enforce a grant in a handler, import `requirePermission` from `@shivaedev/access/requirePermission.ts` and call `yield* requirePermission(yield* SessionUser, permission)`.
|
|
349
350
|
|
|
350
351
|
### Session-scoped contract keys
|
|
351
352
|
|
|
@@ -353,7 +354,9 @@ For self-only features, declare `contract("preferences", { keyScope: "session",
|
|
|
353
354
|
|
|
354
355
|
The host's generated `$changes` handler accepts `{ queries: [{ query: "get", payload: { id: "theme" } }] }`, resolves the declared query dependencies during that subscription invocation, and passes the authenticated scope to the change stream. It does not accept physical subscription keys or a caller-selected scope. Missing request-local `Identity` on a session-scoped subscription is a configuration defect, with no unscoped fallback.
|
|
355
356
|
|
|
356
|
-
`authenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer` and `permissionLayer` run scoped command invalidation inside the authenticated invocation. Successful commands publish their scoped keys after
|
|
357
|
+
`authenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer` and `permissionLayer` run scoped command invalidation inside the authenticated invocation. Successful commands publish their scoped keys after the handler returns and omit keys the handler's transactions already published. Keys that must commit atomically with a write come from the stored model's `bucket()` fields and the repository, rather than command `invalidates`. A rejected transaction publishes no keys.
|
|
358
|
+
|
|
359
|
+
Declared-key publication retries twice, after 50 ms and 100 ms, without rerunning the handler. Exhausted retries preserve the committed result. On a database-backed host, they mark local live streams for Resync and attempt a broadcast Resync on the PostgreSQL change channel. If that broadcast also fails, the server logs that other hosts may remain stale. There is no durable replay: a remote host whose listener remains healthy cannot discover a notification that never reached PostgreSQL. Reconnect or listener recovery reconciles its streams.
|
|
357
360
|
|
|
358
361
|
Hosted applications use `Api.application.toLayer(...)` and let `appHost` own `$changes`. A custom change handler accepts query references and resolves them inside `Stream.unwrap`, after authentication has provided `Identity`:
|
|
359
362
|
|
|
@@ -515,14 +518,17 @@ Import the module that defines the name; there is no package-root entry. Paths b
|
|
|
515
518
|
|
|
516
519
|
| Module | Names and purpose |
|
|
517
520
|
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
518
|
-
| `identity.ts` | `RequestId`, `Identity`, `OptionalIdentity`, `SessionUser`, `SessionUserWithProviderAccounts`: request-local services.
|
|
519
|
-
| `middleware.ts` | `RequestTracing`, `Authenticated`, `AuthenticatedUser`, `AuthenticatedUserWithProviderAccounts`, `MaybeAuthenticated`: native RPC middleware declarations.
|
|
520
|
-
| `
|
|
521
|
+
| `identity.ts` | `RequestId`, `Identity`, `OptionalIdentity`, `SessionUser`, `SessionUserWithProviderAccounts`, `SessionUserSchema`: request-local services and the shared user schema. |
|
|
522
|
+
| `middleware.ts` | `RequestTracing`, `Authenticated`, `AuthenticatedUser`, `AuthenticatedUserWithProviderAccounts`, `MaybeAuthenticated`, `IdentityFailures`: native RPC middleware declarations and their shared failure schema. |
|
|
523
|
+
| `server/providerFailure.ts` | `providerFailure(cause)`: log a redacted provider failure and fail with `AuthUnavailable`. |
|
|
524
|
+
| `permission.ts` | `permissionMiddleware`, `hasPermission`: native permission middleware declarations and predicates over resolved grants. |
|
|
521
525
|
| `server/permissions.ts` | `permissionLayer`, `permissionRoute`: permission middleware Layers and HTTP route guards. |
|
|
522
526
|
| `server/session.ts` | `authenticatedLayer`, `maybeAuthenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer`, `withSessionUser`, `resolveSession`: session middleware implementations and the identity boundary. |
|
|
523
527
|
| `server/adapters/betterAuthSessions.ts` | `betterAuthSessions(getSession, getProviderAccounts?)`: a session provider from Better Auth lookups. |
|
|
524
528
|
| `server/origin.ts` | `trustedOrigins({ allow, missing })`: an exact Origin allowlist. |
|
|
525
|
-
| `server/local.ts` | `localRpcGuard`, `loopbackOnly`, `sameOrigin`, `trustedProxyPeer
|
|
529
|
+
| `server/local.ts` | `localRpcGuard`, `loopbackOnly`, `sameOrigin`, `trustedProxyPeer`: loopback and proxy guards. |
|
|
530
|
+
| `server/trustedProxyRanges.ts` | `trustedProxyRanges(trustedProxy?)`: normalized proxy ranges. |
|
|
531
|
+
| `server/proxyRanges.ts` | `proxyRanges(value)`: parse configured proxy ranges. |
|
|
526
532
|
| `server/transportHeaders.ts` | `transportHeaders(rpcHeaders)`: the headers used for a transport-level decision. |
|
|
527
533
|
| `server/tracing.ts` | `requestTracingLayer({ header?, sensitive? })`: the `RequestTracing` implementation. |
|
|
528
534
|
| `server/sessionKeys.ts` | `resolveChanges`: session-scoped change subscriptions for custom change handlers. |
|
package/dist/identity.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Context, type Effect, type Option } from "effect";
|
|
2
|
-
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
1
|
+
import { Context, type Effect, type Option, Schema } from "effect";
|
|
3
2
|
import type { AuthUnavailable, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
4
3
|
declare const RequestId_base: Context.ServiceClass<RequestId, "@shivaedev/identity/RequestId", string>;
|
|
5
4
|
export declare class RequestId extends RequestId_base {
|
|
@@ -17,13 +16,27 @@ export interface ProviderAccountValue {
|
|
|
17
16
|
readonly accountId: string;
|
|
18
17
|
readonly providerId: string;
|
|
19
18
|
}
|
|
20
|
-
export
|
|
19
|
+
export declare const SessionUserSchema: Schema.Struct<{
|
|
20
|
+
readonly email: Schema.String;
|
|
21
|
+
readonly id: Schema.String;
|
|
22
|
+
readonly name: Schema.String;
|
|
23
|
+
readonly permissions: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
24
|
+
readonly name: Schema.String;
|
|
25
|
+
readonly strength: Schema.Literals<readonly ["own", "any"]>;
|
|
26
|
+
}>>>;
|
|
27
|
+
readonly role: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
28
|
+
}>;
|
|
29
|
+
export type SessionUserValue = typeof SessionUserSchema.Type;
|
|
30
|
+
declare const SessionUser_base: Context.ServiceClass<SessionUser, "@shivaedev/identity/SessionUser", {
|
|
21
31
|
readonly email: string;
|
|
32
|
+
readonly id: string;
|
|
22
33
|
readonly name: string;
|
|
23
|
-
readonly permissions?: readonly
|
|
34
|
+
readonly permissions?: readonly {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly strength: "any" | "own";
|
|
37
|
+
}[];
|
|
24
38
|
readonly role?: string | null | undefined;
|
|
25
|
-
}
|
|
26
|
-
declare const SessionUser_base: Context.ServiceClass<SessionUser, "@shivaedev/identity/SessionUser", SessionUserValue>;
|
|
39
|
+
}>;
|
|
27
40
|
export declare class SessionUser extends SessionUser_base {
|
|
28
41
|
}
|
|
29
42
|
export interface SessionUserWithProviderAccountsValue extends SessionUserValue {
|
package/dist/identity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;;AACnF,qBAAa,SAAU,SAAQ,cAAqE;CAAG;AACvG,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACpB;;AACD,qBAAa,QAAS,SAAQ,aAA0E;CAAG;;AAC3G,qBAAa,gBAAiB,SAAQ,qBAAyG;CAAG;AAClJ,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AACD,eAAO,MAAM,iBAAiB;;;;;;;;;EAM5B,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;;;;;;;;;;;AAC7D,qBAAa,WAAY,SAAQ,gBAAmF;CAAG;AACvH,MAAM,WAAW,oCAAqC,SAAQ,gBAAgB;IAC7E,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,oBAAoB,EAAE,EAAE,eAAe,GAAG,YAAY,CAAC,CAAC;CAC1G;;AACD,qBAAa,+BAAgC,SAAQ,oCAEpD;CAAG"}
|
package/dist/identity.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { Context } from "effect";
|
|
1
|
+
import { Context, Schema } from "effect";
|
|
2
|
+
import { Permission } from "@shivaedev/access/permission.ts";
|
|
2
3
|
export class RequestId extends Context.Service()("@shivaedev/identity/RequestId") {
|
|
3
4
|
}
|
|
4
5
|
export class Identity extends Context.Service()("@shivaedev/identity/Identity") {
|
|
5
6
|
}
|
|
6
7
|
export class OptionalIdentity extends Context.Service()("@shivaedev/identity/OptionalIdentity") {
|
|
7
8
|
}
|
|
9
|
+
export const SessionUserSchema = Schema.Struct({
|
|
10
|
+
email: Schema.String,
|
|
11
|
+
id: Schema.String,
|
|
12
|
+
name: Schema.String,
|
|
13
|
+
permissions: Schema.optionalKey(Schema.Array(Permission)),
|
|
14
|
+
role: Schema.optional(Schema.NullOr(Schema.String)),
|
|
15
|
+
});
|
|
8
16
|
export class SessionUser extends Context.Service()("@shivaedev/identity/SessionUser") {
|
|
9
17
|
}
|
|
10
18
|
export class SessionUserWithProviderAccounts extends Context.Service()("@shivaedev/identity/SessionUserWithProviderAccounts") {
|
package/dist/identity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,MAAM,OAAO,SAAU,SAAQ,OAAO,CAAC,OAAO,EAAqB,CAAC,+BAA+B,CAAC;CAAG;AAIvG,MAAM,OAAO,QAAS,SAAQ,OAAO,CAAC,OAAO,EAA2B,CAAC,8BAA8B,CAAC;CAAG;AAC3G,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,OAAO,EAAkD,CAAC,sCAAsC,CAAC;CAAG;AAKlJ,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CACnD,CAAC,CAAC;AAEH,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAAiC,CAAC,iCAAiC,CAAC;CAAG;AAIvH,MAAM,OAAO,+BAAgC,SAAQ,OAAO,CAAC,OAAO,EAAyE,CAC5I,qDAAqD,CACrD;CAAG"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { RpcMiddleware } from "effect/rpc";
|
|
|
3
3
|
import { MissingReadPolicy, QueryReadDenied } from "@shivaedev/contract/readPolicyErrors.ts";
|
|
4
4
|
import { AuthUnavailable, Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
5
5
|
import type { Identity, OptionalIdentity, RequestId, SessionUser, SessionUserWithProviderAccounts } from "./identity.ts";
|
|
6
|
+
export declare const IdentityFailures: Schema.Union<readonly [typeof Unauthorized, typeof AuthUnavailable, typeof Forbidden, typeof MissingReadPolicy, typeof QueryReadDenied]>;
|
|
7
|
+
export type IdentityFailures = typeof IdentityFailures.Type;
|
|
6
8
|
declare const RequestTracing_base: RpcMiddleware.ServiceClass<RequestTracing, "@shivaedev/identity/RequestTracing", RequestId, Schema.Never, never, never, false>;
|
|
7
9
|
export declare class RequestTracing extends RequestTracing_base {
|
|
8
10
|
}
|
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AACzH,eAAO,MAAM,gBAAgB,0IAA+F,CAAC;AAC7H,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAC;;AAE5D,qBAAa,cAAe,SAAQ,mBAKK;CAAG;;AAC5C,qBAAa,aAAc,SAAQ,kBAOjC;CAAG;;AACL,qBAAa,kBAAmB,SAAQ,uBAOtC;CAAG;;AACL,qBAAa,iBAAkB,SAAQ,sBAOrC;CAAG;;AACL,qBAAa,qCAAsC,SAAQ,0CAKzD;CAAG"}
|
package/dist/middleware.js
CHANGED
|
@@ -2,22 +2,23 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { RpcMiddleware } from "effect/rpc";
|
|
3
3
|
import { MissingReadPolicy, QueryReadDenied } from "@shivaedev/contract/readPolicyErrors.ts";
|
|
4
4
|
import { AuthUnavailable, Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
5
|
+
export const IdentityFailures = Schema.Union([Unauthorized, AuthUnavailable, Forbidden, MissingReadPolicy, QueryReadDenied]);
|
|
5
6
|
export class RequestTracing extends RpcMiddleware.Service()("@shivaedev/identity/RequestTracing") {
|
|
6
7
|
}
|
|
7
8
|
export class Authenticated extends RpcMiddleware.Service()("@shivaedev/identity/Authenticated", {
|
|
8
|
-
error:
|
|
9
|
+
error: IdentityFailures,
|
|
9
10
|
}) {
|
|
10
11
|
}
|
|
11
12
|
export class MaybeAuthenticated extends RpcMiddleware.Service()("@shivaedev/identity/MaybeAuthenticated", {
|
|
12
|
-
error:
|
|
13
|
+
error: IdentityFailures,
|
|
13
14
|
}) {
|
|
14
15
|
}
|
|
15
16
|
export class AuthenticatedUser extends RpcMiddleware.Service()("@shivaedev/identity/AuthenticatedUser", {
|
|
16
|
-
error:
|
|
17
|
+
error: IdentityFailures,
|
|
17
18
|
}) {
|
|
18
19
|
}
|
|
19
20
|
export class AuthenticatedUserWithProviderAccounts extends RpcMiddleware.Service()("@shivaedev/identity/AuthenticatedUserWithProviderAccounts", {
|
|
20
|
-
error:
|
|
21
|
+
error: IdentityFailures,
|
|
21
22
|
}) {
|
|
22
23
|
}
|
|
23
24
|
//# sourceMappingURL=middleware.js.map
|
package/dist/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEzF,MAAM,
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEzF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC,CAAC;AAG7H,MAAM,OAAO,cAAe,SAAQ,aAAa,CAAC,OAAO,EAKtD,CAAC,oCAAoC,CAAC;CAAG;AAC5C,MAAM,OAAO,aAAc,SAAQ,aAAa,CAAC,OAAO,EAKrD,CAAC,mCAAmC,EAAE;IACxC,KAAK,EAAE,gBAAgB;CACvB,CAAC;CAAG;AACL,MAAM,OAAO,kBAAmB,SAAQ,aAAa,CAAC,OAAO,EAK1D,CAAC,wCAAwC,EAAE;IAC7C,KAAK,EAAE,gBAAgB;CACvB,CAAC;CAAG;AACL,MAAM,OAAO,iBAAkB,SAAQ,aAAa,CAAC,OAAO,EAKzD,CAAC,uCAAuC,EAAE;IAC5C,KAAK,EAAE,gBAAgB;CACvB,CAAC;CAAG;AACL,MAAM,OAAO,qCAAsC,SAAQ,aAAa,CAAC,OAAO,EAG7E,CAAC,2DAA2D,EAAE;IAChE,KAAK,EAAE,gBAAgB;CACvB,CAAC;CAAG"}
|
package/dist/permission.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
1
|
import { RpcMiddleware } from "effect/rpc";
|
|
3
|
-
import type
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { type Permission } from "@shivaedev/access/permission.ts";
|
|
3
|
+
import type { Identity, SessionUser, SessionUserValue } from "./identity.ts";
|
|
4
|
+
export declare function permissionMiddleware<TSelf>(): <const TName extends string>(name: TName, permission: Permission) => RpcMiddleware.ServiceClass<TSelf, TName, Identity | SessionUser, import("effect/Schema").Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
|
|
5
|
+
permission: {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly strength: "any" | "own";
|
|
8
|
+
};
|
|
9
9
|
};
|
|
10
10
|
export declare function hasPermission(user: Pick<SessionUserValue, "id" | "permissions">, permission: Permission): boolean;
|
|
11
|
-
export declare function requirePermission(permission: Permission): Effect.Effect<SessionUserValue, Forbidden, SessionUser>;
|
|
12
11
|
//# sourceMappingURL=permission.d.ts.map
|
package/dist/permission.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG7E,wBAAgB,oBAAoB,CAAC,KAAK,MACjC,KAAK,CAAC,KAAK,SAAS,MAAM,QAAQ,KAAK,cAAc,UAAU;;;;;EAEvE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,aAAa,CAAC,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAEjH"}
|
package/dist/permission.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
1
|
import { RpcMiddleware } from "effect/rpc";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { SessionUser } from "./identity.js";
|
|
6
|
-
const Failures = Schema.Union([Unauthorized, AuthUnavailable, Forbidden, MissingReadPolicy, QueryReadDenied]);
|
|
2
|
+
import { hasPermission as evaluateGrant } from "@shivaedev/access/permission.ts";
|
|
3
|
+
import { IdentityFailures } from "./middleware.js";
|
|
7
4
|
export function permissionMiddleware() {
|
|
8
|
-
return (name, permission) => Object.assign(RpcMiddleware.Service()(name, { error:
|
|
5
|
+
return (name, permission) => Object.assign(RpcMiddleware.Service()(name, { error: IdentityFailures }), { permission });
|
|
9
6
|
}
|
|
10
7
|
export function hasPermission(user, permission) {
|
|
11
|
-
return user.permissions
|
|
12
|
-
}
|
|
13
|
-
export function requirePermission(permission) {
|
|
14
|
-
return Effect.flatMap(SessionUser, (user) => hasPermission(user, permission)
|
|
15
|
-
? Effect.succeed(user)
|
|
16
|
-
: Effect.fail(new Forbidden({ message: `Permission required: ${permission.name} (${permission.strength})` })));
|
|
8
|
+
return evaluateGrant(user.permissions, permission);
|
|
17
9
|
}
|
|
18
10
|
//# sourceMappingURL=permission.js.map
|
package/dist/permission.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.js","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"permission.js","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,aAAa,IAAI,aAAa,EAAmB,MAAM,iCAAiC,CAAC;AAElG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,UAAU,oBAAoB;IACnC,OAAO,CAA6B,IAAW,EAAE,UAAsB,EAAE,EAAE,CAC1E,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,EAA+C,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AACzI,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAkD,EAAE,UAAsB;IACvG,OAAO,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { AuthUnavailable, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
2
|
+
import { type AuthUnavailable, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
3
3
|
import type { ProviderAccountValue } from "#identity.ts";
|
|
4
4
|
import type { SessionProvider, SessionShape } from "#server/session.ts";
|
|
5
5
|
export type GetSession<TSession extends SessionShape> = (headers: globalThis.Headers) => Promise<TSession | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"betterAuthSessions.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"betterAuthSessions.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAGnD,OAAO,EAAE,KAAK,eAAe,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxE,MAAM,MAAM,UAAU,CAAC,QAAQ,SAAS,YAAY,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAClH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,KAAK,OAAO,CAAC,SAAS,oBAAoB,EAAE,CAAC,CAAC;AAC5G,MAAM,MAAM,2BAA2B,CAAC,QAAQ,SAAS,YAAY,IAAI,QAAQ,GAAG;IACnF,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG;QAAE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,oBAAoB,EAAE,EAAE,eAAe,GAAG,YAAY,CAAC,CAAA;KAAE,CAAC;CAChJ,CAAC;AACF,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;AAC/H,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,YAAY,EAC/D,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,EAChC,mBAAmB,EAAE,mBAAmB,GACtC,eAAe,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { Effect, Option, Predicate } from "effect";
|
|
2
2
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
function unavailable(cause) {
|
|
6
|
-
return Effect.andThen(Effect.logError("Authentication provider failed", redact(cause)), Effect.fail(new AuthUnavailable({ message: "Authentication is temporarily unavailable" })));
|
|
7
|
-
}
|
|
3
|
+
import { Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import { providerFailure } from "#server/providerFailure.ts";
|
|
8
5
|
export function betterAuthSessions(getSession, getProviderAccounts) {
|
|
9
6
|
const betterAuthSession = Effect.fn("PlatformRpc.betterAuthSession")(function* (headers) {
|
|
10
7
|
const transport = new globalThis.Headers(headers);
|
|
11
|
-
const session = yield* Effect.tryPromise(() => getSession(transport)).pipe(Effect.catch((error) =>
|
|
8
|
+
const session = yield* Effect.tryPromise(() => getSession(transport)).pipe(Effect.catch((error) => providerFailure(error.cause)));
|
|
12
9
|
if (session === null || getProviderAccounts === undefined) {
|
|
13
10
|
return Option.fromNullishOr(session);
|
|
14
11
|
}
|
|
@@ -17,7 +14,7 @@ export function betterAuthSessions(getSession, getProviderAccounts) {
|
|
|
17
14
|
try: () => getProviderAccounts(transport),
|
|
18
15
|
}).pipe(Effect.catch((cause) => Predicate.hasProperty(cause, "statusCode") && cause.statusCode === HttpStatus.fromLiteral("Unauthorized")
|
|
19
16
|
? Effect.fail(new Unauthorized({ message: "Authentication required" }))
|
|
20
|
-
:
|
|
17
|
+
: providerFailure(cause)));
|
|
21
18
|
return Option.some({ ...session, user: { ...session.user, providerAccounts } });
|
|
22
19
|
});
|
|
23
20
|
return { get: betterAuthSession };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"betterAuthSessions.js","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"betterAuthSessions.js","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAwB,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAY7D,MAAM,UAAU,kBAAkB,CAAgC,UAAgC,EAAE,mBAAyC;IAC5I,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,+BAA+B,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAwB;QACvG,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClI,IAAI,OAAO,KAAK,IAAI,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC3D,OAAO,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QACD,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU,CAAC;YAC1C,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;YACvB,GAAG,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC;SACzC,CAAC,CAAC,IAAI,CACN,MAAM,CAAC,KAAK,CACX,CAAC,KAAK,EAAwD,EAAE,CAC/D,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,WAAW,CAAC,cAAc,CAAC;YACxG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC,CAAC;YACvE,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAC1B,CACD,CAAC;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type GetSession } from "#server/adapters/betterAuthSessions.ts";
|
|
2
|
+
import type { SessionProvider, SessionShape } from "#server/session.ts";
|
|
3
|
+
import { type BearerSessionsOptions } from "./bearerSessions.ts";
|
|
4
|
+
import { type PolicyStorage, type SignInGate } from "./signInGate.ts";
|
|
5
|
+
interface SessionStorage extends PolicyStorage {
|
|
6
|
+
readonly authCookies: {
|
|
7
|
+
readonly sessionToken: {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function admittedSessions<E>(gate: SignInGate<E>, storage: () => Promise<SessionStorage>, bearerSessions?: BearerSessionsOptions): <TSession extends SessionShape>(getSession: GetSession<TSession>) => SessionProvider<TSession>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=admittedSessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admittedSessions.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/admittedSessions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAE7F,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,KAAK,qBAAqB,EAAkB,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEnF,UAAU,cAAe,SAAQ,aAAa;IAC7C,QAAQ,CAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,YAAY,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAC3E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC,EAAE,qBAAqB,IAC9H,QAAQ,SAAS,YAAY,cAAc,UAAU,CAAC,QAAQ,CAAC,KAAG,eAAe,CAAC,QAAQ,CAAC,CAwBnG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
|
+
import { Headers as HttpHeaders } from "effect/http";
|
|
3
|
+
import { betterAuthSessions } from "#server/adapters/betterAuthSessions.ts";
|
|
4
|
+
import { providerFailure } from "#server/providerFailure.ts";
|
|
5
|
+
import { sessionHeaders } from "./bearerSessions.js";
|
|
6
|
+
import { fromStorage } from "./signInGate.js";
|
|
7
|
+
export function admittedSessions(gate, storage, bearerSessions) {
|
|
8
|
+
return (getSession) => {
|
|
9
|
+
const provider = betterAuthSessions(getSession);
|
|
10
|
+
return {
|
|
11
|
+
get: Effect.fnUntraced(function* (headers) {
|
|
12
|
+
const auth = gate.active || bearerSessions !== undefined ? yield* fromStorage(storage) : undefined;
|
|
13
|
+
const selected = bearerSessions === undefined || auth === undefined
|
|
14
|
+
? headers
|
|
15
|
+
: HttpHeaders.fromInput(sessionHeaders(new Headers(headers), auth.authCookies.sessionToken.name));
|
|
16
|
+
const session = yield* provider.get(selected);
|
|
17
|
+
if (!gate.active || Option.isNone(session) || auth === undefined) {
|
|
18
|
+
return session;
|
|
19
|
+
}
|
|
20
|
+
const userId = session.value.user.id;
|
|
21
|
+
const admitted = yield* gate.admitsUser(auth, userId).pipe(Effect.catch(providerFailure));
|
|
22
|
+
if (admitted) {
|
|
23
|
+
return session;
|
|
24
|
+
}
|
|
25
|
+
yield* fromStorage(() => auth.internalAdapter.deleteUserSessions(userId));
|
|
26
|
+
yield* Effect.logInfo("The sign-in policy revoked a user's sessions").pipe(Effect.annotateLogs({ userId }));
|
|
27
|
+
return Option.none();
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=admittedSessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admittedSessions.js","sourceRoot":"","sources":["../../../src/server/better-auth/admittedSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAmB,MAAM,wCAAwC,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAA8B,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,WAAW,EAAuC,MAAM,iBAAiB,CAAC;AAMnF,MAAM,UAAU,gBAAgB,CAAI,IAAmB,EAAE,OAAsC,EAAE,cAAsC;IACtI,OAAO,CAAgC,UAAgC,EAA6B,EAAE;QACrG,MAAM,QAAQ,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAChD,OAAO;YACN,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAO;gBACxC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,IAAI,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBACnG,MAAM,QAAQ,GACb,cAAc,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;oBACjD,CAAC,CAAC,OAAO;oBACT,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;gBACpG,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAC9C,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAClE,OAAO,OAAO,CAAC;gBAChB,CAAC;gBACD,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;gBAC1F,IAAI,QAAQ,EAAE,CAAC;oBACd,OAAO,OAAO,CAAC;gBAChB,CAAC;gBACD,KAAK,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC1E,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,8CAA8C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;gBAC5G,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;YACtB,CAAC,CAAC;SACF,CAAC;IACH,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientIp.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/clientIp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"clientIp.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/clientIp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAErD,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C,aASiB,iBAAiB,CAAC,iBAAiB,OAAO,OAAO,UAalE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getIP } from "better-auth/api";
|
|
2
2
|
import { Option } from "effect";
|
|
3
|
-
import { trustedProxyPeer
|
|
3
|
+
import { trustedProxyPeer } from "#server/local.ts";
|
|
4
|
+
import { trustedProxyRanges } from "#server/trustedProxyRanges.ts";
|
|
4
5
|
export const PEER_IP_HEADER = "x-platform-client-ip";
|
|
5
6
|
export function clientIpHeaders(options) {
|
|
6
7
|
const trustedPeer = trustedProxyPeer(options.trustedProxy);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientIp.js","sourceRoot":"","sources":["../../../src/server/better-auth/clientIp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"clientIp.js","sourceRoot":"","sources":["../../../src/server/better-auth/clientIp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,UAAU,eAAe,CAAC,OAI/B;IACA,MAAM,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG;QAChB,SAAS,EAAE;YACV,gBAAgB,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC;YAC1C,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;YAC/E,cAAc,EAAE,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC;SACxD;KACD,CAAC;IACF,OAAO,CAAC,OAA4C,EAAE,GAAY,EAAE,EAAE;QACrE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9D,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACtC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,OAAO,GAAG,WAAW,IAAI,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC5E,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC3B,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -2,18 +2,15 @@ import { type BetterAuthOptions } from "better-auth";
|
|
|
2
2
|
import { Config, Effect, Redacted } from "effect";
|
|
3
3
|
import { Pool, type PoolConfig } from "pg";
|
|
4
4
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
5
|
-
import type { GetSession } from "#server/adapters/betterAuthSessions.ts";
|
|
6
5
|
import { type BearerSessionsOptions } from "#server/better-auth/bearerSessions.ts";
|
|
7
|
-
import { type RevokeUnadmitted } from "#server/better-auth/revokeUnadmitted.ts";
|
|
8
6
|
import { type SignInPolicy } from "#server/better-auth/signInGate.ts";
|
|
9
|
-
import type { SessionShape } from "#server/session.ts";
|
|
10
7
|
export interface BetterAuthMountOptions<E = never, R = never> {
|
|
11
8
|
readonly bearerSessions?: BearerSessionsOptions | undefined;
|
|
12
9
|
readonly roles?: RoleSet;
|
|
13
10
|
readonly signIn?: SignInPolicy<E, R> | undefined;
|
|
14
11
|
}
|
|
15
12
|
export declare const betterAuthMount: <const TOptions extends BetterAuthOptions, E = never, R = never>(options: TOptions, mount?: BetterAuthMountOptions<E, R> | undefined) => Effect.Effect<{
|
|
16
|
-
admittedSessions: <TSession extends SessionShape>(getSession: GetSession<TSession>) =>
|
|
13
|
+
admittedSessions: <TSession extends import("../session.ts").SessionShape>(getSession: import("../adapters/betterAuthSessions.ts").GetSession<TSession>) => import("../session.ts").SessionProvider<TSession>;
|
|
17
14
|
auth: import("better-auth").Auth<TOptions & {
|
|
18
15
|
advanced: {
|
|
19
16
|
disableCSRFCheck?: boolean | undefined;
|
|
@@ -247,16 +244,20 @@ export declare const betterAuthMount: <const TOptions extends BetterAuthOptions,
|
|
|
247
244
|
};
|
|
248
245
|
}) | undefined;
|
|
249
246
|
}>;
|
|
250
|
-
revokeUnadmitted:
|
|
247
|
+
revokeUnadmitted: Effect.Effect<import("#server/better-auth/revokeUnadmitted.ts").RevokedSessions, E | import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Config.ConfigError, never>;
|
|
251
248
|
routes: import("effect/Layer").Layer<never, never, import("effect/http/HttpRouter").HttpRouter>;
|
|
252
249
|
sessions: {
|
|
253
250
|
roles?: RoleSet;
|
|
254
|
-
provider: import("
|
|
251
|
+
provider: import("../session.ts").SessionProvider<{
|
|
255
252
|
readonly user: {
|
|
256
253
|
readonly email: string;
|
|
257
254
|
readonly id: string;
|
|
258
255
|
readonly name: string;
|
|
259
|
-
readonly
|
|
256
|
+
readonly permissions?: readonly {
|
|
257
|
+
readonly name: string;
|
|
258
|
+
readonly strength: "any" | "own";
|
|
259
|
+
}[];
|
|
260
|
+
readonly role?: string | null | undefined;
|
|
260
261
|
};
|
|
261
262
|
}>;
|
|
262
263
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAmB,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAmB,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,KAAK,qBAAqB,EAAsB,MAAM,uCAAuC,CAAC;AAKvG,OAAO,EAAsB,KAAK,YAAY,EAAc,MAAM,mCAAmC,CAAC;AAKtG,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK;IAC3D,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;CACjD;AAED,eAAO,MAAM,eAAe,SAA0D,QAAQ,SAAS,iBAAiB,EAAE,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDA6DpI,CAAC;AAEH,eAAO,MAAM,YAAY,kKAgCvB,CAAC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { betterAuth } from "better-auth";
|
|
2
2
|
import { Config, Effect, Option, Redacted } from "effect";
|
|
3
3
|
import { Pool } from "pg";
|
|
4
|
-
import {
|
|
4
|
+
import { withBearerSessions } from "#server/better-auth/bearerSessions.ts";
|
|
5
5
|
import { PEER_IP_HEADER } from "#server/better-auth/clientIp.ts";
|
|
6
6
|
import { memoryRateLimit } from "#server/better-auth/memoryRateLimit.ts";
|
|
7
7
|
import { mountRoutes } from "#server/better-auth/mountRoutes.ts";
|
|
8
8
|
import { revokeUnadmitted } from "#server/better-auth/revokeUnadmitted.ts";
|
|
9
9
|
import { signInGate } from "#server/better-auth/signInGate.ts";
|
|
10
10
|
import { signInPolicyOptions } from "#server/better-auth/signInPolicy.ts";
|
|
11
|
+
import { admittedSessions } from "./admittedSessions.js";
|
|
11
12
|
import { mountedSessions } from "./mountedSessions.js";
|
|
12
13
|
export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* (options, mount = {}) {
|
|
13
14
|
const secret = options.secret ?? Redacted.value(yield* Config.Redacted("BETTER_AUTH_SECRET"));
|
|
@@ -59,30 +60,11 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* (
|
|
|
59
60
|
roles: mount.roles,
|
|
60
61
|
trustedProxy,
|
|
61
62
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return getSession;
|
|
65
|
-
}
|
|
66
|
-
return (headers) => run(Effect.gen(function* () {
|
|
67
|
-
const { authCookies } = yield* Effect.promise(() => auth.$context);
|
|
68
|
-
const selected = mount.bearerSessions === undefined ? headers : sessionHeaders(headers, authCookies.sessionToken.name);
|
|
69
|
-
const session = yield* Effect.tryPromise(() => getSession(selected));
|
|
70
|
-
if (!gate.active || session === null) {
|
|
71
|
-
return session;
|
|
72
|
-
}
|
|
73
|
-
const storage = yield* Effect.tryPromise(() => auth.$context);
|
|
74
|
-
if (yield* gate.admitsUser(storage, session.user.id)) {
|
|
75
|
-
return session;
|
|
76
|
-
}
|
|
77
|
-
yield* Effect.tryPromise(() => storage.internalAdapter.deleteUserSessions(session.user.id));
|
|
78
|
-
yield* Effect.logInfo("The sign-in policy revoked a user's sessions").pipe(Effect.annotateLogs({ userId: session.user.id }));
|
|
79
|
-
return null;
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
const revoke = Effect.provideContext(revokeUnadmitted(gate, () => auth.$context), context);
|
|
63
|
+
const admit = admittedSessions(gate, () => auth.$context, mount.bearerSessions);
|
|
64
|
+
const revoke = revokeUnadmitted(gate, () => auth.$context);
|
|
83
65
|
const lookupSession = Reflect.get(auth.api, "getSession");
|
|
84
|
-
const sessions = mountedSessions(
|
|
85
|
-
return { admittedSessions, auth, revokeUnadmitted: revoke, routes: authRoutes, sessions };
|
|
66
|
+
const sessions = mountedSessions(lookupSession, admit, mount.roles);
|
|
67
|
+
return { admittedSessions: admit, auth, revokeUnadmitted: revoke, routes: authRoutes, sessions };
|
|
86
68
|
});
|
|
87
69
|
export const authDatabase = Effect.fn("Platform.authDatabase")(function* (url, options = {}) {
|
|
88
70
|
const clients = new Set();
|