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): not await params async API in Next.js 15 #14125

Merged
merged 1 commit into from
Jan 9, 2025
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 @@ -13,8 +13,9 @@ import {
describe('isAuthRoutesHandlersContext', () => {
test.each([
[{}, false],
[{ params: {} }, false],
[{ params: {} }, true],
[{ params: { slug: 'sign-in' } }, true],
[{ params: Promise.resolve({ slug: 'sign-in' }) }, true],
] as [object, boolean][])(
'when call with %o it returns %s',
(input, expectedResult) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const handleAuthApiRouteRequestForAppRouter: HandleAuthApiRouteRequestFor
return new Response(null, { status: 405 });
}

const { slug } = handlerContext.params;
const { slug } = await handlerContext.params;
// don't support [...slug] here
if (slug === undefined || Array.isArray(slug)) {
return new Response(null, { status: 400 });
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-nextjs/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export interface AuthRouteHandlerParams {
}

export interface AuthRoutesHandlerContext {
params: AuthRouteHandlerParams;
// In Next.js 15 params is an async API, so it can be a promise.
params: AuthRouteHandlerParams | Promise<AuthRouteHandlerParams>;
}

/**
Expand Down
11 changes: 2 additions & 9 deletions packages/adapter-nextjs/src/auth/utils/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { NextRequest } from 'next/server';
import { NextApiRequest, NextApiResponse } from 'next';

import { AuthRouteHandlerParams, AuthRoutesHandlerContext } from '../types';
import { AuthRoutesHandlerContext } from '../types';

// NextRequest is the 1st parameter type for the API route handlers in the App Router
export function isNextRequest(request: object): request is NextRequest {
Expand All @@ -20,17 +20,10 @@ export function isAuthRoutesHandlersContext(
return (
'params' in context &&
context.params !== undefined &&
context.params !== null &&
isAuthRouteHandlerParams(context.params)
context.params !== null
);
}

function isAuthRouteHandlerParams(
params: object,
): params is AuthRouteHandlerParams {
return 'slug' in params && typeof params.slug === 'string';
}

// NextApiRequest is the 1st parameter type for the API route handlers in the Pages Router
export function isNextApiRequest(request: object): request is NextApiRequest {
// Can't use `IncomingMessage` to validate the request is an instance of `NextApiRequest`
Expand Down
Loading