@shivaedev/identity 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +21 -3
- 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/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/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 +4 -13
- package/dist/server/better-auth/mount.d.ts.map +1 -1
- package/dist/server/better-auth/mount.js +4 -5
- 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 +6 -1
- package/dist/server/better-auth/testDatabase.d.ts.map +1 -1
- package/dist/server/better-auth/testDatabase.js +13 -2
- package/dist/server/better-auth/testDatabase.js.map +1 -1
- package/dist/sessions.d.ts +4 -4
- package/dist/sessions.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/server/adapters/betterAuthSessions.ts +7 -1
- 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/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 -5
- 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 +14 -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,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.1 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Update `@shivaedev/access` from 0.3.2 to 0.3.3.
|
|
8
|
+
- Update `@shivaedev/contract` from 0.28.0 to 0.29.0.
|
|
9
|
+
- Update `@shivaedev/errors` from 0.2.0 to 0.3.0.
|
|
10
|
+
|
|
11
|
+
## 0.11.0 - 2026-10-31
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- 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.
|
|
16
|
+
- 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.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Server and the platform dependency shell no longer declare `pg` as an optional peer; its PostgreSQL integration uses the native pool from sql.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- 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.
|
|
25
|
+
- 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.
|
|
26
|
+
- 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.
|
|
27
|
+
- 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.
|
|
28
|
+
- A trusted peer without the configured forwarded header falls back to its connection address in development and tests as well as production.
|
|
29
|
+
|
|
30
|
+
### Breaking
|
|
31
|
+
|
|
32
|
+
- 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.
|
|
33
|
+
- Replace `authTestDatabase(pool)` with `yield* authTestDatabase` in identity test fixtures, provided with the application's `SqlClient`.
|
|
34
|
+
- 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.
|
|
35
|
+
- 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 } })`.
|
|
36
|
+
- 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.
|
|
37
|
+
- 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.
|
|
38
|
+
|
|
3
39
|
## 0.10.1 - 2026-10-31
|
|
4
40
|
|
|
5
41
|
### Fixed
|
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ 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
|
|
|
@@ -115,8 +115,24 @@ The mount reads `BETTER_AUTH_SECRET` unless options supply `secret`. `PUBLIC_URL
|
|
|
115
115
|
|
|
116
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.
|
|
117
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
|
+
|
|
118
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.
|
|
119
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
|
+
|
|
120
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.
|
|
121
137
|
|
|
122
138
|
### Role assignments
|
|
@@ -205,7 +221,7 @@ const authentication = Effect.gen(function* () {
|
|
|
205
221
|
|
|
206
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.
|
|
207
223
|
|
|
208
|
-
`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`.
|
|
209
225
|
|
|
210
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.
|
|
211
227
|
|
|
@@ -475,6 +491,8 @@ Use `testUtils()` from `better-auth/plugins` in a test-only Better Auth instance
|
|
|
475
491
|
|
|
476
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.
|
|
477
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.
|
|
495
|
+
|
|
478
496
|
```ts
|
|
479
497
|
import { betterAuth } from "better-auth";
|
|
480
498
|
import { testUtils } from "better-auth/plugins";
|
|
@@ -535,7 +553,7 @@ With database-backed sessions and cookie caching disabled, revocation rejects th
|
|
|
535
553
|
|
|
536
554
|
### Sweep expired sessions in a worker
|
|
537
555
|
|
|
538
|
-
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.
|
|
539
557
|
|
|
540
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.
|
|
541
559
|
|
|
@@ -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,C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AAY,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,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardening.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/hardening.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMvG,MAAM,mBAAmB,GAAG;IAC3B,KAAK,EAAE;QACN,MAAM,EAAE;YACP;gBACC,OAAO,EAAE,oBAAoB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;oBAC3C,MAAM,QAAQ,GAAY,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;oBAC7C,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;wBAC9H,MAAM,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;oBAC1G,CAAC;oBACD,yFAAyF;oBACzF,MAAM,oBAAoB,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnI,CAAC,CAAC;gBACF,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,eAAe;aAC9C;SACD;KACD;IACD,EAAE,EAAE,gCAAgC;CACT,CAAC;AAE7B,MAAM,UAAU,aAAa,CAAqC,OAAiB,EAAE,SAAS,GAA+B,EAAE;IAC9H,OAAO;QACN,GAAG,OAAO;QACV,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI;YAC7C,GAAG,OAAO,CAAC,gBAAgB;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,SAAS,MAAM,CAAO,MAA2B;IAChD,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,6BAA6B,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC;AAED,KAAK,UAAU,gBAAgB,CAC9B,MAA8B,EAC9B,SAAiI;IAEjI,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;I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AAI,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1G,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO,WAAW,CAAC;QACpB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IACzC,CAAC,CAAC;IACF,OAAO;QACN,aAAa,EAAE;YACd,GAAG,OAAO,CAAC,aAAa;YACxB,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;SAC7G;QACD,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,gBAAgB,EAAE;KAC3C,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,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"allowedAccounts.js","sourceRoot":"","sources":["../../../src/server/better-auth/allowedAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE9D,MAAM,eAAe,GAAG,MAAM,CAAC,MA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,IAAI,EAAE,EAAE,CAAC;IACnG,CAAC,CAAC;IACF,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,GAAG,UAAU,IAAI,SAAS,EAAE,CAAC;CAC3F,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAChD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE;IACxE,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CACxC,KAAK;SACH,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CACrC;IACD,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;CAC9D,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bearer } from "better-auth/plugins/bearer";
|
|
2
|
+
import { Result } from "effect";
|
|
2
3
|
export function withBearerSessions(options, enabled) {
|
|
3
4
|
return enabled ? { ...options, plugins: [...(options.plugins ?? []), bearer({ requireSignature: true })] } : options;
|
|
4
5
|
}
|
|
@@ -28,11 +29,16 @@ export async function cookieSessionResponse(response) {
|
|
|
28
29
|
.filter((header) => header.trim().toLowerCase() !== "set-auth-token")
|
|
29
30
|
.join(","));
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const init = { headers, status: response.status, statusText: response.statusText };
|
|
33
|
+
if ((response.status >= 300 && response.status < 400) || response.body === null || !headers.get("content-type")?.includes("application/json")) {
|
|
34
|
+
return new Response(response.body, init);
|
|
35
|
+
}
|
|
36
|
+
const bytes = await response.arrayBuffer();
|
|
37
|
+
const body = Result.try(() => JSON.parse(new TextDecoder().decode(bytes), (key, value) => (key === "token" ? undefined : value)));
|
|
38
|
+
if (Result.isFailure(body)) {
|
|
39
|
+
return new Response(bytes, init);
|
|
33
40
|
}
|
|
34
|
-
const body = JSON.parse(await response.text(), (key, value) => (key === "token" ? undefined : value));
|
|
35
41
|
headers.delete("content-length");
|
|
36
|
-
return Response.json(body,
|
|
42
|
+
return Response.json(body.success, init);
|
|
37
43
|
}
|
|
38
44
|
//# sourceMappingURL=bearerSessions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bearerSessions.js","sourceRoot":"","sources":["../../../src/server/better-auth/bearerSessions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"bearerSessions.js","sourceRoot":"","sources":["../../../src/server/better-auth/bearerSessions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,MAAM,UAAU,kBAAkB,CAAqC,OAAiB,EAAE,OAAgB;IACzG,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACtH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAgB,EAAE,UAAkB;IACpE,OAAO,CACN,OAAO;SACL,GAAG,CAAC,QAAQ,CAAC;QACd,EAAE,KAAK,CAAC,GAAG,CAAC;SACX,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,CAAC,KAAK,IAAI,CACvE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAgB,EAAE,UAAkB;IAClE,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;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,KAAK,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,GAAY,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,KAAc,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACpJ,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACjC,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -4,5 +4,8 @@ export declare function clientIpHeaders(options: {
|
|
|
4
4
|
readonly clientIpHeader: string;
|
|
5
5
|
readonly ipv6Subnet?: number | undefined;
|
|
6
6
|
readonly trustedProxy?: string | undefined;
|
|
7
|
-
}): (request: HttpServerRequest.HttpServerRequest, web: Request) =>
|
|
7
|
+
}): (request: HttpServerRequest.HttpServerRequest, web: Request) => {
|
|
8
|
+
address: string | null;
|
|
9
|
+
source: string;
|
|
10
|
+
};
|
|
8
11
|
//# sourceMappingURL=clientIp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientIp.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/clientIp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAErD,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C,
|
|
1
|
+
{"version":3,"file":"clientIp.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/clientIp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAErD,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C,aAYiB,iBAAiB,CAAC,iBAAiB,OAAO,OAAO;;;EAclE"}
|
|
@@ -12,10 +12,13 @@ export function clientIpHeaders(options) {
|
|
|
12
12
|
trustedProxies: trustedProxyRanges(options.trustedProxy),
|
|
13
13
|
},
|
|
14
14
|
};
|
|
15
|
+
const resolved = {
|
|
16
|
+
advanced: { ipAddress: { ...advanced.ipAddress, ipAddressHeaders: [PEER_IP_HEADER], trustedProxies: [] } },
|
|
17
|
+
};
|
|
15
18
|
return (request, web) => {
|
|
16
19
|
web.headers.delete(PEER_IP_HEADER);
|
|
17
20
|
const trusted = Option.exists(request.remoteAddress, trustedPeer);
|
|
18
|
-
const forwardedIp = trusted ? getIP(web, { advanced }) : null;
|
|
21
|
+
const forwardedIp = trusted && web.headers.has(options.clientIpHeader) ? getIP(web, { advanced }) : null;
|
|
19
22
|
if (!trusted) {
|
|
20
23
|
web.headers.delete("x-forwarded-for");
|
|
21
24
|
web.headers.delete(options.clientIpHeader);
|
|
@@ -24,6 +27,7 @@ export function clientIpHeaders(options) {
|
|
|
24
27
|
if (address !== undefined) {
|
|
25
28
|
web.headers.set(PEER_IP_HEADER, address);
|
|
26
29
|
}
|
|
30
|
+
return { address: getIP(web, resolved), source: forwardedIp === null ? "peer" : "forwarded" };
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
33
|
//# sourceMappingURL=clientIp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientIp.js","sourceRoot":"","sources":["../../../src/server/better-auth/clientIp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,UAAU,eAAe,CAAC,OAI/B;IACA,MAAM,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG;QAChB,SAAS,EAAE;YACV,gBAAgB,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC;YAC1C,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;YAC/E,cAAc,EAAE,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC;SACxD;KACD,CAAC;IACF,OAAO,CAAC,OAA4C,EAAE,GAAY,EAAE,EAAE;QACrE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,C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,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACzG,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACtC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,OAAO,GAAG,WAAW,IAAI,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC5E,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC3B,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/F,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type BetterAuthOptions } from "better-auth";
|
|
2
2
|
import { Config, Effect } from "effect";
|
|
3
3
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
4
|
+
import { type BetterAuthHardeningOptions } from "#server/better-auth/adapters/hardening.ts";
|
|
4
5
|
import { type BearerSessionsOptions } from "#server/better-auth/bearerSessions.ts";
|
|
5
6
|
import { type SignInPolicy } from "#server/better-auth/signInGate.ts";
|
|
6
7
|
export interface BetterAuthMountOptions<E = never, R = never> {
|
|
7
8
|
readonly bearerSessions?: BearerSessionsOptions | undefined;
|
|
9
|
+
readonly hardening?: BetterAuthHardeningOptions;
|
|
8
10
|
readonly roles?: RoleSet;
|
|
9
11
|
readonly signIn?: SignInPolicy<E, R> | undefined;
|
|
10
12
|
}
|
|
@@ -249,19 +251,8 @@ export declare const betterAuthMount: <const TOptions extends BetterAuthOptions,
|
|
|
249
251
|
revokeUnadmitted: Effect.Effect<import("#server/better-auth/revokeUnadmitted.ts").RevokedSessions, E | import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Config.ConfigError, never>;
|
|
250
252
|
routes: import("effect/Layer").Layer<never, never, import("effect/http/HttpRouter").HttpRouter>;
|
|
251
253
|
sessions: {
|
|
252
|
-
roles?: RoleSet;
|
|
253
|
-
provider: import("../session.ts").SessionProvider<
|
|
254
|
-
readonly user: {
|
|
255
|
-
readonly email: string;
|
|
256
|
-
readonly id: string;
|
|
257
|
-
readonly name: string;
|
|
258
|
-
readonly permissions?: readonly {
|
|
259
|
-
readonly name: string;
|
|
260
|
-
readonly strength: "any" | "own";
|
|
261
|
-
}[];
|
|
262
|
-
readonly role?: string | null | undefined;
|
|
263
|
-
};
|
|
264
|
-
}>;
|
|
254
|
+
readonly roles?: RoleSet;
|
|
255
|
+
readonly provider: import("../session.ts").SessionProvider<import("../session.ts").UserSessionShape>;
|
|
265
256
|
};
|
|
266
257
|
}, Config.ConfigError, R | import("effect/Scope").Scope>;
|
|
267
258
|
//# sourceMappingURL=mount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,KAAK,qBAAqB,EAAsB,MAAM,uCAAuC,CAAC;AAKvG,OAAO,EAAsB,KAAK,YAAY,EAAc,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,KAAK,0BAA0B,EAAiB,MAAM,2CAA2C,CAAC;AAE3G,OAAO,EAAE,KAAK,qBAAqB,EAAsB,MAAM,uCAAuC,CAAC;AAKvG,OAAO,EAAsB,KAAK,YAAY,EAAc,MAAM,mCAAmC,CAAC;AAKtG,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK;IAC3D,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,0BAA0B,CAAC;IAChD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;CACjD;AAED,eAAO,MAAM,eAAe,SAA0D,QAAQ,SAAS,iBAAiB,EAAE,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDA4DpI,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { betterAuth } from "better-auth";
|
|
2
2
|
import { Config, Effect, Option, Redacted } from "effect";
|
|
3
|
+
import { withHardening } from "#server/better-auth/adapters/hardening.ts";
|
|
4
|
+
import { signInPolicyOptions } from "#server/better-auth/adapters/signInPolicyOptions.ts";
|
|
3
5
|
import { withBearerSessions } from "#server/better-auth/bearerSessions.ts";
|
|
4
6
|
import { PEER_IP_HEADER } from "#server/better-auth/clientIp.ts";
|
|
5
7
|
import { memoryRateLimit } from "#server/better-auth/memoryRateLimit.ts";
|
|
6
8
|
import { mountRoutes } from "#server/better-auth/mountRoutes.ts";
|
|
7
9
|
import { revokeUnadmitted } from "#server/better-auth/revokeUnadmitted.ts";
|
|
8
10
|
import { signInGate } from "#server/better-auth/signInGate.ts";
|
|
9
|
-
import { signInPolicyOptions } from "#server/better-auth/signInPolicy.ts";
|
|
10
11
|
import { admittedSessions } from "./admittedSessions.js";
|
|
11
12
|
import { closeRoleEndpoints } from "./closeRoleEndpoints.js";
|
|
12
13
|
import { mountedSessions } from "./mountedSessions.js";
|
|
@@ -17,19 +18,17 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* (
|
|
|
17
18
|
const trustedProxy = Option.getOrUndefined(yield* Config.String("TRUSTED_PROXY").pipe(Config.option));
|
|
18
19
|
const clientIpHeader = yield* Config.String("AUTH_CLIENT_IP_HEADER").pipe(Config.withDefault("x-forwarded-for"));
|
|
19
20
|
const rateLimitEnabled = yield* Config.Boolean("AUTH_RATE_LIMIT_ENABLED").pipe(Config.withDefault(true));
|
|
20
|
-
const context = yield* Effect.context();
|
|
21
|
-
const run = Effect.runPromiseWith(context);
|
|
22
21
|
const policy = mount.signIn ?? {};
|
|
23
22
|
if (policy.accounts !== undefined) {
|
|
24
23
|
yield* policy.accounts;
|
|
25
24
|
}
|
|
26
25
|
const gate = yield* signInGate(policy);
|
|
27
|
-
const gated = signInPolicyOptions(options, gate,
|
|
26
|
+
const gated = yield* signInPolicyOptions(options, gate, () => auth.$context);
|
|
28
27
|
const rateLimit = options.rateLimit;
|
|
29
28
|
const customStorage = rateLimit?.customStorage ?? (rateLimit?.storage === undefined || rateLimit.storage === "memory" ? yield* memoryRateLimit : undefined);
|
|
30
29
|
const configured = mount.roles === undefined ? options : closeRoleEndpoints(options);
|
|
31
30
|
const auth = betterAuth({
|
|
32
|
-
...withBearerSessions(configured, mount.bearerSessions !== undefined),
|
|
31
|
+
...withHardening(withBearerSessions(configured, mount.bearerSessions !== undefined), mount.hardening),
|
|
33
32
|
advanced: {
|
|
34
33
|
useSecureCookies: Option.isSome(publicUrl) && publicUrl.value.protocol === "https:",
|
|
35
34
|
...options.advanced,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EAA8B,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAyC,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACtG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EAAmC,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC3G,OAAO,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,EAA8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,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,iBAAiB,qEAqBxE"}
|
|
@@ -38,14 +38,18 @@ const authResponse = Effect.fnUntraced(function* (auth, web, options) {
|
|
|
38
38
|
url.searchParams.set("disableCookieCache", "true");
|
|
39
39
|
}
|
|
40
40
|
const request = sessionRequest ? new Request(url, web) : web;
|
|
41
|
-
const response = yield* Effect.tryPromise(() => providerResponse(auth, request, options));
|
|
41
|
+
const response = yield* Effect.tryPromise((signal) => providerResponse(auth, new Request(request, { signal }), options));
|
|
42
42
|
return sessionRequest && response.ok && options.roles !== undefined ? yield* sessionPermissions(response, options.roles) : response;
|
|
43
43
|
});
|
|
44
44
|
export function mountRoutes(auth, options) {
|
|
45
45
|
const setClientIp = clientIpHeaders(options);
|
|
46
46
|
return HttpRouter.use((router) => router.add("*", "/api/auth/*", (request) => Effect.gen(function* () {
|
|
47
47
|
const web = yield* HttpServerRequest.toWeb(request);
|
|
48
|
-
setClientIp(request, web);
|
|
48
|
+
const clientIp = setClientIp(request, web);
|
|
49
|
+
yield* Effect.annotateCurrentSpan({
|
|
50
|
+
"auth.rate_limit.address": clientIp.address,
|
|
51
|
+
"auth.rate_limit.address_source": clientIp.source,
|
|
52
|
+
});
|
|
49
53
|
return HttpServerResponse.fromWeb(yield* authResponse(auth, web, options).pipe(Effect.catch(providerFailure)));
|
|
50
54
|
}).pipe(Effect.catch(() => Effect.succeed(HttpServerResponse.text("Authentication is temporarily unavailable", { status: HttpStatus.fromLiteral("ServiceUnavailable") }))))));
|
|
51
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mountRoutes.js","sourceRoot":"","sources":["../../../src/server/better-auth/mountRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,UAAU,MAAM,wB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AC,mBAAmB,CAAC;YACjC,yBAAyB,EAAE,QAAQ,CAAC,OAAO;YAC3C,gCAAgC,EAAE,QAAQ,CAAC,MAAM;SACjD,CAAC,CAAC;QACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAChH,CAAC,CAAC,CAAC,IAAI,CACN,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CACjB,MAAM,CAAC,OAAO,CACb,kBAAkB,CAAC,IAAI,CAAC,2CAA2C,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAC9H,CACD,CACD,CACD,CACD,CAAC;AACH,CAAC"}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
2
2
|
import type { GetSession } from "#server/adapters/betterAuthSessions.ts";
|
|
3
|
-
import type { SessionProvider, SessionShape } from "#server/session.ts";
|
|
3
|
+
import type { SessionProvider, SessionShape, UserSessionShape } from "#server/session.ts";
|
|
4
4
|
export declare function mountedSessions(lookup: unknown, admit: <TSession extends SessionShape>(getSession: GetSession<TSession>) => SessionProvider<TSession>, roles?: RoleSet): {
|
|
5
|
-
roles?: RoleSet;
|
|
6
|
-
provider: SessionProvider<
|
|
7
|
-
readonly user: {
|
|
8
|
-
readonly email: string;
|
|
9
|
-
readonly id: string;
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly permissions?: readonly {
|
|
12
|
-
readonly name: string;
|
|
13
|
-
readonly strength: "any" | "own";
|
|
14
|
-
}[];
|
|
15
|
-
readonly role?: string | null | undefined;
|
|
16
|
-
};
|
|
17
|
-
}>;
|
|
5
|
+
readonly roles?: RoleSet;
|
|
6
|
+
readonly provider: SessionProvider<UserSessionShape>;
|
|
18
7
|
};
|
|
19
8
|
//# sourceMappingURL=mountedSessions.d.ts.map
|