@shivaedev/identity 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +26 -6
  3. package/dist/server/better-auth/adapters/storedRoleOptions.d.ts +6 -0
  4. package/dist/server/better-auth/adapters/storedRoleOptions.d.ts.map +1 -0
  5. package/dist/server/better-auth/adapters/storedRoleOptions.js +16 -0
  6. package/dist/server/better-auth/adapters/storedRoleOptions.js.map +1 -0
  7. package/dist/server/better-auth/migrate.d.ts +6 -0
  8. package/dist/server/better-auth/migrate.d.ts.map +1 -0
  9. package/dist/server/better-auth/migrate.js +19 -0
  10. package/dist/server/better-auth/migrate.js.map +1 -0
  11. package/dist/server/better-auth/mount.d.ts +7 -3
  12. package/dist/server/better-auth/mount.d.ts.map +1 -1
  13. package/dist/server/better-auth/mount.js +4 -3
  14. package/dist/server/better-auth/mount.js.map +1 -1
  15. package/dist/server/better-auth/mountRoutes.d.ts.map +1 -1
  16. package/dist/server/better-auth/mountRoutes.js +1 -1
  17. package/dist/server/better-auth/mountRoutes.js.map +1 -1
  18. package/dist/server/better-auth/sessionPermissions.d.ts +2 -1
  19. package/dist/server/better-auth/sessionPermissions.d.ts.map +1 -1
  20. package/dist/server/better-auth/sessionPermissions.js.map +1 -1
  21. package/dist/server/better-auth/testDatabase.d.ts +11 -0
  22. package/dist/server/better-auth/testDatabase.d.ts.map +1 -1
  23. package/dist/server/better-auth/testDatabase.js +10 -0
  24. package/dist/server/better-auth/testDatabase.js.map +1 -1
  25. package/dist/server/lookupSession.d.ts +2 -2
  26. package/dist/server/lookupSession.d.ts.map +1 -1
  27. package/dist/server/resolveRole.d.ts +2 -1
  28. package/dist/server/resolveRole.d.ts.map +1 -1
  29. package/dist/server/resolveRole.js +4 -0
  30. package/dist/server/resolveRole.js.map +1 -1
  31. package/package.json +7 -7
  32. package/src/server/better-auth/adapters/storedRoleOptions.ts +21 -0
  33. package/src/server/better-auth/migrate.ts +23 -0
  34. package/src/server/better-auth/mount.ts +6 -6
  35. package/src/server/better-auth/mountRoutes.ts +8 -1
  36. package/src/server/better-auth/sessionPermissions.ts +2 -1
  37. package/src/server/better-auth/testDatabase.ts +11 -0
  38. package/src/server/resolveRole.ts +7 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0 - 2026-10-31
4
+
5
+ ### Added
6
+
7
+ - `migrateBetterAuth` runs Better Auth schema migrations using the database from Effect's SQL service. Applications pass auth configuration without a database pool.
8
+ - Generated applications mount roles through identity, migrate the stored default through a numbered migration, and bootstrap the first owner through `assignRole`.
9
+ - Declare the user role field and its sign-up default through identity, and adopt existing users with `migrateBetterAuth(options, { defaultRole })` without an application backfill. Fresh and upgraded PostgreSQL schemas have the same non-null text column and database default.
10
+ - Let identity's database story kit migrate schemas with or without roles, inspect the stored role column and user roles, and model a missing role.
11
+
12
+ ### Fixed
13
+
14
+ - Generated applications start with no quality baseline and rely on the jobs package’s peer installation of `pg-boss`.
15
+ - Loaded editors construct their form from the supplied row without an unreachable synchronous guard.
16
+ - Refuse missing stored roles with `Forbidden` and log the migration fix instead of failing requests with a defect.
17
+
18
+ ### Breaking
19
+
20
+ - `registerAdmin` reports missing or extra page handlers as defects when its handler Layer is built. Consumers that catch synchronous registration errors must instead observe Layer acquisition failures.
21
+ - Pass `defaultRole` alongside `roles` to `betterAuthMount`. Remove application-owned role `additionalFields` and Better Auth's `admin()` plugin if it was only supplying roles. Add and run a numbered `migrateBetterAuth(options, { defaultRole })` migration before deploying, then bootstrap administrators through `assignRole`.
22
+
3
23
  ## 0.11.1 - 2026-10-31
4
24
 
5
25
  ### Changed
package/README.md CHANGED
@@ -107,7 +107,7 @@ const authentication = Effect.gen(function* () {
107
107
  });
108
108
  ```
109
109
 
110
- `betterAuthDatabase()` reads the application’s `SqlClient` and reserves connections from its PostgreSQL pool. Build it inside `appHost`’s `application` Effect, or provide sql’s `postgresLayer` for a standalone process. Set `maxConnections` and `applicationName` on the application SQL Layer. The adapter also works with Better Auth’s `getMigrations`; create it inside a SQL transaction when auth writes must commit or roll back with application writes. The application SQL Layer owns shutdown.
110
+ `betterAuthDatabase()` reads the application’s `SqlClient` and reserves connections from its PostgreSQL pool. Build it inside `appHost`’s `application` Effect, or provide sql’s `postgresLayer` for a standalone process. Set `maxConnections` and `applicationName` on the application SQL Layer. Use `migrateBetterAuth(options)` from `@shivaedev/identity/server/better-auth/migrate.ts` for the auth schema migration. It takes Better Auth options without a database and reads the SQL service itself. Create the database adapter inside a SQL transaction when auth writes must commit or roll back with application writes. The application SQL Layer owns shutdown.
111
111
 
112
112
  Run this Effect in the host's scope; the application SQL Layer manages its connections. A rejected auth handler returns HTTP 503 with `Authentication is temporarily unavailable`.
113
113
 
@@ -137,7 +137,7 @@ For email sign-in through `appHost`, the session record's `ipAddress` follows th
137
137
 
138
138
  ### Role assignments
139
139
 
140
- Pass `{ roles: AppAccess }` as the second argument to `betterAuthMount`. Identity adds `/admin/set-role`, `/admin/update-user` and `/admin/create-user` to the disabled HTTP paths and sets the Better Auth admin plugin's `adminRoles` to `[]`. Existing disabled paths remain in effect. The admin Users page remains the application path for role changes.
140
+ Pass `{ defaultRole: "member", roles: AppAccess }` as the second argument to `betterAuthMount`. Identity adds `/admin/set-role`, `/admin/update-user` and `/admin/create-user` to the disabled HTTP paths and sets the Better Auth admin plugin's `adminRoles` to `[]`. Existing disabled paths remain in effect. The admin Users page remains the application path for role changes.
141
141
 
142
142
  Seeds and trusted operator commands use the same transactional write and last-role-assigner guard as the Users page:
143
143
 
@@ -350,11 +350,31 @@ import { betterAuthMount } from "@shivaedev/identity/server/better-auth/mount.ts
350
350
 
351
351
  const UseTools = permission("tools.use");
352
352
  const Access = roleSet(role("member", []), role("operator", [UseTools]));
353
- const mounted = yield* betterAuthMount(authOptions, { roles: Access });
353
+ const mounted = yield* betterAuthMount(authOptions, { defaultRole: "member", roles: Access });
354
354
  const sessions = { ...mounted.sessions, origin: trustedOrigins({ allow: ["https://app.example.com"], missing: "reject" }) };
355
355
  ```
356
356
 
357
- 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`.
357
+ 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. A missing or null stored role refuses access with `Forbidden` (HTTP 403 at the session endpoint) and logs the fix: run `migrateBetterAuth` with `defaultRole`, then use `assignRole` for administrators. An undeclared non-null 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`.
358
+
359
+ ### Adopting stored roles with existing users
360
+
361
+ Identity declares `user.additionalFields.role` when the mount has `roles` and `defaultRole`. Choose a default from your application's role set, such as `member`. It is a required string and cannot be supplied by sign-up input. No `additionalFields` entry or Better Auth `admin()` plugin is needed.
362
+ 1. Add a numbered application migration that calls `migrateBetterAuth(authOptions, { defaultRole: "member" })`. Run it before deploying the mount with roles. PostgreSQL fills existing users when the column is added; identity also fills null roles when adopting a nullable role column. Both fresh and upgraded schemas finish with a `text NOT NULL DEFAULT 'member'` column. The migration keeps existing non-null roles.
363
+ 2. Mount with `betterAuthMount(authOptions, { defaultRole: "member", roles: Access })`, using the same default as the migration. New users get that role. Remove any app-owned role field configuration and the admin plugin if you used it only for roles.
364
+ 3. In a trusted server-side bootstrap process, call `assignRole(Access, existingUserId, "admin")` to make the first administrator. Provide the application's SQL Layer and Effect Reactivity, as for other role changes. `Access` must declare `admin` with the permissions that administrator needs, including `AssignRoles` to manage other users. Do not expose the bootstrap process as an unauthenticated endpoint.
365
+
366
+ ```ts
367
+ import { assignRole } from "@shivaedev/identity/server/better-auth/assignRole.ts";
368
+ import { migrateBetterAuth } from "@shivaedev/identity/server/better-auth/migrate.ts";
369
+
370
+ export default migrateBetterAuth(authOptions, { defaultRole: "member" });
371
+
372
+ const changed = yield* assignRole(Access, existingUserId, "admin");
373
+ ```
374
+
375
+ Use a numbered migration for schema adoption and a separate bootstrap command for the assignment. Existing sessions read the stored role on their next request. In an isolated story database, `const storage = yield* authTestDatabase; yield* storage.migrate(authOptions)` builds the schema without a role field when the options omit it; store users through `signedInUser`, then call `storage.migrate(authOptions, { defaultRole: "member" })` to exercise adoption without writing SQL against auth tables.
376
+
377
+ ### Permission middleware
358
378
 
359
379
  Declare a native middleware service for each required permission and provide its Layer beside the handlers:
360
380
 
@@ -489,7 +509,7 @@ Run the auth schema migration before the app migration. Use `ON DELETE CASCADE`
489
509
 
490
510
  Use `testUtils()` from `better-auth/plugins` in a test-only Better Auth instance with the host's database, secret and cookie policy. Keep the plugin out of production auth options.
491
511
 
492
- Use `authTestDatabase` from `@shivaedev/identity/server/better-auth/testDatabase.ts` when a story needs observations or faults in the default Better Auth PostgreSQL schema. It returns Effect readouts `users` (IDs and emails) and `sessions` (IDs, user IDs and emails), plus the test-only faults `expireSessions(userId?)` and `omitImageColumn`. Pass a user id to expire only that user's sessions, or call `expireSessions()` to expire every session. It never returns tokens, password hashes or provider credentials. These fixtures assume the default table and column mappings and read `SqlClient` from the Effect environment; use only an isolated test database. Application stories keep their auth SQL in this provider-owned boundary.
512
+ Use `authTestDatabase` from `@shivaedev/identity/server/better-auth/testDatabase.ts` when a story needs observations or faults in the default Better Auth PostgreSQL schema. It returns Effect readouts `users` (IDs and emails) and `sessions` (IDs, user IDs and emails), plus `migrate(options, roleOptions?)`, `roleColumn` (PostgreSQL type, nullability and default), `userRoles` (emails and roles), and the test-only faults `expireSessions(userId?)`, `omitImageColumn` and `omitRole(userId)`. The last fault makes a role nullable and clears that user's role to model a partial migration. Pass a user id to expire only that user's sessions, or call `expireSessions()` to expire every session. It never returns tokens, password hashes or provider credentials. These fixtures assume the default table and column mappings and read `SqlClient` from the Effect environment; use only an isolated test database. Application stories keep their auth SQL in this provider-owned boundary.
493
513
 
494
514
  `authTestDatabase` also exposes `sessionsFor(userId)`, returning that user’s stored sessions as `{ id, expiresAt, expired }`. `expiresAt` is a native Effect UTC value; `expired` compares it with Effect’s current clock. Expired sessions remain visible until removed. Revocation deletes a session, so its id disappears from this readout; it keeps no revocation history. For expiry stories, advance `TestClock` to the minted session’s expiry instead of rewriting storage timestamps. Identity’s Better Auth session provider, session administration list and expired-session sweep use Effect’s clock. Better Auth’s own auth endpoints, session creation and refresh still use the provider’s clock.
495
515
 
@@ -510,7 +530,7 @@ const { user, headers, cookies } = await signedInUser(testAuth, {
510
530
  });
511
531
  ```
512
532
 
513
- `options` is the application's auth configuration. `signedInUser` saves the supplied user fields, creates each optional `providerAccounts` entry for that user through Better Auth's internal adapter, and mints one session through Better Auth's `testUtils`, without OAuth or password hashing. The accounts carry no tokens or password. Omitting `providerAccounts` creates only the user and session. It returns Better Auth's login result: the user, session, signed request headers, browser cookies and token. Roles require the application's role plugin, such as Better Auth's `admin()`. Send `headers` to the real host, or pass `cookies` to test-story's `seedCookies` in a DOM story after setting its host location with `domFetch`. Keep a real sign-in story for each sign-in flow; feature stories start from the minted precondition.
533
+ `options` is the application's auth configuration. `signedInUser` saves the supplied user fields, creates each optional `providerAccounts` entry for that user through Better Auth's internal adapter, and mints one session through Better Auth's `testUtils`, without OAuth or password hashing. The accounts carry no tokens or password. Omitting `providerAccounts` creates only the user and session. It returns Better Auth's login result: the user, session, signed request headers, browser cookies and token. To mint users with roles, use the auth instance returned by `betterAuthMount(options, { defaultRole: "member", roles: Access })`. Send `headers` to the real host, or pass `cookies` to test-story's `seedCookies` in a DOM story after setting its host location with `domFetch`. Keep a real sign-in story for each sign-in flow; feature stories start from the minted precondition.
514
534
 
515
535
  `passwordUser(auth, { email, password, ...fields })` from the same testing module saves a user and a credential account using Better Auth's configured password hasher, and returns an Effect containing the user without minting a session. Use it for the one story that signs in through `/api/auth/sign-in/email`; keep feature stories on `signedInUser` so they avoid password hashing.
516
536
 
@@ -0,0 +1,6 @@
1
+ import type { BetterAuthOptions } from "better-auth";
2
+ export interface StoredRoleOptions {
3
+ readonly defaultRole: string;
4
+ }
5
+ export declare function storedRoleOptions<TOptions extends BetterAuthOptions>(options: TOptions, role?: StoredRoleOptions): TOptions;
6
+ //# sourceMappingURL=storedRoleOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storedRoleOptions.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/storedRoleOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,SAAS,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,QAAQ,CAc3H"}
@@ -0,0 +1,16 @@
1
+ export function storedRoleOptions(options, role) {
2
+ if (role === undefined) {
3
+ return options;
4
+ }
5
+ return {
6
+ ...options,
7
+ user: {
8
+ ...options.user,
9
+ additionalFields: {
10
+ ...options.user?.additionalFields,
11
+ role: { defaultValue: role.defaultRole, input: false, required: true, type: "string" },
12
+ },
13
+ },
14
+ };
15
+ }
16
+ //# sourceMappingURL=storedRoleOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storedRoleOptions.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/storedRoleOptions.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,iBAAiB,CAAqC,OAAiB,EAAE,IAAwB;IAChH,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,OAAO;QACN,GAAG,OAAO;QACV,IAAI,EAAE;YACL,GAAG,OAAO,CAAC,IAAI;YACf,gBAAgB,EAAE;gBACjB,GAAG,OAAO,CAAC,IAAI,EAAE,gBAAgB;gBACjC,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE;aACtF;SACD;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { BetterAuthOptions } from "better-auth";
2
+ import { Effect } from "effect";
3
+ import { SqlClient } from "effect/sql";
4
+ import { type StoredRoleOptions } from "#server/better-auth/adapters/storedRoleOptions.ts";
5
+ export declare const migrateBetterAuth: (options: Omit<BetterAuthOptions, "database">, role?: StoredRoleOptions | undefined) => Effect.Effect<void, import("effect/sql/SqlError").SqlError | import("effect/Cause").UnknownError, import("effect/Scope").Scope | SqlClient.SqlClient>;
6
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,KAAK,iBAAiB,EAAqB,MAAM,mDAAmD,CAAC;AAE9G,eAAO,MAAM,iBAAiB,+OAe5B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { getMigrations } from "better-auth/db/migration";
2
+ import { Effect } from "effect";
3
+ import { SqlClient } from "effect/sql";
4
+ import { betterAuthDatabase } from "#server/better-auth/adapters/database.ts";
5
+ import { storedRoleOptions } from "#server/better-auth/adapters/storedRoleOptions.ts";
6
+ export const migrateBetterAuth = Effect.fn("Identity.migrateBetterAuth")(function* (options, role) {
7
+ const database = yield* betterAuthDatabase();
8
+ const migration = yield* Effect.tryPromise(() => getMigrations({ ...storedRoleOptions(options, role), database }));
9
+ yield* Effect.tryPromise(() => migration.runMigrations());
10
+ if (role !== undefined) {
11
+ const sql = yield* SqlClient.SqlClient;
12
+ const table = sql(options.user?.modelName ?? "user");
13
+ const defaultValue = sql.literal(`'${role.defaultRole.replaceAll("'", "''")}'`);
14
+ yield* sql `alter table ${table} alter column role set default ${defaultValue}`;
15
+ yield* sql `update ${table} set role = ${role.defaultRole} where role is null`;
16
+ yield* sql `alter table ${table} alter column role set not null`;
17
+ }
18
+ });
19
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../src/server/better-auth/migrate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAA0B,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AAE9G,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,4BAA4B,CAAC,CAAC,QAAQ,CAAC,EACjF,OAA4C,EAC5C,IAAwB;IAExB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,kBAAkB,EAAE,CAAC;IAC7C,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,GAAG,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IACnH,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;IAC1D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC;QACvC,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,IAAI,MAAM,CAAC,CAAC;QACrD,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAChF,KAAK,CAAC,CAAC,GAAG,CAAA,eAAe,KAAK,kCAAkC,YAAY,EAAE,CAAC;QAC/E,KAAK,CAAC,CAAC,GAAG,CAAA,UAAU,KAAK,eAAe,IAAI,CAAC,WAAW,qBAAqB,CAAC;QAC9E,KAAK,CAAC,CAAC,GAAG,CAAA,eAAe,KAAK,iCAAiC,CAAC;IACjE,CAAC;AACF,CAAC,CAAC,CAAC"}
@@ -2,14 +2,18 @@ import { type BetterAuthOptions } from "better-auth";
2
2
  import { Config, Effect } from "effect";
3
3
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
4
4
  import { type BetterAuthHardeningOptions } from "#server/better-auth/adapters/hardening.ts";
5
+ import { type StoredRoleOptions } from "#server/better-auth/adapters/storedRoleOptions.ts";
5
6
  import { type BearerSessionsOptions } from "#server/better-auth/bearerSessions.ts";
6
7
  import { type SignInPolicy } from "#server/better-auth/signInGate.ts";
7
- export interface BetterAuthMountOptions<E = never, R = never> {
8
+ export type BetterAuthMountOptions<E = never, R = never> = {
8
9
  readonly bearerSessions?: BearerSessionsOptions | undefined;
9
10
  readonly hardening?: BetterAuthHardeningOptions;
10
- readonly roles?: RoleSet;
11
11
  readonly signIn?: SignInPolicy<E, R> | undefined;
12
- }
12
+ } & ({
13
+ readonly roles?: undefined;
14
+ } | (StoredRoleOptions & {
15
+ readonly roles: RoleSet;
16
+ }));
13
17
  export declare const betterAuthMount: <const TOptions extends BetterAuthOptions, E = never, R = never>(options: TOptions, mount?: BetterAuthMountOptions<E, R> | undefined) => Effect.Effect<{
14
18
  admittedSessions: {
15
19
  <TSession extends import("../session.ts").SessionShape>(getSession: import("../adapters/betterAuthSessions.ts").GetSession<TSession>): import("../session.ts").SessionProvider<TSession>;
@@ -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,EAAoB,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,KAAK,0BAA0B,EAAiB,MAAM,2CAA2C,CAAC;AAE3G,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,SAAS,CAAC,EAAE,0BAA0B,CAAC;IAChD,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;;;;;;;;;;;;;;;;;;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C,CAAC,CAAC;AAEzF,eAAO,MAAM,eAAe,SAA0D,QAAQ,SAAS,iBAAiB,EAAE,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDA4DpI,CAAC"}
@@ -2,6 +2,7 @@ import { betterAuth } from "better-auth";
2
2
  import { Config, Effect, Option, Redacted } from "effect";
3
3
  import { withHardening } from "#server/better-auth/adapters/hardening.ts";
4
4
  import { signInPolicyOptions } from "#server/better-auth/adapters/signInPolicyOptions.ts";
5
+ import { storedRoleOptions } from "#server/better-auth/adapters/storedRoleOptions.ts";
5
6
  import { withBearerSessions } from "#server/better-auth/bearerSessions.ts";
6
7
  import { PEER_IP_HEADER } from "#server/better-auth/clientIp.ts";
7
8
  import { memoryRateLimit } from "#server/better-auth/memoryRateLimit.ts";
@@ -23,10 +24,10 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* (
23
24
  yield* policy.accounts;
24
25
  }
25
26
  const gate = yield* signInGate(policy);
26
- const gated = yield* signInPolicyOptions(options, gate, () => auth.$context);
27
+ const configured = mount.roles === undefined ? options : storedRoleOptions(closeRoleEndpoints(options), mount);
28
+ const gated = yield* signInPolicyOptions(configured, gate, () => auth.$context);
27
29
  const rateLimit = options.rateLimit;
28
30
  const customStorage = rateLimit?.customStorage ?? (rateLimit?.storage === undefined || rateLimit.storage === "memory" ? yield* memoryRateLimit : undefined);
29
- const configured = mount.roles === undefined ? options : closeRoleEndpoints(options);
30
31
  const auth = betterAuth({
31
32
  ...withHardening(withBearerSessions(configured, mount.bearerSessions !== undefined), mount.hardening),
32
33
  advanced: {
@@ -51,7 +52,7 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* (
51
52
  },
52
53
  secret,
53
54
  trustedOrigins: options.trustedOrigins ?? Option.match(origin, { onNone: () => ["http://127.0.0.1:*", "http://localhost:*"], onSome: (url) => [url] }),
54
- user: gate.active ? gated.user : options.user,
55
+ user: gate.active ? gated.user : configured.user,
55
56
  });
56
57
  const authRoutes = mountRoutes(auth, {
57
58
  bearerSessions: mount.bearerSessions,
@@ -1 +1 @@
1
- {"version":3,"file":"mount.js","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EAAmC,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC3G,OAAO,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,EAA8B,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAyC,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACtG,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AASvD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,0BAA0B,CAAC,CAAC,QAAQ,CAAC,EAC7E,OAAiB,EACjB,KAAK,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AAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC1D;AACD,UAAU,iBAAiB;IAC1B,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C;AAuCD,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,iBAAiB,qEA4BxE"}
@@ -50,7 +50,7 @@ export function mountRoutes(auth, options) {
50
50
  "auth.rate_limit.address": clientIp.address,
51
51
  "auth.rate_limit.address_source": clientIp.source,
52
52
  });
53
- return HttpServerResponse.fromWeb(yield* authResponse(auth, web, options).pipe(Effect.catch(providerFailure)));
53
+ return HttpServerResponse.fromWeb(yield* authResponse(auth, web, options).pipe(Effect.catchTag("Forbidden", (error) => Effect.succeed(Response.json({ message: error.message }, { status: HttpStatus.fromLiteral("Forbidden") }))), Effect.catch(providerFailure)));
54
54
  }).pipe(Effect.catch(() => Effect.succeed(HttpServerResponse.text("Authentication is temporarily unavailable", { status: HttpStatus.fromLiteral("ServiceUnavailable") }))))));
55
55
  }
56
56
  //# sourceMappingURL=mountRoutes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mountRoutes.js","sourceRoot":"","sources":["../../../src/server/better-auth/mountRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAA8B,qBAAqB,EAAE,gBAAgB,E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,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC3C,KAAK,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC;YACjC,yBAAyB,EAAE,QAAQ,CAAC,OAAO;YAC3C,gCAAgC,EAAE,QAAQ,CAAC,MAAM;SACjD,CAAC,CAAC;QACH,OAAO,kBAAkB,CAAC,OAAO,CAChC,KAAK,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI,CAC3C,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CACtC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAC1G,EACD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAC7B,CACD,CAAC;IACH,CAAC,CAAC,CAAC,IAAI,CACN,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CACjB,MAAM,CAAC,OAAO,CACb,kBAAkB,CAAC,IAAI,CAAC,2CAA2C,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAC9H,CACD,CACD,CACD,CACD,CAAC;AACH,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { type Cause, Effect, Schema } from "effect";
2
2
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
3
- export declare const sessionPermissions: (response: Response, roles: RoleSet) => Effect.Effect<Response, Schema.SchemaError | Cause.UnknownError, never>;
3
+ import type { Forbidden } from "@shivaedev/errors/taxonomy.ts";
4
+ export declare const sessionPermissions: (response: Response, roles: RoleSet) => Effect.Effect<Response, Forbidden | Schema.SchemaError | Cause.UnknownError, never>;
4
5
  //# sourceMappingURL=sessionPermissions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sessionPermissions.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/sessionPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAO5D,eAAO,MAAM,kBAAkB,iHAa7B,CAAC"}
1
+ {"version":3,"file":"sessionPermissions.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/sessionPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAO/D,eAAO,MAAM,kBAAkB,6HAa7B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sessionPermissions.js","sourceRoot":"","sources":["../../../src/server/better-auth/sessionPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,cAAc,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAEnJ,MAAM,CAAC,MAAM,kB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ClH,CAAC,CAAC,CAAC"}
@@ -2,7 +2,14 @@ import { DateTime, Effect, Schema } from "effect";
2
2
  import { SqlClient } from "effect/sql";
3
3
  export declare const authTestDatabase: Effect.Effect<{
4
4
  expireSessions: (userId?: string) => Effect.Effect<void, import("effect/sql/SqlError").SqlError, never>;
5
+ migrate: (options: Omit<import("better-auth").BetterAuthOptions, "database">, role?: import("./adapters/storedRoleOptions.ts").StoredRoleOptions | undefined) => Effect.Effect<void, import("effect/sql/SqlError").SqlError | import("effect/Cause").UnknownError, import("effect/Scope").Scope | SqlClient.SqlClient>;
5
6
  omitImageColumn: Effect.Effect<void, import("effect/sql/SqlError").SqlError, never>;
7
+ omitRole: (userId: string) => Effect.Effect<void, import("effect/sql/SqlError").SqlError, never>;
8
+ roleColumn: import("effect/sql/Statement").Statement<{
9
+ type: string;
10
+ nullable: string;
11
+ default: string | null;
12
+ }>;
6
13
  sessionIpAddresses: import("effect/sql/Statement").Statement<{
7
14
  ipAddress: string | null;
8
15
  }>;
@@ -16,6 +23,10 @@ export declare const authTestDatabase: Effect.Effect<{
16
23
  id: string;
17
24
  expired: boolean;
18
25
  }[], Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
26
+ userRoles: import("effect/sql/Statement").Statement<{
27
+ email: string;
28
+ role: string | null;
29
+ }>;
19
30
  users: import("effect/sql/Statement").Statement<{
20
31
  email: string;
21
32
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"testDatabase.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/testDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAIlD,eAAO,MAAM,gBAAgB;8BAQD,MAAM;;;mBAKK,MAAM,GAAG,IAAI;;;eAE1C,MAAM;YACT,MAAM;gBACF,MAAM;;;;;;;;eAOK,MAAM;YAAM,MAAM;;8BAEtC,CAAC"}
1
+ {"version":3,"file":"testDatabase.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/testDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAKlD,eAAO,MAAM,gBAAgB;8BAQD,MAAM;;;uBAMb,MAAM;;cAKD,MAAM;kBAAY,MAAM;iBAAW,MAAM,GAAG,IAAI;;;mBAGnC,MAAM,GAAG,IAAI;;;eAE1C,MAAM;YACT,MAAM;gBACF,MAAM;;;;;;;;eAOS,MAAM;cAAQ,MAAM,GAAG,IAAI;;;eAC/B,MAAM;YAAM,MAAM;;8BAEtC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { DateTime, Effect, Schema } from "effect";
2
2
  import { SqlClient, SqlSchema } from "effect/sql";
3
+ import { migrateBetterAuth } from "./migrate.js";
3
4
  const StoredSession = Schema.Struct({ expiresAt: Schema.DateTimeUtcFromDate, id: Schema.String });
4
5
  export const authTestDatabase = Effect.gen(function* () {
5
6
  const sql = (yield* SqlClient.SqlClient).withoutTransforms();
@@ -10,7 +11,15 @@ export const authTestDatabase = Effect.gen(function* () {
10
11
  });
11
12
  return {
12
13
  expireSessions: (userId) => sql `update "session" set "expiresAt" = now() - interval '1 second' ${userId === undefined ? sql.literal("") : sql `where "userId" = ${userId}`}`.pipe(Effect.asVoid),
14
+ migrate: migrateBetterAuth,
13
15
  omitImageColumn: sql `alter table "user" drop column image`.pipe(Effect.asVoid),
16
+ omitRole: (userId) => Effect.gen(function* () {
17
+ yield* sql `alter table "user" alter column role drop not null`;
18
+ yield* sql `update "user" set role = null where id = ${userId}`;
19
+ }),
20
+ roleColumn: sql `
21
+ select data_type as type, is_nullable as nullable, column_default as "default"
22
+ from information_schema.columns where table_schema = current_schema() and table_name = 'user' and column_name = 'role'`,
14
23
  sessionIpAddresses: sql `select "ipAddress" from "session" order by "createdAt", id`,
15
24
  sessions: sql `select s.id, s."userId", u.email from "session" s join "user" u on u.id = s."userId" order by u.email, s.id`,
16
25
  sessionsFor: Effect.fnUntraced(function* (userId) {
@@ -18,6 +27,7 @@ export const authTestDatabase = Effect.gen(function* () {
18
27
  const now = yield* DateTime.now;
19
28
  return sessions.map((session) => ({ ...session, expired: DateTime.toEpochMillis(session.expiresAt) <= DateTime.toEpochMillis(now) }));
20
29
  }),
30
+ userRoles: sql `select email, role from "user" order by email`,
21
31
  users: sql `select id, email from "user" order by email`,
22
32
  };
23
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"testDatabase.js","sourceRoot":"","sources":["../../../src/server/better-auth/testDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,mBAAmB,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAElG,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACnD,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,iBAAiB,EAAE,CAAC;IAC7D,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC;QACtC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAA,0DAA0D,MAAM,cAAc;QACtG,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,MAAM,EAAE,aAAa;KACrB,CAAC,CAAC;IACH,OAAO;QACN,cAAc,EAAE,CAAC,MAAe,EAAE,EAAE,CACnC,GAAG,CAAA,kEAAkE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG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AAM,GAAG,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YAChC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACvI,CAAC,CAAC;QACF,SAAS,EAAE,GAAG,CAAwC,+CAA+C;QACrG,KAAK,EAAE,GAAG,CAA+B,6CAA6C;KACtF,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -3,6 +3,6 @@ import type { Headers } from "effect/http";
3
3
  import { Forbidden } from "@shivaedev/errors/taxonomy.ts";
4
4
  import type { SessionPolicy, SessionShape } from "./session.ts";
5
5
  export declare const sessionRequest: (policy: SessionPolicy<SessionShape>, headers: Headers.Headers, rpc: string) => Effect.Effect<import("./origin.ts").OriginRequest, Forbidden, never>;
6
- export declare const sessionAccess: <TSession extends SessionShape>(policy: SessionPolicy<SessionShape>, session: Option.Option<TSession>) => Effect.Effect<Option.None<TSession> | Option.Some<TSession>, never, never>;
7
- export declare const lookupSession: <TSession extends SessionShape>(policy: SessionPolicy<TSession>, headers: Headers.Headers) => Effect.Effect<Option.None<TSession> | Option.Some<TSession>, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
6
+ export declare const sessionAccess: <TSession extends SessionShape>(policy: SessionPolicy<SessionShape>, session: Option.Option<TSession>) => Effect.Effect<Option.None<TSession> | Option.Some<TSession>, Forbidden, never>;
7
+ export declare const lookupSession: <TSession extends SessionShape>(policy: SessionPolicy<TSession>, headers: Headers.Headers) => Effect.Effect<Option.None<TSession> | Option.Some<TSession>, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Forbidden, never>;
8
8
  //# sourceMappingURL=lookupSession.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lookupSession.d.ts","sourceRoot":"","sources":["../../src/server/lookupSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG1D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhE,eAAO,MAAM,cAAc,sJAMzB,CAAC;AAEH,eAAO,MAAM,aAAa,GAAgC,QAAQ,SAAS,YAAY,sJAUrF,CAAC;AAEH,eAAO,MAAM,aAAa,GAAgC,QAAQ,SAAS,YAAY,4LAErF,CAAC"}
1
+ {"version":3,"file":"lookupSession.d.ts","sourceRoot":"","sources":["../../src/server/lookupSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG1D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhE,eAAO,MAAM,cAAc,sJAMzB,CAAC;AAEH,eAAO,MAAM,aAAa,GAAgC,QAAQ,SAAS,YAAY,0JAUrF,CAAC;AAEH,eAAO,MAAM,aAAa,GAAgC,QAAQ,SAAS,YAAY,wMAErF,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { Effect } from "effect";
2
2
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
3
- export declare function resolveRole(roles: RoleSet, stored: unknown): Effect.Effect<{
3
+ import { Forbidden } from "@shivaedev/errors/taxonomy.ts";
4
+ export declare function resolveRole(roles: RoleSet, stored: unknown): Effect.Effect<never, Forbidden, never> | Effect.Effect<{
4
5
  permissions: readonly {
5
6
  readonly name: string;
6
7
  readonly strength: "any" | "own";
@@ -1 +1 @@
1
- {"version":3,"file":"resolveRole.d.ts","sourceRoot":"","sources":["../../src/server/resolveRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAE5D,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO;;;;;;iBAK1D"}
1
+ {"version":3,"file":"resolveRole.d.ts","sourceRoot":"","sources":["../../src/server/resolveRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO;;;;;;iBAW1D"}
@@ -1,5 +1,9 @@
1
1
  import { Effect } from "effect";
2
+ import { Forbidden } from "@shivaedev/errors/taxonomy.ts";
2
3
  export function resolveRole(roles, stored) {
4
+ if (stored === undefined || stored === null) {
5
+ return Effect.andThen(Effect.logWarning("Stored user role is missing. Run migrateBetterAuth with defaultRole, then use assignRole for administrators."), Effect.fail(new Forbidden({ message: "User role is missing" })));
6
+ }
3
7
  return roles.resolve(stored).pipe(Effect.mapError((cause) => new Error(`Stored user role is not declared by the application: ${String(stored)}`, { cause })), Effect.orDie);
4
8
  }
5
9
  //# sourceMappingURL=resolveRole.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveRole.js","sourceRoot":"","sources":["../../src/server/resolveRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,MAAe;IAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAChC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,wDAAwD,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,EAC1H,MAAM,CAAC,KAAK,CACZ,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"resolveRole.js","sourceRoot":"","sources":["../../src/server/resolveRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,MAAe;IAC1D,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC7C,OAAO,MAAM,CAAC,OAAO,CACpB,MAAM,CAAC,UAAU,CAAC,8GAA8G,CAAC,EACjI,MAAM,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAC/D,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAChC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,wDAAwD,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,EAC1H,MAAM,CAAC,KAAK,CACZ,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/identity",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
5
5
  "keywords": [
6
6
  "effect"
@@ -49,17 +49,17 @@
49
49
  "@shivaedev/changes": "0.6.0",
50
50
  "@shivaedev/contract": "0.29.0",
51
51
  "@shivaedev/errors": "0.3.0",
52
- "@shivaedev/sql": "0.27.0"
52
+ "@shivaedev/sql": "0.28.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@effect/platform-node": "4.0.6",
56
56
  "@effect/sql-pg": "4.0.6",
57
- "@shivaedev/admin": "0.14.0",
58
- "@shivaedev/quality": "0.50.0",
59
- "@shivaedev/server": "0.12.0",
57
+ "@shivaedev/admin": "0.15.0",
58
+ "@shivaedev/quality": "0.51.0",
59
+ "@shivaedev/server": "0.13.0",
60
60
  "@shivaedev/test": "0.12.0",
61
- "@shivaedev/test-sql": "0.15.0",
62
- "@shivaedev/test-story": "0.30.0",
61
+ "@shivaedev/test-sql": "0.15.1",
62
+ "@shivaedev/test-story": "0.31.0",
63
63
  "@types/node": "24.19.2",
64
64
  "better-auth": "1.7.12",
65
65
  "effect": "4.0.6",
@@ -0,0 +1,21 @@
1
+ import type { BetterAuthOptions } from "better-auth";
2
+
3
+ export interface StoredRoleOptions {
4
+ readonly defaultRole: string;
5
+ }
6
+
7
+ export function storedRoleOptions<TOptions extends BetterAuthOptions>(options: TOptions, role?: StoredRoleOptions): TOptions {
8
+ if (role === undefined) {
9
+ return options;
10
+ }
11
+ return {
12
+ ...options,
13
+ user: {
14
+ ...options.user,
15
+ additionalFields: {
16
+ ...options.user?.additionalFields,
17
+ role: { defaultValue: role.defaultRole, input: false, required: true, type: "string" },
18
+ },
19
+ },
20
+ };
21
+ }
@@ -0,0 +1,23 @@
1
+ import type { BetterAuthOptions } from "better-auth";
2
+ import { getMigrations } from "better-auth/db/migration";
3
+ import { Effect } from "effect";
4
+ import { SqlClient } from "effect/sql";
5
+ import { betterAuthDatabase } from "#server/better-auth/adapters/database.ts";
6
+ import { type StoredRoleOptions, storedRoleOptions } from "#server/better-auth/adapters/storedRoleOptions.ts";
7
+
8
+ export const migrateBetterAuth = Effect.fn("Identity.migrateBetterAuth")(function* (
9
+ options: Omit<BetterAuthOptions, "database">,
10
+ role?: StoredRoleOptions,
11
+ ) {
12
+ const database = yield* betterAuthDatabase();
13
+ const migration = yield* Effect.tryPromise(() => getMigrations({ ...storedRoleOptions(options, role), database }));
14
+ yield* Effect.tryPromise(() => migration.runMigrations());
15
+ if (role !== undefined) {
16
+ const sql = yield* SqlClient.SqlClient;
17
+ const table = sql(options.user?.modelName ?? "user");
18
+ const defaultValue = sql.literal(`'${role.defaultRole.replaceAll("'", "''")}'`);
19
+ yield* sql`alter table ${table} alter column role set default ${defaultValue}`;
20
+ yield* sql`update ${table} set role = ${role.defaultRole} where role is null`;
21
+ yield* sql`alter table ${table} alter column role set not null`;
22
+ }
23
+ });
@@ -3,6 +3,7 @@ import { Config, Effect, Option, Redacted } from "effect";
3
3
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
4
4
  import { type BetterAuthHardeningOptions, withHardening } from "#server/better-auth/adapters/hardening.ts";
5
5
  import { signInPolicyOptions } from "#server/better-auth/adapters/signInPolicyOptions.ts";
6
+ import { type StoredRoleOptions, storedRoleOptions } from "#server/better-auth/adapters/storedRoleOptions.ts";
6
7
  import { type BearerSessionsOptions, withBearerSessions } from "#server/better-auth/bearerSessions.ts";
7
8
  import { PEER_IP_HEADER } from "#server/better-auth/clientIp.ts";
8
9
  import { memoryRateLimit } from "#server/better-auth/memoryRateLimit.ts";
@@ -13,12 +14,11 @@ import { admittedSessions } from "./admittedSessions.ts";
13
14
  import { closeRoleEndpoints } from "./closeRoleEndpoints.ts";
14
15
  import { mountedSessions } from "./mountedSessions.ts";
15
16
 
16
- export interface BetterAuthMountOptions<E = never, R = never> {
17
+ export type BetterAuthMountOptions<E = never, R = never> = {
17
18
  readonly bearerSessions?: BearerSessionsOptions | undefined;
18
19
  readonly hardening?: BetterAuthHardeningOptions;
19
- readonly roles?: RoleSet;
20
20
  readonly signIn?: SignInPolicy<E, R> | undefined;
21
- }
21
+ } & ({ readonly roles?: undefined } | (StoredRoleOptions & { readonly roles: RoleSet }));
22
22
 
23
23
  export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* <const TOptions extends BetterAuthOptions, E = never, R = never>(
24
24
  options: TOptions,
@@ -35,11 +35,11 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* <
35
35
  yield* policy.accounts;
36
36
  }
37
37
  const gate = yield* signInGate(policy);
38
- const gated = yield* signInPolicyOptions(options, gate, (): Promise<PolicyStorage> => auth.$context);
38
+ const configured = mount.roles === undefined ? options : storedRoleOptions(closeRoleEndpoints(options), mount);
39
+ const gated = yield* signInPolicyOptions(configured, gate, (): Promise<PolicyStorage> => auth.$context);
39
40
  const rateLimit = options.rateLimit;
40
41
  const customStorage =
41
42
  rateLimit?.customStorage ?? (rateLimit?.storage === undefined || rateLimit.storage === "memory" ? yield* memoryRateLimit : undefined);
42
- const configured = mount.roles === undefined ? options : closeRoleEndpoints(options);
43
43
  const auth = betterAuth({
44
44
  ...withHardening(withBearerSessions(configured, mount.bearerSessions !== undefined), mount.hardening),
45
45
  advanced: {
@@ -66,7 +66,7 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* <
66
66
  secret,
67
67
  trustedOrigins:
68
68
  options.trustedOrigins ?? Option.match(origin, { onNone: () => ["http://127.0.0.1:*", "http://localhost:*"], onSome: (url) => [url] }),
69
- user: gate.active ? gated.user : options.user,
69
+ user: gate.active ? gated.user : configured.user,
70
70
  });
71
71
  const authRoutes = mountRoutes(auth, {
72
72
  bearerSessions: mount.bearerSessions,
@@ -67,7 +67,14 @@ export function mountRoutes(auth: MountedAuth, options: MountRouteOptions) {
67
67
  "auth.rate_limit.address": clientIp.address,
68
68
  "auth.rate_limit.address_source": clientIp.source,
69
69
  });
70
- return HttpServerResponse.fromWeb(yield* authResponse(auth, web, options).pipe(Effect.catch(providerFailure)));
70
+ return HttpServerResponse.fromWeb(
71
+ yield* authResponse(auth, web, options).pipe(
72
+ Effect.catchTag("Forbidden", (error) =>
73
+ Effect.succeed(Response.json({ message: error.message }, { status: HttpStatus.fromLiteral("Forbidden") })),
74
+ ),
75
+ Effect.catch(providerFailure),
76
+ ),
77
+ );
71
78
  }).pipe(
72
79
  Effect.catch(() =>
73
80
  Effect.succeed(
@@ -1,5 +1,6 @@
1
1
  import { type Cause, Effect, Schema } from "effect";
2
2
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
3
+ import type { Forbidden } from "@shivaedev/errors/taxonomy.ts";
3
4
  import { SessionUserSchema } from "#identity.ts";
4
5
  import { resolveRole } from "#server/resolveRole.ts";
5
6
 
@@ -9,7 +10,7 @@ const SessionPayload = Schema.NullOr(Schema.StructWithRest(Schema.Struct({ user:
9
10
  export const sessionPermissions = Effect.fn("Platform.sessionPermissions")(function* (
10
11
  response: Response,
11
12
  roles: RoleSet,
12
- ): Effect.fn.Return<Response, Cause.UnknownError | Schema.SchemaError> {
13
+ ): Effect.fn.Return<Response, Cause.UnknownError | Schema.SchemaError | Forbidden> {
13
14
  const payload = yield* Schema.decodeUnknownEffect(SessionPayload)(yield* Effect.tryPromise(() => response.json()));
14
15
  if (payload === null) {
15
16
  return Response.json(null, response);
@@ -1,5 +1,6 @@
1
1
  import { DateTime, Effect, Schema } from "effect";
2
2
  import { SqlClient, SqlSchema } from "effect/sql";
3
+ import { migrateBetterAuth } from "./migrate.ts";
3
4
 
4
5
  const StoredSession = Schema.Struct({ expiresAt: Schema.DateTimeUtcFromDate, id: Schema.String });
5
6
 
@@ -15,7 +16,16 @@ export const authTestDatabase = Effect.gen(function* () {
15
16
  sql`update "session" set "expiresAt" = now() - interval '1 second' ${userId === undefined ? sql.literal("") : sql`where "userId" = ${userId}`}`.pipe(
16
17
  Effect.asVoid,
17
18
  ),
19
+ migrate: migrateBetterAuth,
18
20
  omitImageColumn: sql`alter table "user" drop column image`.pipe(Effect.asVoid),
21
+ omitRole: (userId: string) =>
22
+ Effect.gen(function* () {
23
+ yield* sql`alter table "user" alter column role drop not null`;
24
+ yield* sql`update "user" set role = null where id = ${userId}`;
25
+ }),
26
+ roleColumn: sql<{ type: string; nullable: string; default: string | null }>`
27
+ select data_type as type, is_nullable as nullable, column_default as "default"
28
+ from information_schema.columns where table_schema = current_schema() and table_name = 'user' and column_name = 'role'`,
19
29
  sessionIpAddresses: sql<{ ipAddress: string | null }>`select "ipAddress" from "session" order by "createdAt", id`,
20
30
  sessions: sql<{
21
31
  email: string;
@@ -27,6 +37,7 @@ export const authTestDatabase = Effect.gen(function* () {
27
37
  const now = yield* DateTime.now;
28
38
  return sessions.map((session) => ({ ...session, expired: DateTime.toEpochMillis(session.expiresAt) <= DateTime.toEpochMillis(now) }));
29
39
  }),
40
+ userRoles: sql<{ email: string; role: string | null }>`select email, role from "user" order by email`,
30
41
  users: sql<{ email: string; id: string }>`select id, email from "user" order by email`,
31
42
  };
32
43
  });
@@ -1,7 +1,14 @@
1
1
  import { Effect } from "effect";
2
2
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
3
+ import { Forbidden } from "@shivaedev/errors/taxonomy.ts";
3
4
 
4
5
  export function resolveRole(roles: RoleSet, stored: unknown) {
6
+ if (stored === undefined || stored === null) {
7
+ return Effect.andThen(
8
+ Effect.logWarning("Stored user role is missing. Run migrateBetterAuth with defaultRole, then use assignRole for administrators."),
9
+ Effect.fail(new Forbidden({ message: "User role is missing" })),
10
+ );
11
+ }
5
12
  return roles.resolve(stored).pipe(
6
13
  Effect.mapError((cause) => new Error(`Stored user role is not declared by the application: ${String(stored)}`, { cause })),
7
14
  Effect.orDie,