@shivaedev/identity 0.16.0 → 0.18.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 (109) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +84 -54
  3. package/dist/server/SessionPolicy.d.ts +14 -0
  4. package/dist/server/SessionPolicy.d.ts.map +1 -0
  5. package/dist/server/SessionPolicy.js +4 -0
  6. package/dist/server/SessionPolicy.js.map +1 -0
  7. package/dist/server/adapters/authCall.d.ts +5 -0
  8. package/dist/server/adapters/authCall.d.ts.map +1 -0
  9. package/dist/server/adapters/authCall.js +7 -0
  10. package/dist/server/adapters/authCall.js.map +1 -0
  11. package/dist/server/adapters/betterAuthSessions.d.ts.map +1 -1
  12. package/dist/server/adapters/betterAuthSessions.js +4 -6
  13. package/dist/server/adapters/betterAuthSessions.js.map +1 -1
  14. package/dist/server/better-auth/PasswordReset.d.ts +7 -0
  15. package/dist/server/better-auth/PasswordReset.d.ts.map +1 -0
  16. package/dist/server/better-auth/PasswordReset.js +2 -0
  17. package/dist/server/better-auth/PasswordReset.js.map +1 -0
  18. package/dist/server/better-auth/accountRoleSeed.d.ts +2 -1
  19. package/dist/server/better-auth/accountRoleSeed.d.ts.map +1 -1
  20. package/dist/server/better-auth/accountRoleSeed.js +8 -6
  21. package/dist/server/better-auth/accountRoleSeed.js.map +1 -1
  22. package/dist/server/better-auth/adapters/database.d.ts.map +1 -1
  23. package/dist/server/better-auth/adapters/database.js +18 -3
  24. package/dist/server/better-auth/adapters/database.js.map +1 -1
  25. package/dist/server/better-auth/adapters/hookRuntime.d.ts.map +1 -1
  26. package/dist/server/better-auth/adapters/hookRuntime.js +2 -1
  27. package/dist/server/better-auth/adapters/hookRuntime.js.map +1 -1
  28. package/dist/server/better-auth/adapters/passwordResetOptions.d.ts +6 -0
  29. package/dist/server/better-auth/adapters/passwordResetOptions.d.ts.map +1 -0
  30. package/dist/server/better-auth/adapters/passwordResetOptions.js +17 -0
  31. package/dist/server/better-auth/adapters/passwordResetOptions.js.map +1 -0
  32. package/dist/server/better-auth/adapters/storedRoleOptions.d.ts.map +1 -1
  33. package/dist/server/better-auth/adapters/storedRoleOptions.js +8 -1
  34. package/dist/server/better-auth/adapters/storedRoleOptions.js.map +1 -1
  35. package/dist/server/better-auth/assignRole.d.ts +2 -1
  36. package/dist/server/better-auth/assignRole.d.ts.map +1 -1
  37. package/dist/server/better-auth/assignRole.js +7 -5
  38. package/dist/server/better-auth/assignRole.js.map +1 -1
  39. package/dist/server/better-auth/columnDrift.d.ts.map +1 -1
  40. package/dist/server/better-auth/columnDrift.js +4 -3
  41. package/dist/server/better-auth/columnDrift.js.map +1 -1
  42. package/dist/server/better-auth/migrationPlan.d.ts.map +1 -1
  43. package/dist/server/better-auth/migrationPlan.js +7 -5
  44. package/dist/server/better-auth/migrationPlan.js.map +1 -1
  45. package/dist/server/better-auth/mount.d.ts +3 -0
  46. package/dist/server/better-auth/mount.d.ts.map +1 -1
  47. package/dist/server/better-auth/mount.js +15 -4
  48. package/dist/server/better-auth/mount.js.map +1 -1
  49. package/dist/server/better-auth/sessionPermissions.js +1 -1
  50. package/dist/server/better-auth/signInGate.d.ts.map +1 -1
  51. package/dist/server/better-auth/signInGate.js +2 -1
  52. package/dist/server/better-auth/signInGate.js.map +1 -1
  53. package/dist/server/better-auth/tables.d.ts +19 -0
  54. package/dist/server/better-auth/tables.d.ts.map +1 -0
  55. package/dist/server/better-auth/tables.js +24 -0
  56. package/dist/server/better-auth/tables.js.map +1 -0
  57. package/dist/server/better-auth/userProfiles.js +1 -1
  58. package/dist/server/lookupSession.d.ts +5 -4
  59. package/dist/server/lookupSession.d.ts.map +1 -1
  60. package/dist/server/lookupSession.js +8 -4
  61. package/dist/server/lookupSession.js.map +1 -1
  62. package/dist/server/permissions.d.ts +4 -4
  63. package/dist/server/permissions.d.ts.map +1 -1
  64. package/dist/server/permissions.js +11 -8
  65. package/dist/server/permissions.js.map +1 -1
  66. package/dist/server/providerAccountsUser.d.ts +16 -0
  67. package/dist/server/providerAccountsUser.d.ts.map +1 -0
  68. package/dist/server/providerAccountsUser.js +12 -0
  69. package/dist/server/providerAccountsUser.js.map +1 -0
  70. package/dist/server/recheckSession.d.ts +2 -2
  71. package/dist/server/recheckSession.d.ts.map +1 -1
  72. package/dist/server/recheckSession.js +5 -3
  73. package/dist/server/recheckSession.js.map +1 -1
  74. package/dist/server/revalidateStream.d.ts +3 -2
  75. package/dist/server/revalidateStream.d.ts.map +1 -1
  76. package/dist/server/revalidateStream.js +3 -2
  77. package/dist/server/revalidateStream.js.map +1 -1
  78. package/dist/server/session.d.ts +9 -21
  79. package/dist/server/session.d.ts.map +1 -1
  80. package/dist/server/session.js +30 -28
  81. package/dist/server/session.js.map +1 -1
  82. package/dist/server/tracing.d.ts.map +1 -1
  83. package/dist/server/tracing.js +3 -2
  84. package/dist/server/tracing.js.map +1 -1
  85. package/package.json +12 -12
  86. package/src/server/SessionPolicy.ts +14 -0
  87. package/src/server/adapters/authCall.ts +8 -0
  88. package/src/server/adapters/betterAuthSessions.ts +5 -7
  89. package/src/server/better-auth/PasswordReset.ts +7 -0
  90. package/src/server/better-auth/accountRoleSeed.ts +8 -5
  91. package/src/server/better-auth/adapters/database.ts +21 -4
  92. package/src/server/better-auth/adapters/hookRuntime.ts +2 -1
  93. package/src/server/better-auth/adapters/passwordResetOptions.ts +25 -0
  94. package/src/server/better-auth/adapters/storedRoleOptions.ts +8 -1
  95. package/src/server/better-auth/assignRole.ts +7 -4
  96. package/src/server/better-auth/columnDrift.ts +4 -3
  97. package/src/server/better-auth/migrationPlan.ts +7 -5
  98. package/src/server/better-auth/mount.ts +17 -4
  99. package/src/server/better-auth/sessionPermissions.ts +1 -1
  100. package/src/server/better-auth/signInGate.ts +2 -1
  101. package/src/server/better-auth/tables.ts +28 -0
  102. package/src/server/better-auth/userProfiles.ts +1 -1
  103. package/src/server/lookupSession.ts +9 -8
  104. package/src/server/permissions.ts +29 -21
  105. package/src/server/providerAccountsUser.ts +16 -0
  106. package/src/server/recheckSession.ts +5 -4
  107. package/src/server/revalidateStream.ts +7 -5
  108. package/src/server/session.ts +88 -85
  109. package/src/server/tracing.ts +5 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.0 - 2026-11-02
4
+
5
+ ### Added
6
+
7
+ - Accept the application's Better Auth options in role assignment, provider-account role seeds and admin Users handlers to follow custom table and column mappings. Existing calls retain the default mapping.
8
+ - Identity mounts expose `admitsUser(userId)` to check the current sign-in policy for authenticated users on other transports, without caching rule verdicts.
9
+
10
+ ### Fixed
11
+
12
+ - Interrupting a session lookup, provider-account lookup or mounted Better Auth request cancels its pending PostgreSQL query. Transaction commit, rollback and connection cleanup still finish after cancellation.
13
+ - Present SQL interruption to Better Auth as a cancelled request so an interrupted session lookup does not log an internal server error.
14
+ - Compute command invalidation once with the resolved viewer and publish declared changes for optional-auth commands, including anonymous callers.
15
+ - Preserve the configured role column when mounting stored roles, generating role-aware migrations and checking the auth schema.
16
+ - Identity checks with a zero recheck interval start an independent rule lookup even while another check for the same account is pending.
17
+
18
+ ### Breaking
19
+
20
+ - MCP's `betterAuthMcp` requires `admitsUser`. Pass `admitsUser: mounted.admitsUser` from `betterAuthMount` alongside `auth: mounted.auth`. Each MCP request refuses users denied by the identity sign-in policy; existing tokens follow admission changes on the next request.
21
+
22
+ ## 0.17.0 - 2026-11-01
23
+
24
+ ### Added
25
+
26
+ - Identity's `betterAuthMount` accepts `onPasswordReset`, an Effect callback that runs with the host's context and composes after Better Auth's native reset callback.
27
+ - React's `permissionGuard` accepts `hidden: true` to render TanStack Router's not-found page when a signed-in viewer lacks a required permission.
28
+
29
+ ### Changed
30
+
31
+ - Identity operation spans use the `Identity` prefix, including `Identity.resolveSession` and `Identity.betterAuthSession`. Adjust trace queries that used `Platform` or `PlatformRpc` names.
32
+
33
+ ### Breaking
34
+
35
+ - Identity reads `SessionPolicy` from the Effect environment. Import the service from `@shivaedev/identity/server/SessionPolicy.ts` and construct one `Layer.succeed(SessionPolicy, { origin, provider, roles, streamRevalidationInterval })`, omitting optional fields as needed. Replace `SessionPolicy<TSession>` annotations with `SessionPolicy["Service"]`; provider-specific types remain on `SessionProvider<TSession>`. Remove policy arguments from session middleware constructors, `resolveSession`, `withSessionUser`, `permissionLayer`, `permissionRoute`, session lookup, rechecks and stream revalidation; provide the policy Layer to the composed readers. Profiles and provider accounts are decoded at their middleware boundaries from the shared provider.
36
+ - Server's `appHost` `sessions` option accepts that Layer and supplies it to middleware, application routes, sockets and change subscriptions. Wrap the previous policy object in `Layer.succeed(SessionPolicy, policy)`. Remove the session-shape generic from host option and factory types, and remove the policy argument from `hostChanges` and `bearerSocketRpc`.
37
+ - Admin uses identity's `SessionPolicy` directly. Replace `AdminSessions` imports and Layers with the identity service, and provide the policy once through the host instead of separately to admin handlers and documents.
38
+ - MCP's `mcpRoutes` reads `SessionPolicy` from the environment. Remove its `sessions` option and the session-shape generic from `McpOptions`; `betterAuthMcp` now returns `sessions` as a policy Layer, which can be passed to the host or supplied to MCP routes with `HttpRouter.provideRequest(oauth.sessions)` when the host also serves cookie-authenticated RPC.
39
+
3
40
  ## 0.16.0 - 2026-11-01
4
41
 
5
42
  ### Added
package/README.md CHANGED
@@ -69,17 +69,19 @@ export const Handlers = Account.toLayer({
69
69
 
70
70
  The middleware declaration makes `Identity` available to guarded handlers and adds `Unauthorized`, `AuthUnavailable` and `Forbidden` to the client's failure type. An unguarded handler that requires `Identity` cannot become a service-free handler Layer. Keep the group declaration in the shared module and the handler implementation on the server when organizing application files.
71
71
 
72
- Supply a provider and an explicit Origin policy as the host's `sessions` input. For a Better Auth provider, adapt its existing session lookup:
72
+ Provide one `SessionPolicy` Layer as the host's `sessions` input. Middleware, permission routes and session resolution read that service from the Effect environment. For a Better Auth provider, adapt its existing session lookup:
73
73
 
74
74
  ```ts
75
+ import { Layer } from "effect";
76
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
75
77
  import { betterAuthSessions } from "@shivaedev/identity/server/adapters/betterAuthSessions.ts";
76
78
  import { trustedOrigins } from "@shivaedev/identity/server/origin.ts";
77
79
  import { auth } from "./auth.ts";
78
80
 
79
- export const sessions = {
81
+ export const sessions = Layer.succeed(SessionPolicy, {
80
82
  origin: trustedOrigins({ allow: ["http://localhost:3000"], missing: "allow" }),
81
83
  provider: betterAuthSessions((headers) => auth.api.getSession({ headers })),
82
- };
84
+ });
83
85
  ```
84
86
 
85
87
  `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.
@@ -170,6 +172,19 @@ Fail a `before` hook with `{ code: "MEMBERS_ONLY", message: "Membership is requi
170
172
 
171
173
  Native callbacks in the first argument run before the corresponding Effect callbacks. A native `before` returning `false` stops the Effect callback too. Data changes compose in order. Identity's sign-in policy still runs after the application's session hook.
172
174
 
175
+ #### Application password-reset hook
176
+
177
+ Pass `onPasswordReset` in the mount's second argument to run an Effect after a password reset. Its `{ user }` argument follows Better Auth's callback; `BetterAuthPasswordReset` lives in `@shivaedev/identity/server/better-auth/PasswordReset.ts`. The callback reads the mounted request's services, or the mount's services for direct `auth.api` calls, so an application can invoke its grant-revocation service without capturing a runtime or the returned auth instance.
178
+
179
+ ```ts
180
+ const authentication = (options: BetterAuthOptions) =>
181
+ betterAuthMount(options, {
182
+ onPasswordReset: ({ user }) => Effect.flatMap(SessionAdmission, ({ check }) => check(user.id)),
183
+ });
184
+ ```
185
+
186
+ The native `emailAndPassword.onPasswordReset` callback runs first. An Effect failure with `BetterAuthHookError` fields reaches the caller as HTTP 403 with its code and message. This callback follows Better Auth's post-reset lifecycle; a failure does not undo the password change.
187
+
173
188
  ### Role assignments
174
189
 
175
190
  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.
@@ -184,6 +199,8 @@ yield* assignRole(AppAccess, userId, "owner");
184
199
 
185
200
  Supply the application's `SqlClient` Layer. `assignRole` uses the existing Reactivity service when present and supplies its own when absent, so server-only apps need no Users page or Reactivity Layer. This trusted server verb has no caller authorization check; authorize operator access before calling it. It returns whether the role changed, fails with `NotFound` for a missing user, and refuses to remove the final holder of `AssignRoles` (`roles.assign`) with `LastRoleAssigner`. Both declarations live in `@shivaedev/access/roles.ts`. Writes serialize through the same PostgreSQL transaction lock and invalidate the Users list after commit. The Users page adds its caller permission check and audit log.
186
201
 
202
+ For custom auth tables, pass the same Better Auth options used by `betterAuthMount` as the fourth argument: `assignRole(AppAccess, userId, "owner", authOptions)`. Role administration uses `user.modelName`, `user.fields.updatedAt` and `user.additionalFields.role.fieldName`. Role-aware migrations and schema checks preserve the role field mapping. Omitting the options keeps Better Auth's default table and column names.
203
+
187
204
  For named provider accounts, declare the role once and pass a configured `accountRoleSeed` to the mount:
188
205
 
189
206
  ```ts
@@ -209,13 +226,13 @@ const mounted = yield* betterAuthMount(authOptions, {
209
226
 
210
227
  Set `AUTH_OPERATOR_ACCOUNTS=github:1001,github:1002` using stable provider account IDs. `ProviderAccounts` shares the parser and account-ID validation of `AllowedAccounts`, while accepting an empty list. `Config.withDefault([])` also accepts an unset variable. Both grant nothing. Invalid entries fail boot with `ConfigError`.
211
228
 
212
- The mount runs the seed at boot for existing users and before creating sign-in sessions, including the first provider sign-in. A listed account that has never signed in is ignored until it does. Assignments go through `assignRole`, including its last-role-assigner guard and commit invalidation. The seed uses the application's SQL Layer and default Better Auth PostgreSQL tables.
229
+ The mount runs the seed at boot for existing users and before creating sign-in sessions, including the first provider sign-in. A listed account that has never signed in is ignored until it does. Assignments go through `assignRole`, including its last-role-assigner guard and commit invalidation. The seed uses the application's SQL Layer. With custom mappings, pass `authOptions` as the fourth argument to `accountRoleSeed(AppAccess, Operator.name, operators, authOptions)`. It follows the user mapping above and `account.modelName` plus `account.fields.accountId`, `providerId` and `userId` at boot and sign-in.
213
230
 
214
231
  The seed only grants: removing an account from config does not restore its previous role. To demote it, first remove the account from config and restart the server, then assign the desired role through the Users page or a trusted `assignRole` command. Keep another holder of `AssignRoles` before demoting the last administrator. A still-listed account receives the configured role again on sign-in or boot.
215
232
 
216
233
  ### Administer signed-in sessions
217
234
 
218
- Merge `Sessions` from `@shivaedev/identity/sessions.ts` into the application's RPC group and provide `sessionsHandlers` from `@shivaedev/identity/server/better-auth/sessionsHandlers.ts`. Install `permissionLayer(SessionsPermission, sessions)` using `SessionsPermission` from `@shivaedev/identity/sessionPermissions.ts` and the mounted session policy. Supply the application's Effect `SqlClient`; the handlers use the default Better Auth PostgreSQL user and session tables.
235
+ Merge `Sessions` from `@shivaedev/identity/sessions.ts` into the application's RPC group and provide `sessionsHandlers` from `@shivaedev/identity/server/better-auth/sessionsHandlers.ts`. Install `permissionLayer(SessionsPermission)` using `SessionsPermission` from `@shivaedev/identity/sessionPermissions.ts` and the mounted session policy. Supply the application's Effect `SqlClient`; the handlers use the default Better Auth PostgreSQL user and session tables.
219
236
 
220
237
  Grant `ManageSessions` (`sessions.manage`) from `sessionPermissions.ts` to the roles that manage sessions. The starter grants it to admin and owner. Both operations use the same permission middleware and `Forbidden` refusal as the admin Users page. They require no Better Auth admin plugin.
221
238
 
@@ -228,6 +245,8 @@ Grant `ManageSessions` (`sessions.manage`) from `sessionPermissions.ts` to the r
228
245
  For a Capacitor or similar WebView whose page is served from the app bundle, opt in with the auth host mount's `bearerSessions` option. It installs Better Auth's own `bearer({ requireSignature: true })` plugin from the existing dependency; do not add a second bearer plugin. The option is absent by default. List only bundled-client origins here, and include them in Better Auth's `trustedOrigins` as well.
229
246
 
230
247
  ```ts
248
+ import { Layer } from "effect";
249
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
231
250
  const nativeOrigins = ["capacitor://localhost", "https://localhost"];
232
251
  const mounted = yield* betterAuthMount(
233
252
  {
@@ -238,10 +257,10 @@ const mounted = yield* betterAuthMount(
238
257
  },
239
258
  { bearerSessions: { origins: nativeOrigins } },
240
259
  );
241
- const sessions = {
260
+ const sessions = Layer.succeed(SessionPolicy, {
242
261
  origin: trustedOrigins({ allow: [publicOrigin, ...nativeOrigins], missing: "allow" }),
243
262
  provider: mounted.admittedSessions((headers) => mounted.auth.api.getSession({ headers })),
244
- };
263
+ });
245
264
  const host = appHost({ group, handlers, routes: mounted.routes, sessions, nativeOrigins });
246
265
  ```
247
266
 
@@ -262,7 +281,8 @@ Use the WebView's own fetch with `credentials: "omit"` for incremental NDJSON ch
262
281
  Give the mount a sign-in policy as its second argument, and resolve RPC sessions through `admittedSessions` so a removal ends access on the next request:
263
282
 
264
283
  ```ts
265
- import { Effect } from "effect";
284
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
285
+ import { Effect, Layer } from "effect";
266
286
  import { allowedAccounts } from "@shivaedev/identity/server/better-auth/allowedAccounts.ts";
267
287
  import { betterAuthDatabase } from "@shivaedev/identity/server/better-auth/adapters/database.ts";
268
288
  import { betterAuthMount } from "@shivaedev/identity/server/better-auth/mount.ts";
@@ -275,10 +295,10 @@ const authentication = Effect.gen(function* () {
275
295
  { signIn: { accounts: allowedAccounts, recheckInterval: "5 minutes", rule: inOrganization } },
276
296
  );
277
297
  yield* mounted.revokeUnadmitted;
278
- const sessions = {
298
+ const sessions = Layer.succeed(SessionPolicy, {
279
299
  origin: trustedOrigins({ allow: ["https://app.example"], missing: "reject" }),
280
300
  provider: mounted.admittedSessions((headers) => mounted.auth.api.getSession({ headers })),
281
- };
301
+ });
282
302
  return { ...mounted, sessions };
283
303
  });
284
304
  ```
@@ -293,11 +313,13 @@ A removal takes effect on the user's next request through `admittedSessions`: th
293
313
 
294
314
  `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`.
295
315
 
296
- 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.
316
+ `mounted.admitsUser(userId)` checks the same sign-in policy against the user's stored provider accounts, without caching rule verdicts or deleting browser sessions. Use it to admit an already authenticated user through another transport, such as MCP. It returns an Effect of boolean, fails with `AuthUnavailable` if admission cannot be checked, and admits all users when no sign-in policy is configured.
317
+
318
+ Without `signIn`, the mount installs no sign-in policy hooks and `revokeUnadmitted` revokes nothing. `admittedSessions(lookup)` returns an Effect `SessionProvider`; use it as the `provider` in the `SessionPolicy` Layer. 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.
297
319
 
298
320
  ### Once per feature: identity and typed refusals
299
321
 
300
- Use `Authenticated` when the operation needs `Identity`, and `MaybeAuthenticated` with `maybeAuthenticatedLayer(policy)` when it reads `OptionalIdentity`:
322
+ Use `Authenticated` when the operation needs `Identity`, and `MaybeAuthenticated` with `maybeAuthenticatedLayer()` when it reads `OptionalIdentity`:
301
323
 
302
324
  ```ts
303
325
  import { Effect, Option, Schema } from "effect";
@@ -353,29 +375,31 @@ export const AccountHandlers = Account.toLayer({
353
375
  Whoami: () => Effect.map(SessionUser, (user) => user),
354
376
  });
355
377
 
356
- export const AccountServer = Layer.merge(AccountHandlers, authenticatedUserLayer(sessions));
378
+ export const AccountServer = Layer.merge(AccountHandlers, authenticatedUserLayer());
357
379
  ```
358
380
 
359
- Here `sessions` is the application's policy from the previous example, with a Better Auth lookup that returns all three user fields. Merge `authenticatedUserLayer(sessions)` alongside the handler Layer when using `appHost`; the host continues to supply its id-only and optional middleware. A missing session fails with typed `Unauthorized`; rejected origins fail with `Forbidden`, and provider failures remain `AuthUnavailable`. The profile contains id, name and email, plus an optional role when the provider supplies it, without exposing the rest of the provider's user record. Handlers do not query the provider's user table.
381
+ Here `sessions` is the application's policy Layer from the previous example, with a Better Auth lookup that returns all three user fields. The host provides it once to middleware and routes; custom hosts provide it with `Layer.provide(sessions)`. Merge `authenticatedUserLayer()` alongside the handler Layer when using `appHost`; the host continues to supply its id-only and optional middleware. A missing session fails with typed `Unauthorized`; rejected origins fail with `Forbidden`, and provider failures remain `AuthUnavailable`. The profile contains id, name and email, plus an optional role when the provider supplies it, without exposing the rest of the provider's user record. Handlers do not query the provider's user table.
360
382
 
361
383
  #### Reading provider account IDs
362
384
 
363
- Pass Better Auth's account lookup as the second argument to the mount's `admittedSessions` to combine provider accounts with its sign-in policy and credential selection. Without a mount, `betterAuthSessions` accepts the same two lookups. Declare `AuthenticatedUserWithProviderAccounts` on account-reading RPCs and merge `authenticatedUserWithProviderAccountsLayer(sessions)` alongside their handlers. This boundary requires a provider whose user has a `providerAccounts` Effect; a provider without the second lookup does not satisfy that type.
385
+ Pass Better Auth's account lookup as the second argument to the mount's `admittedSessions` to combine provider accounts with its sign-in policy and credential selection. Without a mount, `betterAuthSessions` accepts the same two lookups. Declare `AuthenticatedUserWithProviderAccounts` on account-reading RPCs and merge `authenticatedUserWithProviderAccountsLayer()` alongside their handlers. This boundary decodes the user profile and requires a `providerAccounts` Effect from the configured provider.
364
386
 
365
387
  ```ts
388
+ import { Layer } from "effect";
389
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
366
390
  import { SessionUserWithProviderAccounts } from "@shivaedev/identity/identity.ts";
367
391
  import { AuthenticatedUserWithProviderAccounts } from "@shivaedev/identity/middleware.ts";
368
392
  import { AuthUnavailable, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
369
393
  import { authenticatedUserWithProviderAccountsLayer } from "@shivaedev/identity/server/session.ts";
370
394
 
371
- const sessions = {
395
+ const sessions = Layer.succeed(SessionPolicy, {
372
396
  origin: trustedOrigins({ allow: ["https://app.example"], missing: "reject" }),
373
397
  ...mounted.sessions,
374
398
  provider: mounted.admittedSessions(
375
399
  (headers) => mounted.auth.api.getSession({ headers }),
376
400
  (headers) => mounted.auth.api.listUserAccounts({ headers }),
377
401
  ),
378
- };
402
+ });
379
403
 
380
404
  const githubAccount = Effect.gen(function* () {
381
405
  const user = yield* SessionUserWithProviderAccounts;
@@ -407,6 +431,8 @@ The Effect returns an array of `{ id, name, image }`, with `image: null` when un
407
431
  Declare application roles with `@shivaedev/access`. Each user row stores one declared role string. Supply the role set once through the existing auth configuration and reuse its returned session policy:
408
432
 
409
433
  ```ts
434
+ import { Layer } from "effect";
435
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
410
436
  import { permission } from "@shivaedev/access/permission.ts";
411
437
  import { role } from "@shivaedev/access/role.ts";
412
438
  import { roleSet } from "@shivaedev/access/roleSet.ts";
@@ -415,11 +441,13 @@ import { betterAuthMount } from "@shivaedev/identity/server/better-auth/mount.ts
415
441
  const UseTools = permission("tools.use");
416
442
  const Access = roleSet(role("member", []), role("operator", [UseTools]));
417
443
  const mounted = yield* betterAuthMount(authOptions, { defaultRole: "member", roles: Access });
418
- const sessions = { ...mounted.sessions, origin: trustedOrigins({ allow: ["https://app.example.com"], missing: "reject" }) };
444
+ const sessions = Layer.succeed(SessionPolicy, { ...mounted.sessions, origin: trustedOrigins({ allow: ["https://app.example.com"], missing: "reject" }) });
419
445
  ```
420
446
 
421
447
  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: generate and apply a frozen migration 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`.
422
448
 
449
+ React's `authSession` reads the session's grants as typed values while preserving the provider's session and user data. Applications using it need no session permission decoder.
450
+
423
451
  ### Frozen auth migrations
424
452
 
425
453
  Generate each auth migration once, review its SQL and commit the generated module. `generateBetterAuthMigration(options, roleOptions?)` reads the current PostgreSQL schema through `SqlClient` and returns a TypeScript migration module. It does not apply the migration. The module imports only native Effect and executes fixed SQL on the migrator's transaction connection. Later auth option changes and Better Auth upgrades cannot change its SQL.
@@ -493,13 +521,13 @@ import { permissionLayer } from "@shivaedev/identity/server/permissions.ts";
493
521
  class ToolsPermission extends permissionMiddleware<ToolsPermission>()("app/ToolsPermission", UseTools) {}
494
522
  const Tools = RpcGroup.make(Rpc.make("tools", { success: Schema.String }).middleware(ToolsPermission));
495
523
  const handlers = Tools.toLayer({ tools: () => Effect.map(SessionUser, (user) => user.email) }).pipe(
496
- Layer.provideMerge(permissionLayer(ToolsPermission, sessions)),
524
+ Layer.provideMerge(permissionLayer(ToolsPermission)),
497
525
  );
498
526
  ```
499
527
 
500
528
  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.
501
529
 
502
- 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.
530
+ For HTTP routes, use `permissionRoute(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.
503
531
 
504
532
  ```ts
505
533
  import { HttpRouter, HttpServerResponse } from "effect/http";
@@ -509,7 +537,7 @@ const routes = HttpRouter.use((router) =>
509
537
  router.add(
510
538
  "GET",
511
539
  "/tools",
512
- permissionRoute(sessions, UseTools)(() => Effect.map(SessionUser, (user) => HttpServerResponse.text(user.email))),
540
+ permissionRoute(UseTools)(() => Effect.map(SessionUser, (user) => HttpServerResponse.text(user.email))),
513
541
  ),
514
542
  );
515
543
  ```
@@ -567,14 +595,16 @@ const authentication = Layer.succeed(MyAuthentication, (effect, { headers, rpc,
567
595
 
568
596
  `authenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer`, the role layers and signed-in `maybeAuthenticatedLayer` calls revalidate live RPC streams every 30 seconds by default, using the original transport headers. A signed-out, revoked or expired session ends the stream with `Unauthorized`, including an idle stream and a subscription receiving a change hint. A signed-in viewer whose query read policy now refuses ends the subscription with `QueryReadDenied`. Session intervals use Effect’s Clock, so advancing `TestClock` drives revalidation; batched session lookups do not need another clock advance. With a session store that reflects sign-out immediately, delivery can continue for up to that interval plus the session lookup time after sign-out. Provider cookie caching or secondary storage can add their own delay; keep Better Auth's cookie cache disabled for database-backed revocation.
569
597
 
570
- Set `SessionPolicy.streamRevalidationInterval` to an Effect `Duration.Input` to change the interval for middleware using that policy:
598
+ Set `streamRevalidationInterval` in the `SessionPolicy` Layer to an Effect `Duration.Input` to change the interval for middleware using that policy:
571
599
 
572
600
  ```ts
573
- const sessions = {
601
+ import { Layer } from "effect";
602
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
603
+ const sessions = Layer.succeed(SessionPolicy, {
574
604
  origin: trustedOrigins({ allow: ["https://app.example.com"], missing: "reject" }),
575
605
  provider: betterAuthSessions((headers) => auth.api.getSession({ headers })),
576
606
  streamRevalidationInterval: "5 seconds",
577
- };
607
+ });
578
608
  ```
579
609
 
580
610
  An `AuthUnavailable` failure during revalidation ends the stream with `AuthUnavailable`. Initial session lookup failures also reject the subscription. Unary calls resolve their session once per call. `MaybeAuthenticated` streams that start anonymous continue without a session monitor; a signed-in optional stream ends with `Unauthorized` when its session is removed. Callers can subscribe again to continue anonymously.
@@ -715,39 +745,39 @@ Register the Effect with a worker schedule, as the starter does at midnight UTC.
715
745
 
716
746
  Import the module that defines the name; there is no package-root entry. Paths below follow `@shivaedev/identity/`.
717
747
 
718
- | Module | Names and purpose |
719
- | -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
720
- | `identity.ts` | `RequestId`, `Identity`, `OptionalIdentity`, `SessionUser`, `SessionUserWithProviderAccounts`, `SessionUserSchema`: request-local services and the shared user schema. |
721
- | `middleware.ts` | `RequestTracing`, `Authenticated`, `AuthenticatedUser`, `AuthenticatedUserWithProviderAccounts`, `MaybeAuthenticated`, `IdentityFailures`: native RPC middleware declarations and their shared failure schema. |
722
- | `server/providerFailure.ts` | `providerFailure(cause)`: log a redacted provider failure and fail with `AuthUnavailable`. |
723
- | `permission.ts` | `permissionMiddleware`, `hasPermission`: native permission middleware declarations and predicates over resolved grants. |
724
- | `server/permissions.ts` | `permissionLayer`, `permissionRoute`: permission middleware Layers and HTTP route guards. |
725
- | `server/session.ts` | `authenticatedLayer`, `maybeAuthenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer`, `withSessionUser`, `resolveSession`: session middleware implementations and the identity boundary. |
726
- | `server/adapters/betterAuthSessions.ts` | `betterAuthSessions(getSession, getProviderAccounts?)`: a session provider from Better Auth lookups. |
727
- | `server/origin.ts` | `trustedOrigins({ allow, missing })`: an exact Origin allowlist. |
728
- | `server/local.ts` | `localRpcGuard`, `loopbackOnly`, `sameOrigin`, `trustedProxyPeer`: loopback and proxy guards. |
729
- | `server/trustedProxyRanges.ts` | `trustedProxyRanges(trustedProxy?)`: normalized proxy ranges. |
730
- | `server/proxyRanges.ts` | `proxyRanges(value)`: parse configured proxy ranges. |
731
- | `server/transportHeaders.ts` | `transportHeaders(rpcHeaders)`: the headers used for a transport-level decision. |
732
- | `server/tracing.ts` | `requestTracingLayer({ header?, sensitive? })`: the `RequestTracing` implementation. |
733
- | `server/sessionKeys.ts` | `resolveChanges`: session-scoped change subscriptions for custom change handlers. |
734
- | `server/commandChanges.ts` | `commandChanges(effect, rpc, payload)`: scoped command invalidation for custom authentication middleware. |
735
- | `server/better-auth/mount.ts` | `betterAuthMount(options, { emails?, signIn?, bearerSessions?, roles?, defaultRole?, roleSeed? })`, returning `{ auth, routes, sessions, admittedSessions, revokeUnadmitted }`: native auth routes and the sign-in policy. |
736
- | `server/better-auth/adapters/database.ts` | `betterAuthDatabase()`: Better Auth storage on the application PostgreSQL client. |
737
- | `server/better-auth/emails.ts` | `AuthEmail`, `BetterAuthEmails`: typed delivery messages, app routes and per-account delivery windows for the mount. |
738
- | `server/better-auth/allowedAccounts.ts` | `ProviderAccounts`, `AllowedAccounts`, `allowedAccounts`: provider-account list Schemas and the non-empty `AUTH_ALLOWED_ACCOUNTS` Config. |
739
- | `server/better-auth/accountRoleSeed.ts` | `accountRoleSeed(access, role, accounts)`: grant a configured role at boot and sign-in through `assignRole`. |
740
- | `server/better-auth/signInGate.ts` | `SignInPolicy`: the `accounts`, `rule` and `recheckInterval` of a sign-in policy. |
741
- | `server/better-auth/revokeUnadmitted.ts` | `RevokedSessions`: the `{ users, sessions }` counts of a revocation. |
742
- | `server/better-auth/userProfiles.ts` | Public profile lookups for other users. |
743
- | `server/better-auth/sweepExpiredSessions.ts` | `sweepExpiredSessions`: delete expired sessions through the application's SQL client and return the number removed. |
744
- | `server/better-auth/userReference.ts` | `userReference`: the default auth user table and id column for application foreign keys. |
745
- | `server/better-auth/testDatabase.ts` | `authTestDatabase`: test-only identity/session readouts and faults for the default PostgreSQL auth schema. |
746
- | `server/better-auth/testing.ts` | `signedInUser(auth, fields)`, `passwordUser(auth, fields)`, `storedProviderAccounts(auth, userId)`: test-only users, minted sessions and credential storage observations. |
748
+ | Module | Names and purpose |
749
+ | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
750
+ | `identity.ts` | `RequestId`, `Identity`, `OptionalIdentity`, `SessionUser`, `SessionUserWithProviderAccounts`, `SessionUserSchema`: request-local services and the shared user schema. |
751
+ | `middleware.ts` | `RequestTracing`, `Authenticated`, `AuthenticatedUser`, `AuthenticatedUserWithProviderAccounts`, `MaybeAuthenticated`, `IdentityFailures`: native RPC middleware declarations and their shared failure schema. |
752
+ | `server/providerFailure.ts` | `providerFailure(cause)`: log a redacted provider failure and fail with `AuthUnavailable`. |
753
+ | `permission.ts` | `permissionMiddleware`, `hasPermission`: native permission middleware declarations and predicates over resolved grants. |
754
+ | `server/permissions.ts` | `permissionLayer`, `permissionRoute`: permission middleware Layers and HTTP route guards. |
755
+ | `server/session.ts` | `authenticatedLayer`, `maybeAuthenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer`, `withSessionUser`, `resolveSession`: session middleware implementations and the identity boundary. |
756
+ | `server/adapters/betterAuthSessions.ts` | `betterAuthSessions(getSession, getProviderAccounts?)`: a session provider from Better Auth lookups. |
757
+ | `server/origin.ts` | `trustedOrigins({ allow, missing })`: an exact Origin allowlist. |
758
+ | `server/local.ts` | `localRpcGuard`, `loopbackOnly`, `sameOrigin`, `trustedProxyPeer`: loopback and proxy guards. |
759
+ | `server/trustedProxyRanges.ts` | `trustedProxyRanges(trustedProxy?)`: normalized proxy ranges. |
760
+ | `server/proxyRanges.ts` | `proxyRanges(value)`: parse configured proxy ranges. |
761
+ | `server/transportHeaders.ts` | `transportHeaders(rpcHeaders)`: the headers used for a transport-level decision. |
762
+ | `server/tracing.ts` | `requestTracingLayer({ header?, sensitive? })`: the `RequestTracing` implementation. |
763
+ | `server/sessionKeys.ts` | `resolveChanges`: session-scoped change subscriptions for custom change handlers. |
764
+ | `server/commandChanges.ts` | `commandChanges(effect, rpc, payload)`: scoped command invalidation for custom authentication middleware. |
765
+ | `server/better-auth/mount.ts` | `betterAuthMount(options, { emails?, onPasswordReset?, signIn?, bearerSessions?, roles?, defaultRole?, roleSeed? })`, returning `{ auth, routes, sessions, admittedSessions, admitsUser, revokeUnadmitted }`: native auth routes and the sign-in policy. |
766
+ | `server/better-auth/adapters/database.ts` | `betterAuthDatabase()`: Better Auth storage on the application PostgreSQL client. |
767
+ | `server/better-auth/emails.ts` | `AuthEmail`, `BetterAuthEmails`: typed delivery messages, app routes and per-account delivery windows for the mount. |
768
+ | `server/better-auth/allowedAccounts.ts` | `ProviderAccounts`, `AllowedAccounts`, `allowedAccounts`: provider-account list Schemas and the non-empty `AUTH_ALLOWED_ACCOUNTS` Config. |
769
+ | `server/better-auth/accountRoleSeed.ts` | `accountRoleSeed(access, role, accounts)`: grant a configured role at boot and sign-in through `assignRole`. |
770
+ | `server/better-auth/signInGate.ts` | `SignInPolicy`: the `accounts`, `rule` and `recheckInterval` of a sign-in policy. |
771
+ | `server/better-auth/revokeUnadmitted.ts` | `RevokedSessions`: the `{ users, sessions }` counts of a revocation. |
772
+ | `server/better-auth/userProfiles.ts` | Public profile lookups for other users. |
773
+ | `server/better-auth/sweepExpiredSessions.ts` | `sweepExpiredSessions`: delete expired sessions through the application's SQL client and return the number removed. |
774
+ | `server/better-auth/userReference.ts` | `userReference`: the default auth user table and id column for application foreign keys. |
775
+ | `server/better-auth/testDatabase.ts` | `authTestDatabase`: test-only identity/session readouts and faults for the default PostgreSQL auth schema. |
776
+ | `server/better-auth/testing.ts` | `signedInUser(auth, fields)`, `passwordUser(auth, fields)`, `storedProviderAccounts(auth, userId)`: test-only users, minted sessions and credential storage observations. |
747
777
 
748
778
  ### Install, setup and limits
749
779
 
750
- Install `@shivaedev/identity` with `effect` as its peer. Everything outside `server/better-auth/` works with only `effect` installed, including the Promise-based `betterAuthSessions` adapter. Better Auth mounts and test fixtures need the optional peer `better-auth` and the application’s PostgreSQL `SqlClient`; `sweepExpiredSessions` needs only the application's Effect SQL client. Browser code imports only `identity.ts`, `middleware.ts` and `permission.ts`.
780
+ Install `@shivaedev/identity` with `effect` as its peer. Everything outside `server/better-auth/` works with only `effect` installed, including the Promise-based `betterAuthSessions` adapter. Better Auth mounts and test fixtures need the optional peer `better-auth` and the application’s PostgreSQL `SqlClient`; `sweepExpiredSessions` needs only the application's Effect SQL client. Browser code imports `identity.ts`, `middleware.ts` and `permission.ts`.
751
781
  - The package needs Node 24 or newer.
752
782
  - Keep the auth provider's configuration, cookie settings and resource authorization in the application. The session adapter takes a session lookup and an optional provider-account lookup and returns a session result; it does not write provider refresh cookies into RPC responses.
753
783
  - Without an `HttpServerRequest`, `transportHeaders` falls back to the supplied RPC headers. An application using another transport must decide what headers it can trust.
@@ -0,0 +1,14 @@
1
+ import { Context, type Duration } from "effect";
2
+ import type { RoleSet } from "@shivaedev/access/roleSet.ts";
3
+ import type { OriginPolicy } from "./origin.ts";
4
+ import type { SessionProvider, SessionShape } from "./session.ts";
5
+ declare const SessionPolicy_base: Context.ServiceClass<SessionPolicy, "@shivaedev/identity/SessionPolicy", {
6
+ readonly origin: OriginPolicy;
7
+ readonly provider: SessionProvider<SessionShape>;
8
+ readonly roles?: RoleSet;
9
+ readonly streamRevalidationInterval?: Duration.Input | undefined;
10
+ }>;
11
+ export declare class SessionPolicy extends SessionPolicy_base {
12
+ }
13
+ export {};
14
+ //# sourceMappingURL=SessionPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionPolicy.d.ts","sourceRoot":"","sources":["../../src/server/SessionPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;;qBAK/C,YAAY;uBACV,eAAe,CAAC,YAAY,CAAC;qBAC/B,OAAO;0CACc,QAAQ,CAAC,KAAK,GAAG,SAAS;;AANlE,qBAAa,aAAc,SAAQ,kBAQK;CAAG"}
@@ -0,0 +1,4 @@
1
+ import { Context } from "effect";
2
+ export class SessionPolicy extends Context.Service()("@shivaedev/identity/SessionPolicy") {
3
+ }
4
+ //# sourceMappingURL=SessionPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionPolicy.js","sourceRoot":"","sources":["../../src/server/SessionPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,QAAQ,CAAC;AAKhD,MAAM,OAAO,aAAc,SAAQ,OAAO,CAAC,OAAO,EAQ/C,CAAC,mCAAmC,CAAC;CAAG"}
@@ -0,0 +1,5 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { Effect } from "effect";
3
+ export declare const authCallSignal: AsyncLocalStorage<AbortSignal>;
4
+ export declare function authCall<A>(call: (signal: AbortSignal) => Promise<A>): Effect.Effect<A, import("effect/Cause").UnknownError, never>;
5
+ //# sourceMappingURL=authCall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authCall.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/authCall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,cAAc,gCAAuC,CAAC;AAEnE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,gEAEpE"}
@@ -0,0 +1,7 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { Effect } from "effect";
3
+ export const authCallSignal = new AsyncLocalStorage();
4
+ export function authCall(call) {
5
+ return Effect.tryPromise((signal) => authCallSignal.run(signal, () => call(signal)));
6
+ }
7
+ //# sourceMappingURL=authCall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authCall.js","sourceRoot":"","sources":["../../../src/server/adapters/authCall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,iBAAiB,EAAe,CAAC;AAEnE,MAAM,UAAU,QAAQ,CAAI,IAAyC;IACpE,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"betterAuthSessions.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAA6B,MAAM,QAAQ,CAAC;AAGlE,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;AAIxE,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;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AAY,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"}
@@ -2,21 +2,19 @@ import { Clock, Effect, Option, Predicate, Schema } from "effect";
2
2
  import * as HttpStatus from "effect/http/HttpStatus";
3
3
  import { Unauthorized } from "@shivaedev/errors/taxonomy.ts";
4
4
  import { providerFailure } from "#server/providerFailure.ts";
5
+ import { authCall } from "./authCall.js";
5
6
  const ExpiringSession = Schema.Struct({ session: Schema.Struct({ expiresAt: Schema.Date }) });
6
7
  export function betterAuthSessions(getSession, getProviderAccounts) {
7
- const betterAuthSession = Effect.fn("PlatformRpc.betterAuthSession")(function* (headers) {
8
+ const betterAuthSession = Effect.fn("Identity.betterAuthSession")(function* (headers) {
8
9
  const transport = new globalThis.Headers(headers);
9
- const session = yield* Effect.tryPromise(() => getSession(transport)).pipe(Effect.catch((error) => providerFailure(error.cause)));
10
+ const session = yield* authCall(() => getSession(transport)).pipe(Effect.catch((error) => providerFailure(error.cause)));
10
11
  if (Schema.is(ExpiringSession)(session) && session.session.expiresAt.getTime() <= (yield* Clock.currentTimeMillis)) {
11
12
  return Option.none();
12
13
  }
13
14
  if (session === null || getProviderAccounts === undefined) {
14
15
  return Option.fromNullishOr(session);
15
16
  }
16
- const providerAccounts = Effect.tryPromise({
17
- catch: (cause) => cause,
18
- try: () => getProviderAccounts(transport),
19
- }).pipe(Effect.catch((cause) => Predicate.hasProperty(cause, "statusCode") && cause.statusCode === HttpStatus.fromLiteral("Unauthorized")
17
+ const providerAccounts = authCall(() => getProviderAccounts(transport)).pipe(Effect.catch(({ cause }) => Predicate.hasProperty(cause, "statusCode") && cause.statusCode === HttpStatus.fromLiteral("Unauthorized")
20
18
  ? Effect.fail(new Unauthorized({ message: "Authentication required" }))
21
19
  : providerFailure(cause)));
22
20
  return Option.some({ ...session, user: { ...session.user, providerAccounts } });
@@ -1 +1 @@
1
- {"version":3,"file":"betterAuthSessions.js","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAElE,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAwB,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AAY9F,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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AAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;QACD,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,QAAQ,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAC3E,MAAM,CAAC,KAAK,CACX,CAAC,EAAE,KAAK,EAAE,EAAwD,EAAE,CACnE,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,7 @@
1
+ import type { BetterAuthOptions } from "better-auth";
2
+ import type { Effect } from "effect";
3
+ import type { BetterAuthHookError } from "./databaseHooks.ts";
4
+ type NativePasswordReset = NonNullable<NonNullable<BetterAuthOptions["emailAndPassword"]>["onPasswordReset"]>;
5
+ export type BetterAuthPasswordReset<R = never> = (data: Parameters<NativePasswordReset>[0]) => Effect.Effect<void, BetterAuthHookError, R>;
6
+ export {};
7
+ //# sourceMappingURL=PasswordReset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PasswordReset.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/PasswordReset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,KAAK,mBAAmB,GAAG,WAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAE9G,MAAM,MAAM,uBAAuB,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PasswordReset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PasswordReset.js","sourceRoot":"","sources":["../../../src/server/better-auth/PasswordReset.ts"],"names":[],"mappings":""}
@@ -3,10 +3,11 @@ import { SqlClient } from "effect/sql";
3
3
  import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
4
4
  import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
5
5
  import type { ProviderAccountValue } from "#identity.ts";
6
+ import { type AuthTableOptions } from "./tables.ts";
6
7
  export interface AccountRoleSeed<E> {
7
8
  readonly onSignIn: (userId: string) => Effect.Effect<void, E>;
8
9
  }
9
- export declare const accountRoleSeed: <TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">, role: NoInfer<TRole>, accounts: Config.Config<readonly ProviderAccountValue[]>) => Effect.Effect<{
10
+ export declare const accountRoleSeed: <TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">, role: NoInfer<TRole>, accounts: Config.Config<readonly ProviderAccountValue[]>, options?: AuthTableOptions | undefined) => Effect.Effect<{
10
11
  onSignIn: (userId: string) => Effect.Effect<void, AuthUnavailable | import("@shivaedev/access/roles.ts").LastRoleAssigner | import("@shivaedev/errors/taxonomy.ts").NotFound, never>;
11
12
  }, AuthUnavailable | Config.ConfigError | import("@shivaedev/access/roles.ts").LastRoleAssigner | import("@shivaedev/errors/taxonomy.ts").NotFound, SqlClient.SqlClient>;
12
13
  //# sourceMappingURL=accountRoleSeed.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accountRoleSeed.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/accountRoleSeed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;CAC9D;AAED,eAAO,MAAM,eAAe,GAAoD,KAAK,SAAS,MAAM;uBA2BvE,MAAM;wKACjC,CAAC"}
1
+ {"version":3,"file":"accountRoleSeed.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/accountRoleSeed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,KAAK,gBAAgB,EAAU,MAAM,aAAa,CAAC;AAE5D,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;CAC9D;AAED,eAAO,MAAM,eAAe,GAAoD,KAAK,SAAS,MAAM;uBA6BvE,MAAM;wKACjC,CAAC"}
@@ -2,15 +2,17 @@ import { Effect, Schema } from "effect";
2
2
  import { SqlClient, SqlSchema } from "effect/sql";
3
3
  import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
4
4
  import { assignRole } from "./assignRole.js";
5
- export const accountRoleSeed = Effect.fn("Identity.accountRoleSeed")(function* (access, role, accounts) {
5
+ import { tables } from "./tables.js";
6
+ export const accountRoleSeed = Effect.fn("Identity.accountRoleSeed")(function* (access, role, accounts, options) {
6
7
  const listed = yield* accounts;
7
8
  const context = yield* Effect.context();
8
- const sql = yield* SqlClient.SqlClient;
9
+ const sql = (yield* SqlClient.SqlClient).withoutTransforms();
10
+ const { account: accountTable } = tables(options);
9
11
  const findUsers = SqlSchema.findAll({
10
12
  execute: ({ accountId, providerId, userId }) => sql `
11
- select distinct "userId" as id from "account"
12
- where "providerId" = ${providerId} and "accountId" = ${accountId}
13
- ${userId === undefined ? sql.literal("") : sql `and "userId" = ${userId}`}`,
13
+ select distinct ${sql(accountTable.userId)} as id from ${sql(accountTable.table)}
14
+ where ${sql(accountTable.providerId)} = ${providerId} and ${sql(accountTable.accountId)} = ${accountId}
15
+ ${userId === undefined ? sql.literal("") : sql `and ${sql(accountTable.userId)} = ${userId}`}`,
14
16
  Request: Schema.Struct({ accountId: Schema.String, providerId: Schema.String, userId: Schema.optional(Schema.String) }),
15
17
  Result: Schema.Struct({ id: Schema.String }),
16
18
  });
@@ -18,7 +20,7 @@ export const accountRoleSeed = Effect.fn("Identity.accountRoleSeed")(function* (
18
20
  for (const account of listed) {
19
21
  const users = yield* findUsers({ ...account, userId }).pipe(Effect.mapError(() => new AuthUnavailable({ message: "Could not access provider accounts" })));
20
22
  for (const user of users) {
21
- yield* assignRole(access, user.id, role);
23
+ yield* assignRole(access, user.id, role, options);
22
24
  }
23
25
  }
24
26
  });
@@ -1 +1 @@
1
- {"version":3,"file":"accountRoleSeed.js","sourceRoot":"","sources":["../../../src/server/better-auth/accountRoleSeed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,0BAA0B,CAAC,CAAC,QAAQ,CAAC,EAC7E,MAA2D,EAC3D,IAAoB,EACpB,QAAwD;IAExD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC;IAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAuB,CAAC;IAC7D,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC;IACvC,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC;QACnC,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;;0BAE3B,UAAU,sBAAsB,SAAS;KAC9D,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA,kBAAkB,MAAM,EAAE,EAAE;QAC3E,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,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AC"}
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/database.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,MAAM,EAAwB,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA4BvC,eAAO,MAAM,kBAAkB,oEA+C7B,CAAC"}