@shivaedev/identity 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +61 -40
- package/dist/server/adapters/betterAuthSessions.d.ts.map +1 -1
- package/dist/server/adapters/betterAuthSessions.js +5 -1
- package/dist/server/adapters/betterAuthSessions.js.map +1 -1
- package/dist/server/better-auth/adapters/database.d.ts +4 -0
- package/dist/server/better-auth/adapters/database.d.ts.map +1 -0
- package/dist/server/better-auth/adapters/database.js +36 -0
- package/dist/server/better-auth/adapters/database.js.map +1 -0
- package/dist/server/better-auth/adapters/hardening.d.ts +6 -0
- package/dist/server/better-auth/adapters/hardening.d.ts.map +1 -0
- package/dist/server/better-auth/adapters/hardening.js +30 -0
- package/dist/server/better-auth/adapters/hardening.js.map +1 -0
- package/dist/server/better-auth/{signInPolicy.d.ts → adapters/signInPolicyOptions.d.ts} +3 -4
- package/dist/server/better-auth/adapters/signInPolicyOptions.d.ts.map +1 -0
- package/dist/server/better-auth/{signInPolicy.js → adapters/signInPolicyOptions.js} +8 -5
- package/dist/server/better-auth/adapters/signInPolicyOptions.js.map +1 -0
- package/dist/server/better-auth/adapters/transaction.d.ts +4 -0
- package/dist/server/better-auth/adapters/transaction.d.ts.map +1 -0
- package/dist/server/better-auth/adapters/transaction.js +29 -0
- package/dist/server/better-auth/adapters/transaction.js.map +1 -0
- package/dist/server/better-auth/allowedAccounts.d.ts +1 -1
- package/dist/server/better-auth/allowedAccounts.d.ts.map +1 -1
- package/dist/server/better-auth/allowedAccounts.js +7 -2
- package/dist/server/better-auth/allowedAccounts.js.map +1 -1
- package/dist/server/better-auth/bearerSessions.d.ts.map +1 -1
- package/dist/server/better-auth/bearerSessions.js +10 -4
- package/dist/server/better-auth/bearerSessions.js.map +1 -1
- package/dist/server/better-auth/clientIp.d.ts +4 -1
- package/dist/server/better-auth/clientIp.d.ts.map +1 -1
- package/dist/server/better-auth/clientIp.js +5 -1
- package/dist/server/better-auth/clientIp.js.map +1 -1
- package/dist/server/better-auth/mount.d.ts +5 -16
- package/dist/server/better-auth/mount.d.ts.map +1 -1
- package/dist/server/better-auth/mount.js +4 -30
- package/dist/server/better-auth/mount.js.map +1 -1
- package/dist/server/better-auth/mountRoutes.d.ts.map +1 -1
- package/dist/server/better-auth/mountRoutes.js +6 -2
- package/dist/server/better-auth/mountRoutes.js.map +1 -1
- package/dist/server/better-auth/mountedSessions.d.ts +3 -14
- package/dist/server/better-auth/mountedSessions.d.ts.map +1 -1
- package/dist/server/better-auth/mountedSessions.js +1 -1
- package/dist/server/better-auth/mountedSessions.js.map +1 -1
- package/dist/server/better-auth/sessionAdministration.d.ts.map +1 -1
- package/dist/server/better-auth/sessionAdministration.js +2 -1
- package/dist/server/better-auth/sessionAdministration.js.map +1 -1
- package/dist/server/better-auth/sweepExpiredSessions.d.ts.map +1 -1
- package/dist/server/better-auth/sweepExpiredSessions.js +3 -2
- package/dist/server/better-auth/sweepExpiredSessions.js.map +1 -1
- package/dist/server/better-auth/testDatabase.d.ts +17 -12
- package/dist/server/better-auth/testDatabase.d.ts.map +1 -1
- package/dist/server/better-auth/testDatabase.js +20 -20
- package/dist/server/better-auth/testDatabase.js.map +1 -1
- package/dist/server/revalidateStream.d.ts +1 -1
- package/dist/server/revalidateStream.d.ts.map +1 -1
- package/dist/server/revalidateStream.js +2 -2
- package/dist/server/revalidateStream.js.map +1 -1
- package/package.json +9 -15
- package/src/server/adapters/betterAuthSessions.ts +7 -1
- package/src/server/better-auth/adapters/database.ts +62 -0
- package/src/server/better-auth/adapters/hardening.ts +36 -0
- package/src/server/better-auth/{signInPolicy.ts → adapters/signInPolicyOptions.ts} +11 -5
- package/src/server/better-auth/adapters/transaction.ts +37 -0
- package/src/server/better-auth/allowedAccounts.ts +10 -2
- package/src/server/better-auth/bearerSessions.ts +10 -4
- package/src/server/better-auth/clientIp.ts +5 -1
- package/src/server/better-auth/mount.ts +5 -40
- package/src/server/better-auth/mountRoutes.ts +6 -2
- package/src/server/better-auth/mountedSessions.ts +3 -3
- package/src/server/better-auth/sessionAdministration.ts +2 -1
- package/src/server/better-auth/sweepExpiredSessions.ts +3 -2
- package/src/server/better-auth/testDatabase.ts +27 -26
- package/src/server/revalidateStream.ts +2 -2
- package/dist/server/better-auth/signInPolicy.d.ts.map +0 -1
- package/dist/server/better-auth/signInPolicy.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Read a user's stored sessions with `authTestDatabase.sessionsFor(userId)`, including native Effect expiry timestamps and clock-relative expiry state. Revoked and swept sessions disappear from the readout.
|
|
8
|
+
- Auth HTTP spans expose the selected rate-limit address and its peer or trusted-forwarded source as `auth.rate_limit.address` and `auth.rate_limit.address_source`, including counted and refused sign-in attempts.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Server and the platform dependency shell no longer declare `pg` as an optional peer; its PostgreSQL integration uses the native pool from sql.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- Validate GitHub ids in `AllowedAccounts` as decimal digits so a login such as `github:octocat` refuses boot with a `ConfigError` naming the entry and expected format. Providers without a known format continue to accept any non-empty id.
|
|
17
|
+
- Better Auth sign-in callbacks run Effects in an adapter with the mount's captured context and the request's AbortSignal. Cancelling an auth request interrupts its waiting sign-in policy.
|
|
18
|
+
- Preserve emailed verification and password-reset redirects behind bearer sessions. Browser responses keep redirect, empty and unparseable bodies intact while parseable JSON still has session tokens removed.
|
|
19
|
+
- Use Effect's clock for session administration expiry filters and expired-session sweeps. Better Auth session providers also reject sessions whose returned `session.expiresAt` has passed, so stories can advance `TestClock` without rewriting stored timestamps.
|
|
20
|
+
- A trusted peer without the configured forwarded header falls back to its connection address in development and tests as well as production.
|
|
21
|
+
|
|
22
|
+
### Breaking
|
|
23
|
+
|
|
24
|
+
- Replace `authDatabase(url, { max, application_name })` from identity's `server/better-auth/mount.ts` with `yield* betterAuthDatabase()` from `server/better-auth/adapters/database.ts`, inside the application's SQL environment. Pass the result as Better Auth's `database`. Use sql's `postgresLayer` for standalone processes; database-backed `appHost` exposes the client inside its `application` Effect. Move connection settings to `maxConnections` and `applicationName` on that SQL Layer. Auth now shares its connection budget and lifecycle; remove direct `pg` dependencies when no longer used.
|
|
25
|
+
- Replace `authTestDatabase(pool)` with `yield* authTestDatabase` in identity test fixtures, provided with the application's `SqlClient`.
|
|
26
|
+
- When applying the generated starter update, replace `poolSizes.auth` with the shared `poolSizes.sql` budget. Auth migrations use the application SQL environment; remove custom `AuthMigrationDatabase` providers.
|
|
27
|
+
- Better Auth mounts require the account's current password for `/change-email`, including signed bearer sessions. Send `password` alongside `newEmail` in the HTTP JSON body; Better Auth's typed `changeEmail` method does not declare this extra field. Passwordless accounts cannot change email under this default. Applications with another account-verification policy can explicitly opt out with `betterAuthMount(options, { hardening: { requirePasswordForEmailChange: false } })`.
|
|
28
|
+
- Better Auth mounts revoke existing sessions after a password reset by default. Applications that intentionally retain sessions must set `emailAndPassword.revokeSessionsOnPasswordReset: false` in their Better Auth options.
|
|
29
|
+
- Move direct imports of `signInPolicyOptions` from `server/better-auth/signInPolicy.ts` to `server/better-auth/adapters/signInPolicyOptions.ts`. Yield the returned Effect when building the mount and remove the runner argument; the adapter captures its own context. The `PolicyRun` type is removed. Applications using `betterAuthMount` need no changes.
|
|
30
|
+
|
|
31
|
+
## 0.10.1 - 2026-10-31
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- End open authenticated streams with `AuthUnavailable` when a session revalidation cannot reach the auth provider. Revoked sessions still end with `Unauthorized`, and live-change subscriptions use identity's shared stream revalidation.
|
|
36
|
+
|
|
3
37
|
## 0.10.0 - 2026-10-31
|
|
4
38
|
|
|
5
39
|
### Added
|
package/README.md
CHANGED
|
@@ -86,18 +86,19 @@ export const sessions = {
|
|
|
86
86
|
|
|
87
87
|
To also accept the transport guard's same-origin requests, pass `sameOrigin: { trustedProxy }`, with the same proxy IP addresses or CIDR ranges as the host. This admits direct loopback HTTP and the forwarded HTTP or HTTPS authority only from a matching transport peer. Session resolution supplies that peer from the HTTP request, including the WebSocket upgrade; RPC message headers cannot supply it. Missing Origins still follow `missing`. Leave `sameOrigin` absent when an explicit public-origin allowlist should be the only authority.
|
|
88
88
|
|
|
89
|
-
The application's `auth` owns its storage and session configuration. A null lookup becomes a missing session. A thrown or rejected lookup is logged in redacted form and fails with the generic `AuthUnavailable` message. It remains a failure even on an RPC with optional authentication.
|
|
89
|
+
The application's `auth` owns its storage and session configuration. A null lookup becomes a missing session. When the lookup returns Better Auth’s `session.expiresAt` as a `Date`, identity also rejects the session at or after that instant using Effect’s current clock. A thrown or rejected lookup is logged in redacted form and fails with the generic `AuthUnavailable` message. It remains a failure even on an RPC with optional authentication.
|
|
90
90
|
|
|
91
91
|
### Mount Better Auth
|
|
92
92
|
|
|
93
93
|
`betterAuthMount(options)` returns the Better Auth instance and a native route Layer for `/api/auth/*`. It accepts Better Auth options, including application plugins and session policy. Merge `routes` into the HTTP host and use `auth.api.getSession` with `betterAuthSessions` for the application's RPC session provider.
|
|
94
94
|
|
|
95
95
|
```ts
|
|
96
|
-
import {
|
|
97
|
-
import {
|
|
96
|
+
import { Effect } from "effect";
|
|
97
|
+
import { betterAuthDatabase } from "@shivaedev/identity/server/better-auth/adapters/database.ts";
|
|
98
|
+
import { betterAuthMount } from "@shivaedev/identity/server/better-auth/mount.ts";
|
|
98
99
|
|
|
99
100
|
const authentication = Effect.gen(function* () {
|
|
100
|
-
const database = yield*
|
|
101
|
+
const database = yield* betterAuthDatabase();
|
|
101
102
|
return yield* betterAuthMount({
|
|
102
103
|
database,
|
|
103
104
|
emailAndPassword: { enabled: true },
|
|
@@ -106,16 +107,32 @@ const authentication = Effect.gen(function* () {
|
|
|
106
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
111
|
|
|
111
|
-
Run this Effect in the host's scope
|
|
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`.
|
|
112
113
|
|
|
113
114
|
The mount reads `BETTER_AUTH_SECRET` unless options supply `secret`. `PUBLIC_URL` supplies the default base URL, trusted origin and HTTPS secure-cookie setting. With it unset, `baseURL.allowedHosts` defaults to `["127.0.0.1:*", "localhost:*"]` over HTTP and `trustedOrigins` defaults to `["http://127.0.0.1:*", "http://localhost:*"]`, accepting both loopback names on any port through a development proxy. Explicit `baseURL` (including `baseURL.allowedHosts`) and `trustedOrigins` options each replace their corresponding default; their lists are not merged. RPC Origin policy remains an application choice.
|
|
114
115
|
|
|
115
116
|
`AUTH_RATE_LIMIT_ENABLED` is a Config boolean that defaults to true and takes precedence over `options.rateLimit.enabled`. Each mount owns scoped in-memory buckets when `storage` is unset or `"memory"`. Application `customStorage`, `"database"` and `"secondary-storage"` selections pass through; Better Auth chooses the rules and client-IP keys.
|
|
116
117
|
|
|
118
|
+
The mount also requires the current account password on `/change-email`. Send it as `password` beside `newEmail` in the JSON body. Missing, empty, non-string, overlong and incorrect passwords are refused with HTTP 400 and `INVALID_PASSWORD`; accounts without a credential password are also refused. The check uses Better Auth's configured password verifier and applies to cookie and signed bearer sessions before an email can change or a verification email can be sent. Better Auth still owns email verification and the rest of the email-change flow.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
await fetch("/api/auth/change-email", {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: { "content-type": "application/json" },
|
|
124
|
+
body: JSON.stringify({ newEmail, password: currentPassword }),
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Better Auth's typed `changeEmail` method does not declare the extra `password` field; send this request through HTTP. To use a different account-verification policy, explicitly pass `{ hardening: { requirePasswordForEmailChange: false } }` as the second argument to `betterAuthMount`. Passwordless applications must make this choice before enabling email changes.
|
|
129
|
+
|
|
130
|
+
Password resets revoke existing sessions by default. Set `emailAndPassword.revokeSessionsOnPasswordReset: false` in the Better Auth options to retain them explicitly. These defaults sit alongside the mount's rate limiting; application plugins and the provider's email-change settings remain in effect.
|
|
131
|
+
|
|
117
132
|
`TRUSTED_PROXY` supplies the same address and CIDR policy used by the host. An untrusted transport peer loses `x-forwarded-for` and the configured client-IP header before Better Auth sees the request. `AUTH_CLIENT_IP_HEADER` defaults to `x-forwarded-for`. Without a trusted proxy, auth rate limiting uses the connection peer address, so different peers have separate buckets and Better Auth receives a client IP without a missing-IP warning. A trusted peer's configured forwarded header takes precedence over the peer address.
|
|
118
133
|
|
|
134
|
+
The auth HTTP server span records the resolved rate-limit address in `auth.rate_limit.address` and its source in `auth.rate_limit.address_source`: `forwarded` for the trusted proxy's configured header, or `peer` for the connection address. These attributes accompany counted sign-in attempts and HTTP 429 refusals, so operators can inspect the choice directly. The recorded address follows Better Auth's normalization, including IPv6 subnet grouping; a trusted peer without a forwarded header records `peer`.
|
|
135
|
+
|
|
119
136
|
For email sign-in through `appHost`, the session record's `ipAddress` follows the same rule. With a trusted peer, `AUTH_CLIENT_IP_HEADER=x-real-ip` stores `X-Real-IP` even if `X-Forwarded-For` supplies a different address; the default header selects the rightmost untrusted address in the `X-Forwarded-For` chain, ignoring trusted proxy hops on the right. With an untrusted peer, neither header can supply the stored address. Sign-in attempts from an untrusted peer share one bucket per path; with a trusted peer and `x-real-ip`, changing `X-Forwarded-For` does not change the bucket, while changing `X-Real-IP` does.
|
|
120
137
|
|
|
121
138
|
### Role assignments
|
|
@@ -181,13 +198,14 @@ Use the WebView's own fetch with `credentials: "omit"` for incremental NDJSON ch
|
|
|
181
198
|
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:
|
|
182
199
|
|
|
183
200
|
```ts
|
|
184
|
-
import {
|
|
201
|
+
import { Effect } from "effect";
|
|
185
202
|
import { allowedAccounts } from "@shivaedev/identity/server/better-auth/allowedAccounts.ts";
|
|
186
|
-
import {
|
|
203
|
+
import { betterAuthDatabase } from "@shivaedev/identity/server/better-auth/adapters/database.ts";
|
|
204
|
+
import { betterAuthMount } from "@shivaedev/identity/server/better-auth/mount.ts";
|
|
187
205
|
import { trustedOrigins } from "@shivaedev/identity/server/origin.ts";
|
|
188
206
|
|
|
189
207
|
const authentication = Effect.gen(function* () {
|
|
190
|
-
const database = yield*
|
|
208
|
+
const database = yield* betterAuthDatabase();
|
|
191
209
|
const mounted = yield* betterAuthMount(
|
|
192
210
|
{ database, session: { cookieCache: { enabled: false } }, socialProviders: { github } },
|
|
193
211
|
{ signIn: { accounts: allowedAccounts, recheckInterval: "5 minutes", rule: inOrganization } },
|
|
@@ -203,7 +221,7 @@ const authentication = Effect.gen(function* () {
|
|
|
203
221
|
|
|
204
222
|
`github` is the application's GitHub client settings. `inOrganization` is the application's rule, `(account: ProviderAccountValue) => Effect<boolean, E, R>`, which asks the provider whether that account belongs to its organization; the mount requires the rule's `R`, and its failures stay typed. Both parts are optional, and a user is admitted when one of their provider accounts is on the list and the rule admits that account.
|
|
205
223
|
|
|
206
|
-
`allowedAccounts` reads `AUTH_ALLOWED_ACCOUNTS` through Effect Config and decodes it with the `AllowedAccounts` Schema: comma-separated `providerId:accountId` entries, such as `github:1001,github:1002` for two GitHub user IDs. A malformed or empty list stops the mount with a `ConfigError`. For another variable name, pass `Config.schema(AllowedAccounts, "NAME")` as `accounts`.
|
|
224
|
+
`allowedAccounts` reads `AUTH_ALLOWED_ACCOUNTS` through Effect Config and decodes it with the `AllowedAccounts` Schema: comma-separated `providerId:accountId` entries, such as `github:1001,github:1002` for two GitHub user IDs. GitHub account IDs must contain decimal digits only; a login such as `github:octocat` stops the mount with a `ConfigError` naming the entry and expected form. Providers without a known format accept any non-empty account ID. Whitespace around providers and IDs is trimmed. A malformed or empty list stops the mount with a `ConfigError`. For another variable name, pass `Config.schema(AllowedAccounts, "NAME")` as `accounts`.
|
|
207
225
|
|
|
208
226
|
At sign-in the mount installs the policy into Better Auth's own hooks. `user.validateUserInfo` checks the provider account from the provider's verified profile before Better Auth creates a user, so a refused sign-up leaves no user behind. Sign-ups without a provider account, such as email and password, are refused while a policy is set. `databaseHooks.session.create.before` checks the stored accounts of a returning user before Better Auth creates the session. A refused OAuth sign-in redirects to the error URL with `error=sign_in_refused`, and a refused API call answers HTTP 403 with code `sign_in_refused`. When the rule fails, the sign-in is refused with `sign_in_unavailable` and no user is created. The application's own `databaseHooks.session.create.before` runs before the policy's, and a session it refuses stays refused.
|
|
209
227
|
|
|
@@ -434,7 +452,7 @@ const sessions = {
|
|
|
434
452
|
};
|
|
435
453
|
```
|
|
436
454
|
|
|
437
|
-
An `AuthUnavailable` failure during revalidation
|
|
455
|
+
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.
|
|
438
456
|
|
|
439
457
|
### Transport headers and request ids
|
|
440
458
|
|
|
@@ -471,7 +489,9 @@ Run the auth schema migration before the app migration. Use `ON DELETE CASCADE`
|
|
|
471
489
|
|
|
472
490
|
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.
|
|
473
491
|
|
|
474
|
-
Use `authTestDatabase
|
|
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.
|
|
493
|
+
|
|
494
|
+
`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.
|
|
475
495
|
|
|
476
496
|
```ts
|
|
477
497
|
import { betterAuth } from "better-auth";
|
|
@@ -533,7 +553,7 @@ With database-backed sessions and cookie caching disabled, revocation rejects th
|
|
|
533
553
|
|
|
534
554
|
### Sweep expired sessions in a worker
|
|
535
555
|
|
|
536
|
-
Better Auth removes an expired session when it is presented. Use `sweepExpiredSessions` from `@shivaedev/identity/server/better-auth/sweepExpiredSessions.ts` to remove expired rows that are never presented again. The Effect reads the application's `SqlClient`, deletes sessions whose `expiresAt` is at or before
|
|
556
|
+
Better Auth removes an expired session when it is presented. Use `sweepExpiredSessions` from `@shivaedev/identity/server/better-auth/sweepExpiredSessions.ts` to remove expired rows that are never presented again. The Effect reads the application's `SqlClient`, deletes sessions whose `expiresAt` is at or before Effect's current time, and returns the number removed. It preserves live sessions and needs no Better Auth mount or auth pool. It assumes the default Better Auth PostgreSQL table and column mappings.
|
|
537
557
|
|
|
538
558
|
Register the Effect with a worker schedule, as the starter does at midnight UTC. SQL and result-decoding failures stay in the Effect's error channel.
|
|
539
559
|
|
|
@@ -541,36 +561,37 @@ Register the Effect with a worker schedule, as the starter does at midnight UTC.
|
|
|
541
561
|
|
|
542
562
|
Import the module that defines the name; there is no package-root entry. Paths below follow `@shivaedev/identity/`.
|
|
543
563
|
|
|
544
|
-
| Module | Names and purpose
|
|
545
|
-
| -------------------------------------------- |
|
|
546
|
-
| `identity.ts` | `RequestId`, `Identity`, `OptionalIdentity`, `SessionUser`, `SessionUserWithProviderAccounts`, `SessionUserSchema`: request-local services and the shared user schema.
|
|
547
|
-
| `middleware.ts` | `RequestTracing`, `Authenticated`, `AuthenticatedUser`, `AuthenticatedUserWithProviderAccounts`, `MaybeAuthenticated`, `IdentityFailures`: native RPC middleware declarations and their shared failure schema.
|
|
548
|
-
| `server/providerFailure.ts` | `providerFailure(cause)`: log a redacted provider failure and fail with `AuthUnavailable`.
|
|
549
|
-
| `permission.ts` | `permissionMiddleware`, `hasPermission`: native permission middleware declarations and predicates over resolved grants.
|
|
550
|
-
| `server/permissions.ts` | `permissionLayer`, `permissionRoute`: permission middleware Layers and HTTP route guards.
|
|
551
|
-
| `server/session.ts` | `authenticatedLayer`, `maybeAuthenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer`, `withSessionUser`, `resolveSession`: session middleware implementations and the identity boundary.
|
|
552
|
-
| `server/adapters/betterAuthSessions.ts` | `betterAuthSessions(getSession, getProviderAccounts?)`: a session provider from Better Auth lookups.
|
|
553
|
-
| `server/origin.ts` | `trustedOrigins({ allow, missing })`: an exact Origin allowlist.
|
|
554
|
-
| `server/local.ts` | `localRpcGuard`, `loopbackOnly`, `sameOrigin`, `trustedProxyPeer`: loopback and proxy guards.
|
|
555
|
-
| `server/trustedProxyRanges.ts` | `trustedProxyRanges(trustedProxy?)`: normalized proxy ranges.
|
|
556
|
-
| `server/proxyRanges.ts` | `proxyRanges(value)`: parse configured proxy ranges.
|
|
557
|
-
| `server/transportHeaders.ts` | `transportHeaders(rpcHeaders)`: the headers used for a transport-level decision.
|
|
558
|
-
| `server/tracing.ts` | `requestTracingLayer({ header?, sensitive? })`: the `RequestTracing` implementation.
|
|
559
|
-
| `server/sessionKeys.ts` | `resolveChanges`: session-scoped change subscriptions for custom change handlers.
|
|
560
|
-
| `server/commandChanges.ts` | `commandChanges(effect, rpc, payload)`: scoped command invalidation for custom authentication middleware.
|
|
561
|
-
| `server/better-auth/mount.ts` | `betterAuthMount(options, { signIn?, bearerSessions?, roles? })`, returning `{ auth, routes, sessions, admittedSessions, revokeUnadmitted }
|
|
562
|
-
| `server/better-auth/
|
|
563
|
-
| `server/better-auth/
|
|
564
|
-
| `server/better-auth/
|
|
565
|
-
| `server/better-auth/
|
|
566
|
-
| `server/better-auth/
|
|
567
|
-
| `server/better-auth/
|
|
568
|
-
| `server/better-auth/
|
|
569
|
-
| `server/better-auth/
|
|
564
|
+
| Module | Names and purpose |
|
|
565
|
+
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
566
|
+
| `identity.ts` | `RequestId`, `Identity`, `OptionalIdentity`, `SessionUser`, `SessionUserWithProviderAccounts`, `SessionUserSchema`: request-local services and the shared user schema. |
|
|
567
|
+
| `middleware.ts` | `RequestTracing`, `Authenticated`, `AuthenticatedUser`, `AuthenticatedUserWithProviderAccounts`, `MaybeAuthenticated`, `IdentityFailures`: native RPC middleware declarations and their shared failure schema. |
|
|
568
|
+
| `server/providerFailure.ts` | `providerFailure(cause)`: log a redacted provider failure and fail with `AuthUnavailable`. |
|
|
569
|
+
| `permission.ts` | `permissionMiddleware`, `hasPermission`: native permission middleware declarations and predicates over resolved grants. |
|
|
570
|
+
| `server/permissions.ts` | `permissionLayer`, `permissionRoute`: permission middleware Layers and HTTP route guards. |
|
|
571
|
+
| `server/session.ts` | `authenticatedLayer`, `maybeAuthenticatedLayer`, `authenticatedUserLayer`, `authenticatedUserWithProviderAccountsLayer`, `withSessionUser`, `resolveSession`: session middleware implementations and the identity boundary. |
|
|
572
|
+
| `server/adapters/betterAuthSessions.ts` | `betterAuthSessions(getSession, getProviderAccounts?)`: a session provider from Better Auth lookups. |
|
|
573
|
+
| `server/origin.ts` | `trustedOrigins({ allow, missing })`: an exact Origin allowlist. |
|
|
574
|
+
| `server/local.ts` | `localRpcGuard`, `loopbackOnly`, `sameOrigin`, `trustedProxyPeer`: loopback and proxy guards. |
|
|
575
|
+
| `server/trustedProxyRanges.ts` | `trustedProxyRanges(trustedProxy?)`: normalized proxy ranges. |
|
|
576
|
+
| `server/proxyRanges.ts` | `proxyRanges(value)`: parse configured proxy ranges. |
|
|
577
|
+
| `server/transportHeaders.ts` | `transportHeaders(rpcHeaders)`: the headers used for a transport-level decision. |
|
|
578
|
+
| `server/tracing.ts` | `requestTracingLayer({ header?, sensitive? })`: the `RequestTracing` implementation. |
|
|
579
|
+
| `server/sessionKeys.ts` | `resolveChanges`: session-scoped change subscriptions for custom change handlers. |
|
|
580
|
+
| `server/commandChanges.ts` | `commandChanges(effect, rpc, payload)`: scoped command invalidation for custom authentication middleware. |
|
|
581
|
+
| `server/better-auth/mount.ts` | `betterAuthMount(options, { signIn?, bearerSessions?, roles? })`, returning `{ auth, routes, sessions, admittedSessions, revokeUnadmitted }`: native auth routes and the sign-in policy. |
|
|
582
|
+
| `server/better-auth/adapters/database.ts` | `betterAuthDatabase()`: Better Auth storage on the application PostgreSQL client. |
|
|
583
|
+
| `server/better-auth/allowedAccounts.ts` | `AllowedAccounts`, `allowedAccounts`: the provider-account list Schema and its `AUTH_ALLOWED_ACCOUNTS` Config. |
|
|
584
|
+
| `server/better-auth/signInGate.ts` | `SignInPolicy`: the `accounts`, `rule` and `recheckInterval` of a sign-in policy. |
|
|
585
|
+
| `server/better-auth/revokeUnadmitted.ts` | `RevokedSessions`: the `{ users, sessions }` counts of a revocation. |
|
|
586
|
+
| `server/better-auth/userProfiles.ts` | Public profile lookups for other users. |
|
|
587
|
+
| `server/better-auth/sweepExpiredSessions.ts` | `sweepExpiredSessions`: delete expired sessions through the application's SQL client and return the number removed. |
|
|
588
|
+
| `server/better-auth/userReference.ts` | `userReference`: the default auth user table and id column for application foreign keys. |
|
|
589
|
+
| `server/better-auth/testDatabase.ts` | `authTestDatabase`: test-only identity/session readouts and faults for the default PostgreSQL auth schema. |
|
|
590
|
+
| `server/better-auth/testing.ts` | `signedInUser(auth, fields)`, `passwordUser(auth, fields)`, `storedProviderAccounts(auth, userId)`: test-only users, minted sessions and credential storage observations. |
|
|
570
591
|
|
|
571
592
|
### Install, setup and limits
|
|
572
593
|
|
|
573
|
-
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
|
|
594
|
+
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`.
|
|
574
595
|
- The package needs Node 24 or newer.
|
|
575
596
|
- 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.
|
|
576
597
|
- Without an `HttpServerRequest`, `transportHeaders` falls back to the supplied RPC headers. An application using another transport must decide what headers it can trust.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"betterAuthSessions.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;AAC5G,MAAM,MAAM,2BAA2B,CAAC,QAAQ,SAAS,YAAY,IAAI,QAAQ,GAAG;IACnF,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG;QAAE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,oBAAoB,EAAE,EAAE,eAAe,GAAG,YAAY,CAAC,CAAA;KAAE,CAAC;CAChJ,CAAC;AACF,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;AAC/H,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,YAAY,EAC/D,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,EAChC,mBAAmB,EAAE,mBAAmB,GACtC,eAAe,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { Effect, Option, Predicate } from "effect";
|
|
1
|
+
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
|
+
const ExpiringSession = Schema.Struct({ session: Schema.Struct({ expiresAt: Schema.Date }) });
|
|
5
6
|
export function betterAuthSessions(getSession, getProviderAccounts) {
|
|
6
7
|
const betterAuthSession = Effect.fn("PlatformRpc.betterAuthSession")(function* (headers) {
|
|
7
8
|
const transport = new globalThis.Headers(headers);
|
|
8
9
|
const session = yield* Effect.tryPromise(() => getSession(transport)).pipe(Effect.catch((error) => providerFailure(error.cause)));
|
|
10
|
+
if (Schema.is(ExpiringSession)(session) && session.session.expiresAt.getTime() <= (yield* Clock.currentTimeMillis)) {
|
|
11
|
+
return Option.none();
|
|
12
|
+
}
|
|
9
13
|
if (session === null || getProviderAccounts === undefined) {
|
|
10
14
|
return Option.fromNullishOr(session);
|
|
11
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"betterAuthSessions.js","sourceRoot":"","sources":["../../../src/server/adapters/betterAuthSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;
|
|
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,CA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Ae,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 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAwB,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiBvC,eAAO,MAAM,kBAAkB,oEA0C7B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect, Exit, Option, Schema, Scope } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { betterAuthTransaction } from "./transaction.js";
|
|
4
|
+
const Result = Schema.Struct({ command: Schema.String, rowCount: Schema.Number, rows: Schema.Array(Schema.Unknown) });
|
|
5
|
+
export const betterAuthDatabase = Effect.fn("Identity.betterAuthDatabase")(function* () {
|
|
6
|
+
const sql = yield* SqlClient.SqlClient;
|
|
7
|
+
const transaction = yield* Effect.serviceOption(sql.transactionService);
|
|
8
|
+
const parent = yield* Scope.Scope;
|
|
9
|
+
const context = yield* Effect.context();
|
|
10
|
+
const run = Effect.runPromiseWith(context);
|
|
11
|
+
const pool = {
|
|
12
|
+
async connect() {
|
|
13
|
+
const scope = await run(Scope.fork(parent));
|
|
14
|
+
const connection = await run((Option.isSome(transaction) ? Effect.succeed(transaction.value[0]) : sql.reserve).pipe(Scope.provide(scope), Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause)))));
|
|
15
|
+
const control = Option.isSome(transaction) ? await run(betterAuthTransaction.pipe(Scope.provide(scope))) : undefined;
|
|
16
|
+
function query(text, parameters = []) {
|
|
17
|
+
if (typeof text !== "string") {
|
|
18
|
+
throw new Error("Better Auth database does not support cursors");
|
|
19
|
+
}
|
|
20
|
+
const nested = control?.(text);
|
|
21
|
+
return (nested === undefined ? run(connection.executeRaw(text, parameters)) : nested.then(() => ({ command: text, rowCount: 0, rows: [] }))).then(Schema.decodeUnknownSync(Result));
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
query,
|
|
25
|
+
release: () => {
|
|
26
|
+
void run(Scope.close(scope, Exit.void));
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
// The application SQL Layer owns pool shutdown.
|
|
31
|
+
end: () => Promise.resolve(),
|
|
32
|
+
options: {},
|
|
33
|
+
};
|
|
34
|
+
return pool;
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAQzD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAQtH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC,6BAA6B,CAAC,CAAC,QAAQ,CAAC;IACnF,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAA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+CAA+C,CAAC,CAAC;gBAClE,CAAC;gBACD,MAAM,MAAM,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;gBAC/B,OAAO,CACN,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CACnI,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;YAC1C,CAAC;YACD,OAAO;gBACN,KAAK;gBACL,OAAO,EAAE,GAAG,EAAE;oBACb,KAAK,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBACzC,CAAC;aACD,CAAC;QACH,CAAC;QACD,gDAAgD;QAChD,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;QAC5B,OAAO,EAAE,EAAE;KACX,CAAC;IACF,OAAO,IAAI,CAAC;AACb,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
export interface BetterAuthHardeningOptions {
|
|
3
|
+
readonly requirePasswordForEmailChange?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function withHardening<TOptions extends BetterAuthOptions>(options: TOptions, hardening?: BetterAuthHardeningOptions): TOptions;
|
|
6
|
+
//# sourceMappingURL=hardening.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardening.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/hardening.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,aAAa,CAAC;AAGvE,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,CAAC,6BAA6B,CAAC,EAAE,OAAO,CAAC;CACjD;AAqBD,wBAAgB,aAAa,CAAC,QAAQ,SAAS,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,GAAE,0BAA+B,GAAG,QAAQ,CASzI"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { APIError, createAuthMiddleware, dispatchAuthEndpoint, verifyPassword } from "better-auth/api";
|
|
2
|
+
const emailChangePassword = {
|
|
3
|
+
hooks: {
|
|
4
|
+
before: [
|
|
5
|
+
{
|
|
6
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
7
|
+
const password = ctx.body?.password;
|
|
8
|
+
if (typeof password !== "string" || password.length === 0 || password.length > ctx.context.password.config.maxPasswordLength) {
|
|
9
|
+
throw new APIError("BAD_REQUEST", { code: "INVALID_PASSWORD", message: "Current password is required" });
|
|
10
|
+
}
|
|
11
|
+
// Bearer conversion finishes after before hooks, so verification needs its own dispatch.
|
|
12
|
+
await dispatchAuthEndpoint(verifyPassword, { asResponse: false, body: { password }, context: ctx.context, headers: ctx.headers });
|
|
13
|
+
}),
|
|
14
|
+
matcher: (ctx) => ctx.path === "/change-email",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
id: "identity-email-change-password",
|
|
19
|
+
};
|
|
20
|
+
export function withHardening(options, hardening = {}) {
|
|
21
|
+
return {
|
|
22
|
+
...options,
|
|
23
|
+
emailAndPassword: options.emailAndPassword && {
|
|
24
|
+
...options.emailAndPassword,
|
|
25
|
+
revokeSessionsOnPasswordReset: options.emailAndPassword.revokeSessionsOnPasswordReset ?? true,
|
|
26
|
+
},
|
|
27
|
+
plugins: [...(options.plugins ?? []), ...(hardening.requirePasswordForEmailChange === false ? [] : [emailChangePassword])],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=hardening.js.map
|
|
@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AgB;YAC3B,6BAA6B,EAAE,OAAO,CAAC,gBAAgB,CAAC,6BAA6B,IAAI,IAAI;SAC7F;QACD,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,6BAA6B,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC;KAC1H,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { BetterAuthOptions, ValidateUserInfoResult, ValidateUserInfoSource } from "better-auth";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { type PolicyStorage, type SignInGate } from "#server/better-auth/signInGate.ts";
|
|
4
|
-
export
|
|
5
|
-
export declare function signInPolicyOptions<E>(options: BetterAuthOptions, gate: SignInGate<E>, run: PolicyRun, storage: () => Promise<PolicyStorage>): {
|
|
4
|
+
export declare const signInPolicyOptions: <E>(options: BetterAuthOptions, gate: SignInGate<E>, storage: () => Promise<PolicyStorage>) => Effect.Effect<{
|
|
6
5
|
databaseHooks: {
|
|
7
6
|
user?: {
|
|
8
7
|
create?: {
|
|
@@ -189,5 +188,5 @@ export declare function signInPolicyOptions<E>(options: BetterAuthOptions, gate:
|
|
|
189
188
|
source: ValidateUserInfoSource;
|
|
190
189
|
}, context: import("better-auth").GenericEndpointContext) => import("better-auth").Awaitable<void | ValidateUserInfoResult>;
|
|
191
190
|
};
|
|
192
|
-
}
|
|
193
|
-
//# sourceMappingURL=
|
|
191
|
+
}, never, never>;
|
|
192
|
+
//# sourceMappingURL=signInPolicyOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signInPolicyOptions.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/signInPolicyOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErG,OAAO,EAAE,MAAM,EAAQ,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,mCAAmC,CAAC;AA2BrG,eAAO,MAAM,mBAAmB,GAAgC,CAAC,kEAGjD,OAAO,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2CpC,CAAC"}
|
|
@@ -18,7 +18,8 @@ async function signingInAccount(source, providers) {
|
|
|
18
18
|
const subject = await provider.accountSubject({ profile, tokens: {} });
|
|
19
19
|
return typeof subject === "string" || typeof subject === "number" ? { accountId: String(subject), providerId: provider.id } : undefined;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export const signInPolicyOptions = Effect.fnUntraced(function* (options, gate, storage) {
|
|
22
|
+
const run = Effect.runPromiseWith(yield* Effect.context());
|
|
22
23
|
const sessionBefore = options.databaseHooks?.session?.create?.before;
|
|
23
24
|
const before = async (session, endpoint) => {
|
|
24
25
|
const own = await sessionBefore?.(session, endpoint);
|
|
@@ -26,7 +27,9 @@ export function signInPolicyOptions(options, gate, run, storage) {
|
|
|
26
27
|
return own;
|
|
27
28
|
}
|
|
28
29
|
const userId = typeof own === "object" && typeof own.data.userId === "string" ? own.data.userId : session.userId;
|
|
29
|
-
const exit = await run(Effect.exit(logged(Effect.flatMap(fromStorage(storage), (auth) => gate.admitsUser(auth, userId))))
|
|
30
|
+
const exit = await run(Effect.exit(logged(Effect.flatMap(fromStorage(storage), (auth) => gate.admitsUser(auth, userId)))), {
|
|
31
|
+
signal: endpoint?.request?.signal,
|
|
32
|
+
});
|
|
30
33
|
if (Exit.isFailure(exit)) {
|
|
31
34
|
throw new APIError("SERVICE_UNAVAILABLE", { code: unavailable.error, message: UNAVAILABLE_MESSAGE });
|
|
32
35
|
}
|
|
@@ -44,7 +47,7 @@ export function signInPolicyOptions(options, gate, run, storage) {
|
|
|
44
47
|
if (account === undefined) {
|
|
45
48
|
return refused;
|
|
46
49
|
}
|
|
47
|
-
const exit = await run(Effect.exit(logged(gate.admits([account]))));
|
|
50
|
+
const exit = await run(Effect.exit(logged(gate.admits([account]))), { signal: endpoint.request?.signal });
|
|
48
51
|
if (Exit.isFailure(exit)) {
|
|
49
52
|
return unavailable;
|
|
50
53
|
}
|
|
@@ -57,5 +60,5 @@ export function signInPolicyOptions(options, gate, run, storage) {
|
|
|
57
60
|
},
|
|
58
61
|
user: { ...options.user, validateUserInfo },
|
|
59
62
|
};
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=signInPolicyOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signInPolicyOptions.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/signInPolicyOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAuC,MAAM,mCAAmC,CAAC;AAKrG,MAAM,eAAe,GAAG,8BAA8B,CAAC;AACvD,MAAM,mBAAmB,GAAG,oCAAoC,CAAC;AACjE,MAAM,OAAO,GAA2B,EAAE,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AACxG,MAAM,WAAW,GAA2B,EAAE,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC;AAEpH,SA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transaction.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAS,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,eAAO,MAAM,qBAAqB,uBAMnB,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,2CAwB/C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Data, Deferred, Effect, Fiber, Scope } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
class Rollback extends Data.TaggedError("BetterAuthRollback") {
|
|
4
|
+
}
|
|
5
|
+
export const betterAuthTransaction = Effect.gen(function* () {
|
|
6
|
+
const sql = yield* SqlClient.SqlClient;
|
|
7
|
+
const context = yield* Effect.context();
|
|
8
|
+
const run = Effect.runPromiseWith(context);
|
|
9
|
+
const scope = yield* Scope.Scope;
|
|
10
|
+
let active;
|
|
11
|
+
return (text) => {
|
|
12
|
+
if (text === "begin") {
|
|
13
|
+
return run(Effect.gen(function* () {
|
|
14
|
+
const ready = yield* Deferred.make();
|
|
15
|
+
const done = yield* Deferred.make();
|
|
16
|
+
const fiber = yield* sql.withTransaction(Deferred.succeed(ready, undefined).pipe(Effect.andThen(Deferred.await(done)))).pipe(Effect.catchTag("BetterAuthRollback", () => Effect.void), Effect.forkIn(scope));
|
|
17
|
+
active = { done, fiber };
|
|
18
|
+
yield* Effect.raceFirst(Deferred.await(ready), Fiber.join(fiber));
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
if (active !== undefined && (text === "commit" || text === "rollback")) {
|
|
22
|
+
const { done, fiber } = active;
|
|
23
|
+
active = undefined;
|
|
24
|
+
return run((text === "commit" ? Deferred.succeed(done, undefined) : Deferred.fail(done, new Rollback())).pipe(Effect.andThen(Fiber.join(fiber))));
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,MAAM,QAAS,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC;CAAG;AAEhE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACxD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAS,CAAC;IAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACjC,IAAI,MAAqH,CAAC;IAC1H,OAAO,CAAC,IAAY,EAA6B,EAAE;QAClD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACtB,OAAO,GAAG,CACT,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;gBACnB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAQ,CAAC;gBAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAkB,CAAC;gBACpD,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAC3H,MAAM,CAAC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EACxD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CACpB,CAAC;gBACF,MAAM,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;gBACzB,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YACnE,CAAC,CAAC,CACF,CAAC;QACH,CAAC;QACD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,UAAU,CAAC,EAAE,CAAC;YACxE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAC/B,MAAM,GAAG,SAAS,CAAC;YACnB,OAAO,GAAG,CACT,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CACrI,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Config, Schema } from "effect";
|
|
2
2
|
export declare const AllowedAccounts: Schema.decodeTo<Schema.$Array<Schema.decodeTo<Schema.Struct<{
|
|
3
|
-
readonly accountId: Schema.
|
|
3
|
+
readonly accountId: Schema.String;
|
|
4
4
|
readonly providerId: Schema.NonEmptyString;
|
|
5
5
|
}>, Schema.String, never, never>>, Schema.String, never, never>;
|
|
6
6
|
export declare const allowedAccounts: Config.Config<readonly {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowedAccounts.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/allowedAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"allowedAccounts.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/allowedAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAwB9D,eAAO,MAAM,eAAe;;;+DAU3B,CAAC;AAEF,eAAO,MAAM,eAAe;;;IAA0D,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { Config, Schema, SchemaGetter } from "effect";
|
|
2
|
-
const
|
|
1
|
+
import { Config, Result, Schema, SchemaGetter } from "effect";
|
|
2
|
+
const GitHubAccountId = Schema.String.check(Schema.isPattern(/^[0-9]+$/u, { expected: "a numeric GitHub account id (digits only)" }));
|
|
3
|
+
const ProviderAccount = Schema.Struct({ accountId: Schema.String, providerId: Schema.NonEmptyString }).check(Schema.makeFilter(({ accountId, providerId }) => {
|
|
4
|
+
const accountIdSchema = providerId === "github" ? GitHubAccountId : Schema.NonEmptyString;
|
|
5
|
+
const decoded = Schema.decodeUnknownResult(accountIdSchema)(accountId);
|
|
6
|
+
return Result.isSuccess(decoded) ? true : `Invalid entry "${providerId}:${accountId}": ${decoded.failure.message}`;
|
|
7
|
+
}));
|
|
3
8
|
const AccountEntry = Schema.String.pipe(Schema.decodeTo(ProviderAccount, {
|
|
4
9
|
decode: SchemaGetter.transform((entry) => {
|
|
5
10
|
const separator = entry.indexOf(":");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowedAccounts.js","sourceRoot":"","sources":["../../../src/server/better-auth/allowedAccounts.ts"],"names":[],"mappings":"AAAA,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3,"file":"bearerSessions.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/bearerSessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"bearerSessions.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/bearerSessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,QAAQ,CAEpH;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAO9E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAQ5E;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwBjF"}
|