refactor: remove the deprecated auth options

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-20 01:38:08 +05:30
co-authored by Claude Opus 5
parent 97d60d0ba8
commit 7f5e1bc3cf
8 changed files with 5 additions and 73 deletions
+1 -9
View File
@@ -160,10 +160,6 @@ export interface AuthEngine {
key: string; key: string;
response: unknown; response: unknown;
name?: string; name?: string;
/** @deprecated Verification uses the RP ID bound to the issued challenge. */
rpId?: string;
/** @deprecated Verification uses the origin bound to the issued challenge. */
origin?: string;
}, },
): Promise<boolean>; ): Promise<boolean>;
beginPasskeyAuthentication(input: { beginPasskeyAuthentication(input: {
@@ -176,10 +172,6 @@ export interface AuthEngine {
response: unknown; response: unknown;
/** Request metadata used only for the resulting session. */ /** Request metadata used only for the resulting session. */
session?: Partial<AuthSession>; session?: Partial<AuthSession>;
/** @deprecated Verification uses the RP ID bound to the issued challenge. */
rpId?: string;
/** @deprecated Verification uses the origin bound to the issued challenge. */
origin?: string;
}): Promise<AuthResult>; }): Promise<AuthResult>;
changePassword( changePassword(
userId: string, userId: string,
@@ -832,7 +824,7 @@ export function createAuthEngine(options: AuthEngineOptions): AuthEngine {
store, store,
onSignedIn: options.onSignedIn, onSignedIn: options.onSignedIn,
onSignedOut: options.onSignedOut, onSignedOut: options.onSignedOut,
onSuccessfulSignUp: options.onSuccessfulSignUp ?? options.onSuccessfullSignUp, onSuccessfulSignUp: options.onSuccessfulSignUp,
async register(input) { async register(input) {
try { try {
+3 -11
View File
@@ -9,11 +9,7 @@ import {
getAuthUser, getAuthUser,
} from "../middleware.ts"; } from "../middleware.ts";
import { resolveAuthSchemas, type AuthSchemaOverrides, type AuthSchemaSet } from "../validation.ts"; import { resolveAuthSchemas, type AuthSchemaOverrides, type AuthSchemaSet } from "../validation.ts";
import type { import type { AuthSessionVerificationHandler } from "../types.ts";
AuthSessionVerificationHandler,
AuthSignedInHandler,
AuthSignedOutHandler,
} from "../types.ts";
function text(value: unknown): string { function text(value: unknown): string {
return typeof value === "string" ? value : value == null ? "" : String(value); return typeof value === "string" ? value : value == null ? "" : String(value);
@@ -53,18 +49,14 @@ export interface AuthHttpOptions {
baseUrl?: string; baseUrl?: string;
schemas?: AuthSchemaOverrides | AuthSchemaSet; schemas?: AuthSchemaOverrides | AuthSchemaSet;
passkey?: AuthPasskeyHttpOptions; passkey?: AuthPasskeyHttpOptions;
/** @deprecated Prefer createAuthEngine({ onSignedIn }). */
onSignedIn?: AuthSignedInHandler;
/** @deprecated Prefer createAuthEngine({ onSignedOut }). */
onSignedOut?: AuthSignedOutHandler;
onSessionVerification?: AuthSessionVerificationHandler; onSessionVerification?: AuthSessionVerificationHandler;
} }
export function createAuthHttpHandlers(options: AuthHttpOptions) { export function createAuthHttpHandlers(options: AuthHttpOptions) {
const engine = options.engine; const engine = options.engine;
const schemas = resolveAuthSchemas(options.schemas); const schemas = resolveAuthSchemas(options.schemas);
const onSignedIn = options.onSignedIn ?? engine.onSignedIn; const onSignedIn = engine.onSignedIn;
const onSignedOut = options.onSignedOut ?? engine.onSignedOut; const onSignedOut = engine.onSignedOut;
const onSuccessfulSignUp = engine.onSuccessfulSignUp; const onSuccessfulSignUp = engine.onSuccessfulSignUp;
function signupRedirect(ctx: Context, value: string | undefined, fallback: string): Response { function signupRedirect(ctx: Context, value: string | undefined, fallback: string): Response {
+1 -17
View File
@@ -4,11 +4,7 @@ import { fileURLToPath } from "node:url";
import { definePlugin, type PluginContext } from "@wrnexus/plugin"; import { definePlugin, type PluginContext } from "@wrnexus/plugin";
import type { AuthEngine } from "./engine.ts"; import type { AuthEngine } from "./engine.ts";
import type { AuthPasskeyHttpOptions } from "./http/index.ts"; import type { AuthPasskeyHttpOptions } from "./http/index.ts";
import type { import type { AuthSessionVerificationHandler } from "./types.ts";
AuthSessionVerificationHandler,
AuthSignedInHandler,
AuthSignedOutHandler,
} from "./types.ts";
import { AUTH_ROUTE_DEFINITIONS, type AuthRouteGroup } from "./routes/definitions.ts"; import { AUTH_ROUTE_DEFINITIONS, type AuthRouteGroup } from "./routes/definitions.ts";
import { import {
clearDefaultAuthEngine, clearDefaultAuthEngine,
@@ -52,10 +48,6 @@ export interface AuthConfig {
baseUrl?: string; baseUrl?: string;
csrf?: boolean; csrf?: boolean;
passkey?: AuthPasskeyHttpOptions; passkey?: AuthPasskeyHttpOptions;
/** @deprecated Prefer createAuthEngine({ onSignedIn }). */
onSignedIn?: AuthSignedInHandler;
/** @deprecated Prefer createAuthEngine({ onSignedOut }). */
onSignedOut?: AuthSignedOutHandler;
/** Shared SSO cookie whose value is an AuthEngine session id. */ /** Shared SSO cookie whose value is an AuthEngine session id. */
sessionCookieName?: string; sessionCookieName?: string;
/** Customize the package forward-auth verification response. */ /** Customize the package forward-auth verification response. */
@@ -94,8 +86,6 @@ interface ResolvedAuthConfig {
baseUrl?: string; baseUrl?: string;
csrf: boolean; csrf: boolean;
passkey?: AuthPasskeyHttpOptions; passkey?: AuthPasskeyHttpOptions;
onSignedIn?: AuthSignedInHandler;
onSignedOut?: AuthSignedOutHandler;
sessionCookieName?: string; sessionCookieName?: string;
onSessionVerification?: AuthSessionVerificationHandler; onSessionVerification?: AuthSessionVerificationHandler;
} }
@@ -156,8 +146,6 @@ function resolveConfig(
baseUrl: raw.baseUrl, baseUrl: raw.baseUrl,
csrf: raw.csrf ?? true, csrf: raw.csrf ?? true,
passkey: raw.passkey, passkey: raw.passkey,
onSignedIn: raw.onSignedIn ?? raw.engine?.onSignedIn,
onSignedOut: raw.onSignedOut ?? raw.engine?.onSignedOut,
sessionCookieName: raw.sessionCookieName, sessionCookieName: raw.sessionCookieName,
onSessionVerification: raw.onSessionVerification, onSessionVerification: raw.onSessionVerification,
}; };
@@ -392,10 +380,6 @@ export function authPlugin(options: AuthPluginOptions = {}) {
passkey: value.passkey, passkey: value.passkey,
onSignedIn: value.onSignedIn,
onSignedOut: value.onSignedOut,
sessionCookieName: value.sessionCookieName, sessionCookieName: value.sessionCookieName,
onSessionVerification: value.onSessionVerification, onSessionVerification: value.onSessionVerification,
-2
View File
@@ -60,8 +60,6 @@ function handlersFor(ctx: Context): AuthHttpHandlers | undefined {
schemas: getDefaultAuthSchemas(), schemas: getDefaultAuthSchemas(),
baseUrl: routeOptions.baseUrl ?? ctx.url.origin, baseUrl: routeOptions.baseUrl ?? ctx.url.origin,
passkey: routeOptions.passkey, passkey: routeOptions.passkey,
onSignedIn: routeOptions.onSignedIn,
onSignedOut: routeOptions.onSignedOut,
onSessionVerification: routeOptions.onSessionVerification, onSessionVerification: routeOptions.onSessionVerification,
}); });
} }
-5
View File
@@ -1,4 +1,3 @@
import type { Context } from "@wrnexus/core";
import type { AuthEngine } from "./engine.ts"; import type { AuthEngine } from "./engine.ts";
import type { AuthPasskeyHttpOptions } from "./http/index.ts"; import type { AuthPasskeyHttpOptions } from "./http/index.ts";
import type { AuthSessionVerificationHandler } from "./types.ts"; import type { AuthSessionVerificationHandler } from "./types.ts";
@@ -8,10 +7,6 @@ export interface DefaultAuthRouteOptions {
baseUrl?: string; baseUrl?: string;
csrf?: boolean; csrf?: boolean;
passkey?: AuthPasskeyHttpOptions; passkey?: AuthPasskeyHttpOptions;
onSignedIn?: (ctx: Context, returnTo?: string) => Response | Promise<Response>;
onSignedOut?: (ctx: Context) => Response | Promise<Response>;
sessionCookieName?: string; sessionCookieName?: string;
onSessionVerification?: AuthSessionVerificationHandler; onSessionVerification?: AuthSessionVerificationHandler;
} }
-2
View File
@@ -420,8 +420,6 @@ export interface AuthEngineOptions {
* redirects to /sign-in. * redirects to /sign-in.
*/ */
onSuccessfulSignUp?: AuthSuccessfulSignUpHandler; onSuccessfulSignUp?: AuthSuccessfulSignUpHandler;
/** @deprecated Misspelled alias; use onSuccessfulSignUp. */
onSuccessfullSignUp?: AuthSuccessfulSignUpHandler;
breachProvider?: PasswordBreachProvider; breachProvider?: PasswordBreachProvider;
passkeys?: PasskeyProvider; passkeys?: PasskeyProvider;
passkeyChallengeStore?: import("./passkeys/index.ts").PasskeyChallengeStore; passkeyChallengeStore?: import("./passkeys/index.ts").PasskeyChallengeStore;
-4
View File
@@ -579,8 +579,6 @@ describe("authentication engine", () => {
await engine.finishPasskeyRegistration(registered.user!.id, { await engine.finishPasskeyRegistration(registered.user!.id, {
key: start.key, key: start.key,
response: {}, response: {},
rpId: "example.test",
origin: "https://example.test",
}), }),
).toBe(true); ).toBe(true);
const auth = await engine.beginPasskeyAuthentication({ const auth = await engine.beginPasskeyAuthentication({
@@ -595,8 +593,6 @@ describe("authentication engine", () => {
await engine.finishPasskeyAuthentication({ await engine.finishPasskeyAuthentication({
key: auth.key, key: auth.key,
response: { id: "cred-1" }, response: { id: "cred-1" },
rpId: "example.test",
origin: "https://example.test",
}) })
).ok, ).ok,
).toBe(true); ).toBe(true);
-23
View File
@@ -3,7 +3,6 @@ import { createPluginRunner } from "@wrnexus/plugin";
import { authPlugin } from "../src/plugin.ts"; import { authPlugin } from "../src/plugin.ts";
import { AUTH_ROUTE_DEFINITIONS } from "../src/routes/definitions.ts"; import { AUTH_ROUTE_DEFINITIONS } from "../src/routes/definitions.ts";
import { readFileSync } from "node:fs"; import { readFileSync } from "node:fs";
import { getDefaultAuthRouteOptions } from "../src/runtime.ts";
test("plugin contributes components, runtime, styles, migration, and toolbar", async () => { test("plugin contributes components, runtime, styles, migration, and toolbar", async () => {
const metadata = new Map<string, unknown>(); const metadata = new Map<string, unknown>();
@@ -70,28 +69,6 @@ test("config.auth controls route groups and migrations without explicit plugin o
expect(contributions.routes.some((route) => route.path === "/api/auth/login")).toBe(true); expect(contributions.routes.some((route) => route.path === "/api/auth/login")).toBe(true);
}); });
test("config.auth resolves navigation hooks from the configured engine", async () => {
const onSignedIn = () => new Response(null, { status: 204 });
const onSignedOut = () => new Response(null, { status: 204 });
const runner = createPluginRunner(authPlugin(), {
root: process.cwd(),
mode: "development",
command: "dev",
metadata: new Map(),
warn() {},
});
await runner.configure({
auth: {
engine: { onSignedIn, onSignedOut } as never,
routes: true,
},
});
expect(getDefaultAuthRouteOptions().onSignedIn).toBe(onSignedIn);
expect(getDefaultAuthRouteOptions().onSignedOut).toBe(onSignedOut);
});
test("auth runtime contains built-in browser schemas", async () => { test("auth runtime contains built-in browser schemas", async () => {
const metadata = new Map<string, unknown>(); const metadata = new Map<string, unknown>();
const runner = createPluginRunner(authPlugin({ includeMigrations: false }), { const runner = createPluginRunner(authPlugin({ includeMigrations: false }), {