diff --git a/packages/adapter-nextjs/src/auth/createAuthRouteHandlersFactory.ts b/packages/adapter-nextjs/src/auth/createAuthRouteHandlersFactory.ts index 6e3b4389d7b..4dea18ae700 100644 --- a/packages/adapter-nextjs/src/auth/createAuthRouteHandlersFactory.ts +++ b/packages/adapter-nextjs/src/auth/createAuthRouteHandlersFactory.ts @@ -11,9 +11,9 @@ import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-c import { AuthRoutesHandlerContext, - CreateAuthRouteHandlers, CreateAuthRouteHandlersFactoryInput, CreateAuthRoutesHandlersInput, + InternalCreateAuthRouteHandlers, } from './types'; import { isAuthRoutesHandlersContext, @@ -28,7 +28,7 @@ export const createAuthRouteHandlersFactory = ({ config: resourcesConfig, runtimeOptions = {}, runWithAmplifyServerContext, -}: CreateAuthRouteHandlersFactoryInput): CreateAuthRouteHandlers => { +}: CreateAuthRouteHandlersFactoryInput): InternalCreateAuthRouteHandlers => { const origin = process.env.AMPLIFY_APP_ORIGIN; if (!origin) throw new AmplifyServerContextError({ diff --git a/packages/adapter-nextjs/src/auth/types.ts b/packages/adapter-nextjs/src/auth/types.ts index 199e4eeb8f7..d8075fea708 100644 --- a/packages/adapter-nextjs/src/auth/types.ts +++ b/packages/adapter-nextjs/src/auth/types.ts @@ -66,10 +66,20 @@ export interface CreateAuthRoutesHandlersInput { redirectOnSignOutComplete?: string; } -export type CreateAuthRouteHandlers = ( +export type InternalCreateAuthRouteHandlers = ( input?: CreateAuthRoutesHandlersInput, ) => AuthRouteHandlers; +export type CreateAuthRouteHandlers = ( + input?: CreateAuthRoutesHandlersInput, +) => + | AuthRouteHandlers + // Forcing the handler interface to be any to ensure the single handler can + // work in both App Router `routes.ts` and Pages router. The former has a + // restrict handler function interface type check. The parameters types are + // properly typed internally, and runtime validation is place. + | any; + export interface CreateAuthRouteHandlersFactoryInput { config: ResourcesConfig; runtimeOptions: NextServer.CreateServerRunnerRuntimeOptions | undefined;