diff --git a/src/auth/server.ts b/src/auth/server.ts index a33c593..4d7556f 100644 --- a/src/auth/server.ts +++ b/src/auth/server.ts @@ -6,13 +6,31 @@ import type { CreateAuthOptions, SessionUser } from "./types"; export type { SessionUser, CreateAuthOptions }; +/** + * Shape of the GET/POST route handlers NextAuth returns. Declared + * structurally (Request → Response) rather than via + * `NextAuthResult["handlers"]` — that type embeds `NextRequest` from + * the kit's own copy of `next`, which conflicts with the consumer's + * `next` and produces a spurious `RouteHandlerConfig` mismatch in + * `.next/types/validator.ts` for every app's `[...nextauth]/route.ts`. + * + * Web-standard `Request`/`Response` are valid for Next.js route + * handlers (NextRequest extends Request), and TS function-parameter + * contravariance makes this assignable wherever the validator wants + * `(request: NextRequest, ctx) => ...`. + */ +export type AuthRouteHandlers = { + GET: (request: Request) => Promise; + POST: (request: Request) => Promise; +}; + /** * Result of `createAuth()`. Mirrors NextAuth's return value plus * `requireAuth` and the resolved `signInPath` so consumers don't have to * thread these around. */ export interface AuthBundle { - handlers: NextAuthResult["handlers"]; + handlers: AuthRouteHandlers; signIn: NextAuthResult["signIn"]; signOut: NextAuthResult["signOut"]; auth: NextAuthResult["auth"]; @@ -114,7 +132,12 @@ export function createAuth(opts: CreateAuthOptions): AuthBundle { } return { - handlers: na.handlers, + // Cast through unknown: NextAuth's handler param type references its + // own NextRequest; the AuthRouteHandlers shape is structurally + // compatible (NextRequest extends Request), but TS can't prove the + // function-parameter contravariance across the two `next` copies on + // its own. + handlers: na.handlers as unknown as AuthRouteHandlers, signIn: na.signIn, signOut: na.signOut, auth: na.auth,