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 Jan 2, 2025
1 parent 3ec76df commit 834215f
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 @@ -29,7 +29,7 @@ export const createAuthRouteHandlersFactory = ({
runtimeOptions = {},
amplifyAppOrigin,
runWithAmplifyServerContext,
}: CreateAuthRouteHandlersFactoryInput): CreateAuthRouteHandlers => {
}: CreateAuthRouteHandlersFactoryInput): InternalCreateAuthRouteHandlers => {
if (!amplifyAppOrigin)
throw new AmplifyServerContextError({
message: 'Could not find the AMPLIFY_APP_ORIGIN environment variable.',
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 834215f

Please sign in to comment.