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

Merged
Merged
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 @@ -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;
jjarvisp marked this conversation as resolved.
Show resolved Hide resolved

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