From 941458dceb321c18e0fb0dfe6249b66bca61ff9e Mon Sep 17 00:00:00 2001 From: "vladyslav.zhytnyk" Date: Mon, 11 Nov 2024 15:15:08 +0200 Subject: [PATCH] FR-17280 - fix next js 15 build & update example app project middleware --- packages/example-app-directory/middleware.ts | 18 ++++++------------ packages/nextjs/src/app/FronteggAppRouter.tsx | 8 ++++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/example-app-directory/middleware.ts b/packages/example-app-directory/middleware.ts index 9a839388..f2b124f6 100644 --- a/packages/example-app-directory/middleware.ts +++ b/packages/example-app-directory/middleware.ts @@ -1,6 +1,5 @@ -import { NextResponse } from 'next/server'; -import type { NextRequest } from 'next/server'; -import { getSessionOnEdge, shouldByPassMiddleware, redirectToLogin } from '@frontegg/nextjs/edge'; +import { NextRequest, NextResponse } from 'next/server'; +import { handleSessionOnEdge } from '@frontegg/nextjs/edge'; export const middleware = async (request: NextRequest) => { // this if for frontegg middleware tests @@ -8,17 +7,12 @@ export const middleware = async (request: NextRequest) => { return NextResponse.next(); } - const { pathname, searchParams, origin } = request.nextUrl; + const { pathname, searchParams } = request.nextUrl; + const headers = request.headers; - if (shouldByPassMiddleware(pathname /*, options: optional bypass configuration */)) { - return NextResponse.next(); - } + // Additional logic if needed - const session = await getSessionOnEdge(request); - if (!session) { - return redirectToLogin(pathname, searchParams, origin); - } - return NextResponse.next(); + return handleSessionOnEdge({ request, pathname, searchParams, headers }); }; export const config = { diff --git a/packages/nextjs/src/app/FronteggAppRouter.tsx b/packages/nextjs/src/app/FronteggAppRouter.tsx index cd812a16..9280b80a 100644 --- a/packages/nextjs/src/app/FronteggAppRouter.tsx +++ b/packages/nextjs/src/app/FronteggAppRouter.tsx @@ -4,7 +4,7 @@ import { isAuthRoute } from '../utils/routing'; import { FronteggRouterBase } from '../common/FronteggRouterBase'; import React from 'react'; -interface FronteggRouterProps { +interface FronteggRouterSyncProps { params: ParsedUrlQuery & { 'frontegg-router'?: string[] }; searchParams?: ParsedUrlQuery; } @@ -14,7 +14,11 @@ interface FronteggRouterAsyncProps { searchParams: Promise; } -export function FronteggAppRouter(props: FronteggRouterProps) { +type FronteggRouterProps = FronteggRouterSyncProps | FronteggRouterAsyncProps; + +export function FronteggAppRouter(routerProps: T) { + const props = routerProps as FronteggRouterProps; + const renderAppRouter = (searchParams: ParsedUrlQuery | undefined, pathArr: string[]) => { let pathname = `/${pathArr.join('/')}`; if (!pathname || pathname.startsWith('/_next/data')) {