Skip to content

Commit

Permalink
fix(adapter-nextjs): make createAuthRouteHandlers interface work in b…
Browse files Browse the repository at this point in the history
…oth App and Pages routers
  • Loading branch information
HuiSF committed Nov 21, 2024
1 parent 1cd0bd6 commit ccca0a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-c

import {
AuthRoutesHandlerContext,
CreateAuthRouteHandlers,
CreateAuthRouteHandlersFactoryInput,
CreateAuthRoutesHandlersInput,
InternalCreateAuthRouteHandlers,
} from './types';
import {
isAuthRoutesHandlersContext,
Expand All @@ -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({
Expand Down
12 changes: 11 additions & 1 deletion packages/adapter-nextjs/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ccca0a9

Please sign in to comment.