Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): remove obsolete auth handler exports (#1121)

Gustavo Ye22fd00fb02b8
diff --git a/src/web/src/app/api/community/channel-ref/route.test.ts b/src/web/src/app/api/community/channel-ref/route.test.ts
index fc74adde2..9fa89a95a 100644
--- a/src/web/src/app/api/community/channel-ref/route.test.ts
+++ b/src/web/src/app/api/community/channel-ref/route.test.ts
@@ -1,6 +1,5 @@
import { NextRequest } from "next/server"
import { beforeEach, describe, expect, it, vi } from "vitest"
-import type { AuthenticatedHandler } from "@/lib/middleware/auth"
const m = vi.hoisted(() => ({ db: {}, resolve: vi.fn() }))
vi.mock("@/lib/db", () => ({ getPrimaryDb: () => m.db }))
vi.mock("@/lib/community/channel-ref-target", () => ({ resolveChannelRefTarget: m.resolve }))
diff --git a/src/web/src/app/api/community/channels/[id]/pins/access.test.ts b/src/web/src/app/api/community/channels/[id]/pins/access.test.ts
index d10b35b61..12a8f299a 100644
--- a/src/web/src/app/api/community/channels/[id]/pins/access.test.ts
+++ b/src/web/src/app/api/community/channels/[id]/pins/access.test.ts
@@ -13,7 +13,6 @@ import {
communityPin,
communityServerMember,
} from "../../../../../../../../shared/src/db/community-schema"
-import type { AuthenticatedHandler } from "@/lib/middleware/auth"
const { getTableConfig } = createRequire(import.meta.resolve("@alook/shared"))("drizzle-orm/sqlite-core") as {
getTableConfig: (table: object) => { name: string; columns: Array<{ name: string; getSQLType: () => string; default?: unknown }> }
diff --git a/src/web/src/app/api/community/users/search/route.test.ts b/src/web/src/app/api/community/users/search/route.test.ts
index 82b7c88f0..77cefaced 100644
--- a/src/web/src/app/api/community/users/search/route.test.ts
+++ b/src/web/src/app/api/community/users/search/route.test.ts
@@ -1,7 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
import { NextRequest } from "next/server"
import { BUSINESS_SCHEMA_VERSION, COMMUNITY_CONTRACT_HEADER, CommunityReadErrorSchema, CommunityUserSearchReadSchema, DEFAULT_USER_SEARCH_LIMIT, MIN_SEARCH_LENGTH, MAX_SEARCH_LENGTH } from "@alook/shared"
-import type { AuthenticatedHandler } from "@/lib/middleware/auth"
import { createCommunitySqliteDb } from "@/test/community-sqlite-db"
let database: ReturnType<typeof createCommunitySqliteDb>
diff --git a/src/web/src/lib/automation.ts b/src/web/src/lib/automation.ts
index 1046407ea..b4cf55d7c 100644
--- a/src/web/src/lib/automation.ts
+++ b/src/web/src/lib/automation.ts
@@ -34,7 +34,7 @@ function readAutomationSecret(req: NextRequest): string | undefined {
type AutomationExpiryContext = { db: ReturnType<typeof getPrimaryDb>; secretHash: string }
-export const automationExpiryPolicy: AuthPolicy<AutomationExpiryContext> = {
+const automationExpiryPolicy: AuthPolicy<AutomationExpiryContext> = {
params: "ignore",
resolve: async req => {
const secret = readAutomationSecret(req)
diff --git a/src/web/src/lib/community/attention-resources.sql.test.ts b/src/web/src/lib/community/attention-resources.sql.test.ts
index 8ddd2c794..45ca655f9 100644
--- a/src/web/src/lib/community/attention-resources.sql.test.ts
+++ b/src/web/src/lib/community/attention-resources.sql.test.ts
@@ -1,7 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest"
import { NextRequest } from "next/server"
import { queries, BUSINESS_SCHEMA_VERSION, COMMUNITY_CONTRACT_HEADER, AccountAttentionSnapshotSchema } from "@alook/shared"
-import type { AuthenticatedHandler } from "@/lib/middleware/auth"
import { createCommunitySqliteDb } from "@/test/community-sqlite-db"
import { hydrateAttentionResources, readCommunityResourceBundle } from "./attention-resources.server"
diff --git a/src/web/src/lib/middleware/auth.protocol.test.ts b/src/web/src/lib/middleware/auth.protocol.test.ts
index 9238cc69c..eed0af315 100644
--- a/src/web/src/lib/middleware/auth.protocol.test.ts
+++ b/src/web/src/lib/middleware/auth.protocol.test.ts
@@ -4,7 +4,7 @@ import { NextRequest, NextResponse } from "next/server"
import { BUSINESS_SCHEMA_VERSION, COMMUNITY_CONTRACT_HEADER } from "@alook/shared"
import { communityActorPolicy } from "./community-actor"
import { apiFetch } from "@/lib/api/client"
-import { humanAuthPolicy, cookieHumanAuthPolicy, optionalAuthPolicy, type OptionalAuthHandler } from "./auth"
+import { humanAuthPolicy, cookieHumanAuthPolicy, optionalAuthPolicy } from "./auth"
const mocks = vi.hoisted(() => ({ session: vi.fn(), signOut: vi.fn(), user: vi.fn(), machine: vi.fn(), bump: vi.fn(), bot: vi.fn() }))
vi.mock("@opennextjs/cloudflare", () => ({ getCloudflareContext: vi.fn(async () => ({ env: { DB: {} }, ctx: { waitUntil: vi.fn() } })) }))
@@ -37,7 +37,7 @@ const sameOrigin = { Origin: "https://alook.test" }
describe("current auth wrapper producer to API consumer", () => {
it("admits anonymous current invite info through optional auth", async () => {
mocks.session.mockResolvedValue({ headers: new Headers(), response: null })
- const handler = vi.fn(async (_req: NextRequest, ctx: Parameters<OptionalAuthHandler>[1]) => NextResponse.json({ serverId: "server", anonymous: ctx.userId === undefined }))
+ const handler = vi.fn(async (_req: NextRequest, ctx: Exclude<Awaited<ReturnType<typeof optionalAuthPolicy.resolve>>, Response>["context"]) => NextResponse.json({ serverId: "server", anonymous: ctx.userId === undefined }))
const transport = connect(withAuth(optionalAuthPolicy, handler))
expect(await apiFetch("/api/community/invites/token/info")).toEqual({ serverId: "server", anonymous: true })
expect(transport.request.headers.get(COMMUNITY_CONTRACT_HEADER)).toBe(String(BUSINESS_SCHEMA_VERSION))
diff --git a/src/web/src/lib/middleware/auth.ts b/src/web/src/lib/middleware/auth.ts
index 75a6b98f4..dd8084f63 100644
--- a/src/web/src/lib/middleware/auth.ts
+++ b/src/web/src/lib/middleware/auth.ts
@@ -32,7 +32,7 @@ interface CookieHumanAuthContext extends AuthContext {
* anonymous). A distinct interface so `AuthContext.userId` stays required and
* no existing `withAuth` handler is disturbed.
*
- * Not exported: handlers infer this shape from `OptionalAuthHandler`, so no
+ * Not exported: handlers infer this shape from `optionalAuthPolicy`, so no
* caller imports it by name yet. Export it once a handler needs the type
* standalone (as `AuthContext` is, because withAuth handlers import it).
*/
@@ -43,21 +43,6 @@ interface OptionalAuthContext {
user?: { isBot: boolean }
}
-export type AuthenticatedHandler = (
- req: NextRequest,
- ctx: AuthContext & { params?: Record<string, string> }
-) => Promise<NextResponse | Response>
-
-export type OptionalAuthHandler = (
- req: NextRequest,
- ctx: OptionalAuthContext & { params?: Record<string, string> }
-) => Promise<NextResponse | Response>
-
-export type CookieHumanAuthHandler = (
- req: NextRequest,
- ctx: CookieHumanAuthContext & { params?: Record<string, string> },
-) => Promise<NextResponse | Response>
-
/**
* Outcome of resolving a Better-Auth cookie session. Shared by `humanAuthPolicy`
* (which turns everything but `ok` into a 401/503) and `optionalAuthPolicy`
diff --git a/src/web/src/lib/middleware/community-daemon-auth.ts b/src/web/src/lib/middleware/community-daemon-auth.ts
index 3052448e7..50f411571 100644
--- a/src/web/src/lib/middleware/community-daemon-auth.ts
+++ b/src/web/src/lib/middleware/community-daemon-auth.ts
@@ -1,5 +1,5 @@
import type { AuthPolicy } from "./auth-policy"
-import { NextRequest, NextResponse } from "next/server"
+import { NextResponse } from "next/server"
import { getCloudflareContext } from "@opennextjs/cloudflare"
import { queries, withD1Retry } from "@alook/shared"
import { getDb } from "@/lib/db"
@@ -11,11 +11,6 @@ interface CommunityDaemonAuthContext {
credentialId: string
}
-export type CommunityDaemonAuthenticatedHandler = (
- req: NextRequest,
- ctx: CommunityDaemonAuthContext & { params?: Record<string, string> }
-) => Promise<NextResponse | Response>
-
/**
* Community-daemon auth middleware. Requires `Authorization: Bearer cmk_…`;
* validates against `community_machine_credential` (revoked_at IS NULL),
diff --git a/src/web/src/lib/middleware/community-pairing-token.ts b/src/web/src/lib/middleware/community-pairing-token.ts
index 0edd8a930..2272d0000 100644
--- a/src/web/src/lib/middleware/community-pairing-token.ts
+++ b/src/web/src/lib/middleware/community-pairing-token.ts
@@ -1,5 +1,5 @@
import type { AuthPolicy } from "./auth-policy"
-import { NextRequest, NextResponse } from "next/server"
+import { NextResponse } from "next/server"
import { getCloudflareContext } from "@opennextjs/cloudflare"
interface CommunityPairingTokenContext {
@@ -8,11 +8,6 @@ interface CommunityPairingTokenContext {
waitUntil?: (promise: Promise<unknown>) => void
}
-export type CommunityPairingTokenAuthenticatedHandler = (
- req: NextRequest,
- ctx: CommunityPairingTokenContext & { params?: Record<string, string> }
-) => Promise<NextResponse | Response>
-
/**
* Community pairing-token middleware. Requires `Authorization: Bearer cmt_…`;
* parses and validates the `cmt_` prefix but does NOT resolve or consume the
diff --git a/src/web/src/lib/middleware/private-media-cache.test.ts b/src/web/src/lib/middleware/private-media-cache.test.ts
index 6dc8f2a7f..1af4a4cf8 100644
--- a/src/web/src/lib/middleware/private-media-cache.test.ts
+++ b/src/web/src/lib/middleware/private-media-cache.test.ts
@@ -1,3 +1,4 @@
+import type { AuthHandler } from "./auth-policy"
import { withAuth } from "./auth-policy"
import { beforeEach, describe, expect, it, vi } from "vitest"
import { NextRequest, NextResponse } from "next/server"
@@ -17,7 +18,7 @@ vi.mock("@/lib/auth", () => ({
}))
vi.mock("./community-agent-runner-auth", () => ({ resolveBotActor: mocks.resolveBotActor }))
-import { humanAuthPolicy, type AuthenticatedHandler } from "./auth"
+import { humanAuthPolicy, type AuthContext } from "./auth"
import { communityActorPolicy, type CommunityActorHandler } from "./community-actor"
import { withPrivateMediaCache } from "./private-media-cache"
@@ -95,7 +96,7 @@ describe("selected private media response policy", () => {
describe("real authentication wrappers inside media policy", () => {
it.each([200, 304])("keeps fixed media status %s independent of GA, session refresh and authenticated viewer cookies", async (status) => {
- const handler = vi.fn<AuthenticatedHandler>(async () => media(status, { Vary: "Accept-Encoding" }))
+ const handler = vi.fn<AuthHandler<AuthContext>>(async () => media(status, { Vary: "Accept-Encoding" }))
const route = withPrivateMediaCache(withAuth(humanAuthPolicy, handler))
const params = { params: Promise.resolve({ id: "fixed" }) }
for (const [viewer, ga, sessionData] of [["A", "first", "old"], ["A", "second", "renewed"], ["B", "third", "other"]]) {
@@ -116,7 +117,7 @@ describe("real authentication wrappers inside media policy", () => {
if (kind === "error") mocks.getSession.mockRejectedValue(new Error("session infrastructure"))
if (kind === "bot") mocks.getSession.mockResolvedValue(session("bot1", { isBot: true }))
if (kind === "deleted") mocks.getSession.mockResolvedValue(session("A", { deletedAt: "2026-10-01" }))
- const handler = vi.fn<AuthenticatedHandler>(async () => media())
+ const handler = vi.fn<AuthHandler<AuthContext>>(async () => media())
const result = await withPrivateMediaCache(withAuth(humanAuthPolicy, handler))(request())
expect(result.status).toBe(kind === "error" ? 503 : 401)
expect(result.headers.get("Cache-Control")).toBe("private, no-store")
@@ -128,7 +129,7 @@ describe("real authentication wrappers inside media policy", () => {
})
it("makes retired token rejection non-storable even with a live Cookie", async () => {
- const handler = vi.fn<AuthenticatedHandler>(async () => media())
+ const handler = vi.fn<AuthHandler<AuthContext>>(async () => media())
const result = await withPrivateMediaCache(withAuth(humanAuthPolicy, handler))(request({ Authorization: "Bearer al_retired", Cookie: "better-auth.session_token=live" }))
expect(result.status).toBe(401)
expect(result.headers.get("Cache-Control")).toBe("private, no-store")