Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(adapter-nextjs): make createAuthRouteHandlers interface work in both App and Pages routers #13840

Open
wants to merge 1 commit into
base: hui/feat/adapter-nextjs/4-check-signed-in-user
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

@jjarvisp jjarvisp Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. A better solution than splitting handlers by router type and there is not much lost utility from not having this fully typed externally.


export interface CreateAuthRouteHandlersFactoryInput {
config: ResourcesConfig;
runtimeOptions: NextServer.CreateServerRunnerRuntimeOptions | undefined;
Expand Down
Loading