@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
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Effect, Option, Predicate } from "effect";
|
|
1
|
+
import { Clock, Effect, Option, Predicate, Schema } from "effect";
|
|
2
2
|
import type { Headers } from "effect/http";
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
4
|
import { type AuthUnavailable, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
5
5
|
import type { ProviderAccountValue } from "#identity.ts";
|
|
6
6
|
import { providerFailure } from "#server/providerFailure.ts";
|
|
7
7
|
import type { SessionProvider, SessionShape } from "#server/session.ts";
|
|
8
|
+
|
|
9
|
+
const ExpiringSession = Schema.Struct({ session: Schema.Struct({ expiresAt: Schema.Date }) });
|
|
10
|
+
|
|
8
11
|
export type GetSession<TSession extends SessionShape> = (headers: globalThis.Headers) => Promise<TSession | null>;
|
|
9
12
|
export type GetProviderAccounts = (headers: globalThis.Headers) => Promise<readonly ProviderAccountValue[]>;
|
|
10
13
|
export type SessionWithProviderAccounts<TSession extends SessionShape> = TSession & {
|
|
@@ -19,6 +22,9 @@ export function betterAuthSessions<TSession extends SessionShape>(getSession: Ge
|
|
|
19
22
|
const betterAuthSession = Effect.fn("PlatformRpc.betterAuthSession")(function* (headers: Headers.Headers) {
|
|
20
23
|
const transport = new globalThis.Headers(headers);
|
|
21
24
|
const session = yield* Effect.tryPromise(() => getSession(transport)).pipe(Effect.catch((error) => providerFailure(error.cause)));
|
|
25
|
+
if (Schema.is(ExpiringSession)(session) && session.session.expiresAt.getTime() <= (yield* Clock.currentTimeMillis)) {
|
|
26
|
+
return Option.none();
|
|
27
|
+
}
|
|
22
28
|
if (session === null || getProviderAccounts === undefined) {
|
|
23
29
|
return Option.fromNullishOr(session);
|
|
24
30
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { Effect, Exit, Option, Schema, Scope } from "effect";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { betterAuthTransaction } from "./transaction.ts";
|
|
5
|
+
|
|
6
|
+
type PostgresPool = Extract<NonNullable<BetterAuthOptions["database"]>, { connect: unknown }>;
|
|
7
|
+
type PoolClient = Awaited<ReturnType<PostgresPool["connect"]>>;
|
|
8
|
+
interface Cursor<R> {
|
|
9
|
+
close: () => Promise<void>;
|
|
10
|
+
read: (count: number) => Promise<R[]>;
|
|
11
|
+
}
|
|
12
|
+
const Result = Schema.Struct({ command: Schema.String, rowCount: Schema.Number, rows: Schema.Array(Schema.Unknown) });
|
|
13
|
+
|
|
14
|
+
interface QueryResult<R> {
|
|
15
|
+
command: "UPDATE" | "DELETE" | "INSERT" | "SELECT" | "MERGE";
|
|
16
|
+
rowCount: number;
|
|
17
|
+
rows: R[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const betterAuthDatabase = Effect.fn("Identity.betterAuthDatabase")(function* () {
|
|
21
|
+
const sql = yield* SqlClient.SqlClient;
|
|
22
|
+
const transaction = yield* Effect.serviceOption(sql.transactionService);
|
|
23
|
+
const parent = yield* Scope.Scope;
|
|
24
|
+
const context = yield* Effect.context<SqlClient.SqlClient>();
|
|
25
|
+
const run = Effect.runPromiseWith(context);
|
|
26
|
+
const pool: PostgresPool = {
|
|
27
|
+
async connect(): Promise<PoolClient> {
|
|
28
|
+
const scope = await run(Scope.fork(parent));
|
|
29
|
+
const connection = await run(
|
|
30
|
+
(Option.isSome(transaction) ? Effect.succeed(transaction.value[0]) : sql.reserve).pipe(
|
|
31
|
+
Scope.provide(scope),
|
|
32
|
+
Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause))),
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
const control = Option.isSome(transaction) ? await run(betterAuthTransaction.pipe(Scope.provide(scope))) : undefined;
|
|
36
|
+
function query<R>(text: string, parameters: readonly unknown[]): Promise<QueryResult<R>>;
|
|
37
|
+
function query<R>(cursor: Cursor<R>): Cursor<R>;
|
|
38
|
+
function query(
|
|
39
|
+
text: string | Cursor<unknown>,
|
|
40
|
+
parameters: readonly unknown[] = [],
|
|
41
|
+
): Promise<Schema.Schema.Type<typeof Result>> | Cursor<unknown> {
|
|
42
|
+
if (typeof text !== "string") {
|
|
43
|
+
throw new Error("Better Auth database does not support cursors");
|
|
44
|
+
}
|
|
45
|
+
const nested = control?.(text);
|
|
46
|
+
return (
|
|
47
|
+
nested === undefined ? run(connection.executeRaw(text, parameters)) : nested.then(() => ({ command: text, rowCount: 0, rows: [] }))
|
|
48
|
+
).then(Schema.decodeUnknownSync(Result));
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
query,
|
|
52
|
+
release: () => {
|
|
53
|
+
void run(Scope.close(scope, Exit.void));
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
// The application SQL Layer owns pool shutdown.
|
|
58
|
+
end: () => Promise.resolve(),
|
|
59
|
+
options: {},
|
|
60
|
+
};
|
|
61
|
+
return pool;
|
|
62
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BetterAuthOptions, BetterAuthPlugin } from "better-auth";
|
|
2
|
+
import { APIError, createAuthMiddleware, dispatchAuthEndpoint, verifyPassword } from "better-auth/api";
|
|
3
|
+
|
|
4
|
+
export interface BetterAuthHardeningOptions {
|
|
5
|
+
readonly requirePasswordForEmailChange?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const emailChangePassword = {
|
|
9
|
+
hooks: {
|
|
10
|
+
before: [
|
|
11
|
+
{
|
|
12
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
13
|
+
const password: unknown = ctx.body?.password;
|
|
14
|
+
if (typeof password !== "string" || password.length === 0 || password.length > ctx.context.password.config.maxPasswordLength) {
|
|
15
|
+
throw new APIError("BAD_REQUEST", { code: "INVALID_PASSWORD", message: "Current password is required" });
|
|
16
|
+
}
|
|
17
|
+
// Bearer conversion finishes after before hooks, so verification needs its own dispatch.
|
|
18
|
+
await dispatchAuthEndpoint(verifyPassword, { asResponse: false, body: { password }, context: ctx.context, headers: ctx.headers });
|
|
19
|
+
}),
|
|
20
|
+
matcher: (ctx) => ctx.path === "/change-email",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
id: "identity-email-change-password",
|
|
25
|
+
} satisfies BetterAuthPlugin;
|
|
26
|
+
|
|
27
|
+
export function withHardening<TOptions extends BetterAuthOptions>(options: TOptions, hardening: BetterAuthHardeningOptions = {}): TOptions {
|
|
28
|
+
return {
|
|
29
|
+
...options,
|
|
30
|
+
emailAndPassword: options.emailAndPassword && {
|
|
31
|
+
...options.emailAndPassword,
|
|
32
|
+
revokeSessionsOnPasswordReset: options.emailAndPassword.revokeSessionsOnPasswordReset ?? true,
|
|
33
|
+
},
|
|
34
|
+
plugins: [...(options.plugins ?? []), ...(hardening.requirePasswordForEmailChange === false ? [] : [emailChangePassword])],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -6,7 +6,6 @@ import { fromStorage, type PolicyStorage, type SignInGate } from "#server/better
|
|
|
6
6
|
|
|
7
7
|
type SessionCreateBefore = NonNullable<NonNullable<NonNullable<NonNullable<BetterAuthOptions["databaseHooks"]>["session"]>["create"]>["before"]>;
|
|
8
8
|
type ValidateUserInfo = NonNullable<NonNullable<BetterAuthOptions["user"]>["validateUserInfo"]>;
|
|
9
|
-
export type PolicyRun = <A, E>(effect: Effect.Effect<A, E>) => Promise<A>;
|
|
10
9
|
|
|
11
10
|
const REFUSED_MESSAGE = "This account may not sign in";
|
|
12
11
|
const UNAVAILABLE_MESSAGE = "Sign-in is temporarily unavailable";
|
|
@@ -30,7 +29,12 @@ async function signingInAccount(
|
|
|
30
29
|
return typeof subject === "string" || typeof subject === "number" ? { accountId: String(subject), providerId: provider.id } : undefined;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
export
|
|
32
|
+
export const signInPolicyOptions = Effect.fnUntraced(function* <E>(
|
|
33
|
+
options: BetterAuthOptions,
|
|
34
|
+
gate: SignInGate<E>,
|
|
35
|
+
storage: () => Promise<PolicyStorage>,
|
|
36
|
+
) {
|
|
37
|
+
const run = Effect.runPromiseWith(yield* Effect.context<never>());
|
|
34
38
|
const sessionBefore = options.databaseHooks?.session?.create?.before;
|
|
35
39
|
const before: SessionCreateBefore = async (session, endpoint) => {
|
|
36
40
|
const own = await sessionBefore?.(session, endpoint);
|
|
@@ -38,7 +42,9 @@ export function signInPolicyOptions<E>(options: BetterAuthOptions, gate: SignInG
|
|
|
38
42
|
return own;
|
|
39
43
|
}
|
|
40
44
|
const userId = typeof own === "object" && typeof own.data.userId === "string" ? own.data.userId : session.userId;
|
|
41
|
-
const exit = await run(Effect.exit(logged(Effect.flatMap(fromStorage(storage), (auth) => gate.admitsUser(auth, userId))))
|
|
45
|
+
const exit = await run(Effect.exit(logged(Effect.flatMap(fromStorage(storage), (auth) => gate.admitsUser(auth, userId)))), {
|
|
46
|
+
signal: endpoint?.request?.signal,
|
|
47
|
+
});
|
|
42
48
|
if (Exit.isFailure(exit)) {
|
|
43
49
|
throw new APIError("SERVICE_UNAVAILABLE", { code: unavailable.error, message: UNAVAILABLE_MESSAGE });
|
|
44
50
|
}
|
|
@@ -56,7 +62,7 @@ export function signInPolicyOptions<E>(options: BetterAuthOptions, gate: SignInG
|
|
|
56
62
|
if (account === undefined) {
|
|
57
63
|
return refused;
|
|
58
64
|
}
|
|
59
|
-
const exit = await run(Effect.exit(logged(gate.admits([account]))));
|
|
65
|
+
const exit = await run(Effect.exit(logged(gate.admits([account]))), { signal: endpoint.request?.signal });
|
|
60
66
|
if (Exit.isFailure(exit)) {
|
|
61
67
|
return unavailable;
|
|
62
68
|
}
|
|
@@ -69,4 +75,4 @@ export function signInPolicyOptions<E>(options: BetterAuthOptions, gate: SignInG
|
|
|
69
75
|
},
|
|
70
76
|
user: { ...options.user, validateUserInfo },
|
|
71
77
|
};
|
|
72
|
-
}
|
|
78
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Data, Deferred, Effect, Fiber, Scope } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
4
|
+
|
|
5
|
+
class Rollback extends Data.TaggedError("BetterAuthRollback") {}
|
|
6
|
+
|
|
7
|
+
export const betterAuthTransaction = Effect.gen(function* () {
|
|
8
|
+
const sql = yield* SqlClient.SqlClient;
|
|
9
|
+
const context = yield* Effect.context<never>();
|
|
10
|
+
const run = Effect.runPromiseWith(context);
|
|
11
|
+
const scope = yield* Scope.Scope;
|
|
12
|
+
let active: { readonly done: Deferred.Deferred<void, Rollback>; readonly fiber: Fiber.Fiber<void, SqlError> } | undefined;
|
|
13
|
+
return (text: string): Promise<void> | undefined => {
|
|
14
|
+
if (text === "begin") {
|
|
15
|
+
return run(
|
|
16
|
+
Effect.gen(function* () {
|
|
17
|
+
const ready = yield* Deferred.make<void>();
|
|
18
|
+
const done = yield* Deferred.make<void, Rollback>();
|
|
19
|
+
const fiber = yield* sql.withTransaction(Deferred.succeed(ready, undefined).pipe(Effect.andThen(Deferred.await(done)))).pipe(
|
|
20
|
+
Effect.catchTag("BetterAuthRollback", () => Effect.void),
|
|
21
|
+
Effect.forkIn(scope),
|
|
22
|
+
);
|
|
23
|
+
active = { done, fiber };
|
|
24
|
+
yield* Effect.raceFirst(Deferred.await(ready), Fiber.join(fiber));
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (active !== undefined && (text === "commit" || text === "rollback")) {
|
|
29
|
+
const { done, fiber } = active;
|
|
30
|
+
active = undefined;
|
|
31
|
+
return run(
|
|
32
|
+
(text === "commit" ? Deferred.succeed(done, undefined) : Deferred.fail(done, new Rollback())).pipe(Effect.andThen(Fiber.join(fiber))),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
37
|
+
});
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { Config, Schema, SchemaGetter } from "effect";
|
|
1
|
+
import { Config, Result, Schema, SchemaGetter } from "effect";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const GitHubAccountId = Schema.String.check(Schema.isPattern(/^[0-9]+$/u, { expected: "a numeric GitHub account id (digits only)" }));
|
|
4
|
+
|
|
5
|
+
const ProviderAccount = Schema.Struct({ accountId: Schema.String, providerId: Schema.NonEmptyString }).check(
|
|
6
|
+
Schema.makeFilter(({ accountId, providerId }) => {
|
|
7
|
+
const accountIdSchema = providerId === "github" ? GitHubAccountId : Schema.NonEmptyString;
|
|
8
|
+
const decoded = Schema.decodeUnknownResult(accountIdSchema)(accountId);
|
|
9
|
+
return Result.isSuccess(decoded) ? true : `Invalid entry "${providerId}:${accountId}": ${decoded.failure.message}`;
|
|
10
|
+
}),
|
|
11
|
+
);
|
|
4
12
|
|
|
5
13
|
const AccountEntry = Schema.String.pipe(
|
|
6
14
|
Schema.decodeTo(ProviderAccount, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BetterAuthOptions } from "better-auth";
|
|
2
2
|
import { bearer } from "better-auth/plugins/bearer";
|
|
3
|
+
import { Result } from "effect";
|
|
3
4
|
|
|
4
5
|
export interface BearerSessionsOptions {
|
|
5
6
|
readonly origins: readonly string[];
|
|
@@ -41,10 +42,15 @@ export async function cookieSessionResponse(response: Response): Promise<Respons
|
|
|
41
42
|
.join(","),
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const init = { headers, status: response.status, statusText: response.statusText };
|
|
46
|
+
if ((response.status >= 300 && response.status < 400) || response.body === null || !headers.get("content-type")?.includes("application/json")) {
|
|
47
|
+
return new Response(response.body, init);
|
|
48
|
+
}
|
|
49
|
+
const bytes = await response.arrayBuffer();
|
|
50
|
+
const body = Result.try((): unknown => JSON.parse(new TextDecoder().decode(bytes), (key, value: unknown) => (key === "token" ? undefined : value)));
|
|
51
|
+
if (Result.isFailure(body)) {
|
|
52
|
+
return new Response(bytes, init);
|
|
46
53
|
}
|
|
47
|
-
const body: unknown = JSON.parse(await response.text(), (key, value: unknown) => (key === "token" ? undefined : value));
|
|
48
54
|
headers.delete("content-length");
|
|
49
|
-
return Response.json(body,
|
|
55
|
+
return Response.json(body.success, init);
|
|
50
56
|
}
|
|
@@ -19,10 +19,13 @@ export function clientIpHeaders(options: {
|
|
|
19
19
|
trustedProxies: trustedProxyRanges(options.trustedProxy),
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
|
+
const resolved = {
|
|
23
|
+
advanced: { ipAddress: { ...advanced.ipAddress, ipAddressHeaders: [PEER_IP_HEADER], trustedProxies: [] } },
|
|
24
|
+
};
|
|
22
25
|
return (request: HttpServerRequest.HttpServerRequest, web: Request) => {
|
|
23
26
|
web.headers.delete(PEER_IP_HEADER);
|
|
24
27
|
const trusted = Option.exists(request.remoteAddress, trustedPeer);
|
|
25
|
-
const forwardedIp = trusted ? getIP(web, { advanced }) : null;
|
|
28
|
+
const forwardedIp = trusted && web.headers.has(options.clientIpHeader) ? getIP(web, { advanced }) : null;
|
|
26
29
|
if (!trusted) {
|
|
27
30
|
web.headers.delete("x-forwarded-for");
|
|
28
31
|
web.headers.delete(options.clientIpHeader);
|
|
@@ -31,5 +34,6 @@ export function clientIpHeaders(options: {
|
|
|
31
34
|
if (address !== undefined) {
|
|
32
35
|
web.headers.set(PEER_IP_HEADER, address);
|
|
33
36
|
}
|
|
37
|
+
return { address: getIP(web, resolved), source: forwardedIp === null ? "peer" : "forwarded" };
|
|
34
38
|
};
|
|
35
39
|
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { type BetterAuthOptions, betterAuth } from "better-auth";
|
|
2
2
|
import { Config, Effect, Option, Redacted } from "effect";
|
|
3
|
-
import { Pool, type PoolClient, type PoolConfig } from "pg";
|
|
4
3
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
4
|
+
import { type BetterAuthHardeningOptions, withHardening } from "#server/better-auth/adapters/hardening.ts";
|
|
5
|
+
import { signInPolicyOptions } from "#server/better-auth/adapters/signInPolicyOptions.ts";
|
|
5
6
|
import { type BearerSessionsOptions, withBearerSessions } from "#server/better-auth/bearerSessions.ts";
|
|
6
7
|
import { PEER_IP_HEADER } from "#server/better-auth/clientIp.ts";
|
|
7
8
|
import { memoryRateLimit } from "#server/better-auth/memoryRateLimit.ts";
|
|
8
9
|
import { mountRoutes } from "#server/better-auth/mountRoutes.ts";
|
|
9
10
|
import { revokeUnadmitted } from "#server/better-auth/revokeUnadmitted.ts";
|
|
10
11
|
import { type PolicyStorage, type SignInPolicy, signInGate } from "#server/better-auth/signInGate.ts";
|
|
11
|
-
import { signInPolicyOptions } from "#server/better-auth/signInPolicy.ts";
|
|
12
12
|
import { admittedSessions } from "./admittedSessions.ts";
|
|
13
13
|
import { closeRoleEndpoints } from "./closeRoleEndpoints.ts";
|
|
14
14
|
import { mountedSessions } from "./mountedSessions.ts";
|
|
15
15
|
|
|
16
16
|
export interface BetterAuthMountOptions<E = never, R = never> {
|
|
17
17
|
readonly bearerSessions?: BearerSessionsOptions | undefined;
|
|
18
|
+
readonly hardening?: BetterAuthHardeningOptions;
|
|
18
19
|
readonly roles?: RoleSet;
|
|
19
20
|
readonly signIn?: SignInPolicy<E, R> | undefined;
|
|
20
21
|
}
|
|
@@ -29,20 +30,18 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* <
|
|
|
29
30
|
const trustedProxy = Option.getOrUndefined(yield* Config.String("TRUSTED_PROXY").pipe(Config.option));
|
|
30
31
|
const clientIpHeader = yield* Config.String("AUTH_CLIENT_IP_HEADER").pipe(Config.withDefault("x-forwarded-for"));
|
|
31
32
|
const rateLimitEnabled = yield* Config.Boolean("AUTH_RATE_LIMIT_ENABLED").pipe(Config.withDefault(true));
|
|
32
|
-
const context = yield* Effect.context<R>();
|
|
33
|
-
const run = Effect.runPromiseWith(context);
|
|
34
33
|
const policy = mount.signIn ?? {};
|
|
35
34
|
if (policy.accounts !== undefined) {
|
|
36
35
|
yield* policy.accounts;
|
|
37
36
|
}
|
|
38
37
|
const gate = yield* signInGate(policy);
|
|
39
|
-
const gated = signInPolicyOptions(options, gate,
|
|
38
|
+
const gated = yield* signInPolicyOptions(options, gate, (): Promise<PolicyStorage> => auth.$context);
|
|
40
39
|
const rateLimit = options.rateLimit;
|
|
41
40
|
const customStorage =
|
|
42
41
|
rateLimit?.customStorage ?? (rateLimit?.storage === undefined || rateLimit.storage === "memory" ? yield* memoryRateLimit : undefined);
|
|
43
42
|
const configured = mount.roles === undefined ? options : closeRoleEndpoints(options);
|
|
44
43
|
const auth = betterAuth({
|
|
45
|
-
...withBearerSessions(configured, mount.bearerSessions !== undefined),
|
|
44
|
+
...withHardening(withBearerSessions(configured, mount.bearerSessions !== undefined), mount.hardening),
|
|
46
45
|
advanced: {
|
|
47
46
|
useSecureCookies: Option.isSome(publicUrl) && publicUrl.value.protocol === "https:",
|
|
48
47
|
...options.advanced,
|
|
@@ -82,37 +81,3 @@ export const betterAuthMount = Effect.fn("Platform.betterAuthMount")(function* <
|
|
|
82
81
|
const sessions = mountedSessions(lookupSession, admit, mount.roles);
|
|
83
82
|
return { admittedSessions: admit, auth, revokeUnadmitted: revoke, routes: authRoutes, sessions };
|
|
84
83
|
});
|
|
85
|
-
|
|
86
|
-
export const authDatabase = Effect.fn("Platform.authDatabase")(function* (
|
|
87
|
-
url: Redacted.Redacted<string>,
|
|
88
|
-
options: Pick<PoolConfig, "max" | "application_name"> = {},
|
|
89
|
-
) {
|
|
90
|
-
const clients = new Set<PoolClient>();
|
|
91
|
-
const run = Effect.runForkWith(yield* Effect.context<never>());
|
|
92
|
-
return yield* Effect.acquireRelease(
|
|
93
|
-
Effect.sync(() => {
|
|
94
|
-
const pool = new Pool({
|
|
95
|
-
...options,
|
|
96
|
-
connectionString: Redacted.value(url),
|
|
97
|
-
});
|
|
98
|
-
pool.on("connect", (client) => clients.add(client));
|
|
99
|
-
pool.on("remove", (client) => clients.delete(client));
|
|
100
|
-
pool.on("error", (error) => {
|
|
101
|
-
run(
|
|
102
|
-
Effect.logDebug({
|
|
103
|
-
event: "auth_database_idle_client_failed",
|
|
104
|
-
message: error.message,
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
return pool;
|
|
109
|
-
}),
|
|
110
|
-
(pool) =>
|
|
111
|
-
Effect.promise(async () => {
|
|
112
|
-
// pg-pool resolves end before its clients finish disconnecting.
|
|
113
|
-
const disconnected = [...clients].map((client) => new Promise<void>((resolve) => client.once("end", resolve)));
|
|
114
|
-
await pool.end();
|
|
115
|
-
await Promise.all(disconnected);
|
|
116
|
-
}),
|
|
117
|
-
);
|
|
118
|
-
});
|
|
@@ -53,7 +53,7 @@ const authResponse = Effect.fnUntraced(function* (auth: MountedAuth, web: Reques
|
|
|
53
53
|
url.searchParams.set("disableCookieCache", "true");
|
|
54
54
|
}
|
|
55
55
|
const request = sessionRequest ? new Request(url, web) : web;
|
|
56
|
-
const response = yield* Effect.tryPromise(() => providerResponse(auth, request, options));
|
|
56
|
+
const response = yield* Effect.tryPromise((signal) => providerResponse(auth, new Request(request, { signal }), options));
|
|
57
57
|
return sessionRequest && response.ok && options.roles !== undefined ? yield* sessionPermissions(response, options.roles) : response;
|
|
58
58
|
});
|
|
59
59
|
export function mountRoutes(auth: MountedAuth, options: MountRouteOptions) {
|
|
@@ -62,7 +62,11 @@ export function mountRoutes(auth: MountedAuth, options: MountRouteOptions) {
|
|
|
62
62
|
router.add("*", "/api/auth/*", (request) =>
|
|
63
63
|
Effect.gen(function* () {
|
|
64
64
|
const web = yield* HttpServerRequest.toWeb(request);
|
|
65
|
-
setClientIp(request, web);
|
|
65
|
+
const clientIp = setClientIp(request, web);
|
|
66
|
+
yield* Effect.annotateCurrentSpan({
|
|
67
|
+
"auth.rate_limit.address": clientIp.address,
|
|
68
|
+
"auth.rate_limit.address_source": clientIp.source,
|
|
69
|
+
});
|
|
66
70
|
return HttpServerResponse.fromWeb(yield* authResponse(auth, web, options).pipe(Effect.catch(providerFailure)));
|
|
67
71
|
}).pipe(
|
|
68
72
|
Effect.catch(() =>
|
|
@@ -2,9 +2,9 @@ import { Schema } from "effect";
|
|
|
2
2
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
3
3
|
import { SessionUserSchema } from "#identity.ts";
|
|
4
4
|
import type { GetSession } from "#server/adapters/betterAuthSessions.ts";
|
|
5
|
-
import type { SessionProvider, SessionShape } from "#server/session.ts";
|
|
5
|
+
import type { SessionProvider, SessionShape, UserSessionShape } from "#server/session.ts";
|
|
6
6
|
|
|
7
|
-
const AuthSession = Schema.NullOr(Schema.Struct({ user: SessionUserSchema }));
|
|
7
|
+
const AuthSession = Schema.NullOr(Schema.Struct({ session: Schema.Struct({ expiresAt: Schema.Date }), user: SessionUserSchema }));
|
|
8
8
|
type SessionLookup = (options: {
|
|
9
9
|
readonly asResponse: false;
|
|
10
10
|
readonly headers: Headers;
|
|
@@ -17,7 +17,7 @@ export function mountedSessions(
|
|
|
17
17
|
lookup: unknown,
|
|
18
18
|
admit: <TSession extends SessionShape>(getSession: GetSession<TSession>) => SessionProvider<TSession>,
|
|
19
19
|
roles?: RoleSet,
|
|
20
|
-
) {
|
|
20
|
+
): { readonly roles?: RoleSet; readonly provider: SessionProvider<UserSessionShape> } {
|
|
21
21
|
const getSession = Schema.decodeUnknownSync(SessionLookup)(lookup);
|
|
22
22
|
return {
|
|
23
23
|
...(roles === undefined ? {} : { roles }),
|
|
@@ -13,13 +13,14 @@ function unavailable() {
|
|
|
13
13
|
export const listSessions = Effect.fn("Identity.listSessions")(function* (input: typeof SessionListInput.Type) {
|
|
14
14
|
yield* requirePermission(yield* SessionUser, ManageSessions);
|
|
15
15
|
const sql = yield* SqlClient.SqlClient;
|
|
16
|
+
const now = DateTime.toDateUtc(yield* DateTime.now);
|
|
16
17
|
const cursor = input.cursor;
|
|
17
18
|
const before = cursor === undefined ? sql`true` : sql`(s."updatedAt", s.id) < (${DateTime.toDateUtc(cursor.lastActivityAt)}, ${cursor.id})`;
|
|
18
19
|
const read = SqlSchema.findAll({
|
|
19
20
|
execute: () => sql`select s.id, s."createdAt" as "startedAt", s."updatedAt" as "lastActivityAt", s."expiresAt",
|
|
20
21
|
json_build_object('id', u.id, 'name', u.name, 'email', u.email) as "user"
|
|
21
22
|
from "session" s join "user" u on u.id = s."userId"
|
|
22
|
-
where s."expiresAt" > now
|
|
23
|
+
where s."expiresAt" > ${now} and ${before}
|
|
23
24
|
order by s."updatedAt" desc, s.id desc limit ${input.limit + 1}`,
|
|
24
25
|
Request: Schema.Void,
|
|
25
26
|
Result: SignedInSession,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { DateTime, Effect, Schema } from "effect";
|
|
2
2
|
import { SqlClient } from "effect/sql";
|
|
3
3
|
|
|
4
4
|
const SweepResult = Schema.Tuple([Schema.Struct({ removed: Schema.NumberFromString })]);
|
|
5
5
|
|
|
6
6
|
export const sweepExpiredSessions = Effect.gen(function* () {
|
|
7
7
|
const sql = yield* SqlClient.SqlClient;
|
|
8
|
+
const now = DateTime.toDateUtc(yield* DateTime.now);
|
|
8
9
|
const rows = yield* sql`with expired as (
|
|
9
|
-
delete from "session" where "expiresAt" <= now
|
|
10
|
+
delete from "session" where "expiresAt" <= ${now} returning 1
|
|
10
11
|
) select count(*)::text as removed from expired`;
|
|
11
12
|
const [result] = yield* Schema.decodeUnknownEffect(SweepResult)(rows);
|
|
12
13
|
return result.removed;
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import
|
|
1
|
+
import { DateTime, Effect, Schema } from "effect";
|
|
2
|
+
import { SqlClient, SqlSchema } from "effect/sql";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const StoredSession = Schema.Struct({ expiresAt: Schema.DateTimeUtcFromDate, id: Schema.String });
|
|
5
|
+
|
|
6
|
+
export const authTestDatabase = Effect.gen(function* () {
|
|
7
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
8
|
+
const readSessions = SqlSchema.findAll({
|
|
9
|
+
execute: (userId) => sql`select id, "expiresAt" from "session" where "userId" = ${userId} order by id`,
|
|
10
|
+
Request: Schema.String,
|
|
11
|
+
Result: StoredSession,
|
|
12
|
+
});
|
|
5
13
|
return {
|
|
6
14
|
expireSessions: (userId?: string) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const result = await pool.query<{ email: string; id: string; userId: string }>(
|
|
22
|
-
'select s.id, s."userId", u.email from "session" s join "user" u on u.id = s."userId" order by u.email, s.id',
|
|
23
|
-
);
|
|
24
|
-
return result.rows;
|
|
25
|
-
}),
|
|
26
|
-
users: Effect.tryPromise(async () => {
|
|
27
|
-
const result = await pool.query<{ email: string; id: string }>('select id, email from "user" order by email');
|
|
28
|
-
return result.rows;
|
|
15
|
+
sql`update "session" set "expiresAt" = now() - interval '1 second' ${userId === undefined ? sql.literal("") : sql`where "userId" = ${userId}`}`.pipe(
|
|
16
|
+
Effect.asVoid,
|
|
17
|
+
),
|
|
18
|
+
omitImageColumn: sql`alter table "user" drop column image`.pipe(Effect.asVoid),
|
|
19
|
+
sessionIpAddresses: sql<{ ipAddress: string | null }>`select "ipAddress" from "session" order by "createdAt", id`,
|
|
20
|
+
sessions: sql<{
|
|
21
|
+
email: string;
|
|
22
|
+
id: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
}>`select s.id, s."userId", u.email from "session" s join "user" u on u.id = s."userId" order by u.email, s.id`,
|
|
25
|
+
sessionsFor: Effect.fnUntraced(function* (userId: string) {
|
|
26
|
+
const sessions = yield* readSessions(userId);
|
|
27
|
+
const now = yield* DateTime.now;
|
|
28
|
+
return sessions.map((session) => ({ ...session, expired: DateTime.toEpochMillis(session.expiresAt) <= DateTime.toEpochMillis(now) }));
|
|
29
29
|
}),
|
|
30
|
+
users: sql<{ email: string; id: string }>`select id, email from "user" order by email`,
|
|
30
31
|
};
|
|
31
|
-
}
|
|
32
|
+
});
|
|
@@ -15,8 +15,8 @@ export function revalidateStream<TSession extends SessionShape>(
|
|
|
15
15
|
return effect;
|
|
16
16
|
}
|
|
17
17
|
const check = Effect.gen(function* () {
|
|
18
|
-
const session = yield* lookup
|
|
19
|
-
if (
|
|
18
|
+
const session = yield* lookup;
|
|
19
|
+
if (Option.isNone(session) || session.value.user.id !== id) {
|
|
20
20
|
return yield* new Unauthorized({ message: "Authentication required" });
|
|
21
21
|
}
|
|
22
22
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signInPolicy.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/signInPolicy.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;AAIrG,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAwB1E,wBA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