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

FR-17280 - fix next js 15 build & update example app project middleware #387

Merged
merged 1 commit into from
Nov 11, 2024
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
18 changes: 6 additions & 12 deletions packages/example-app-directory/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
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
if (process.env['FRONTEGG_TEST_URL']) {
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 = {
Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/src/app/FronteggAppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -14,7 +14,11 @@ interface FronteggRouterAsyncProps {
searchParams: Promise<ParsedUrlQuery>;
}

export function FronteggAppRouter(props: FronteggRouterProps) {
type FronteggRouterProps = FronteggRouterSyncProps | FronteggRouterAsyncProps;

export function FronteggAppRouter<T>(routerProps: T) {
const props = routerProps as FronteggRouterProps;

const renderAppRouter = (searchParams: ParsedUrlQuery | undefined, pathArr: string[]) => {
let pathname = `/${pathArr.join('/')}`;
if (!pathname || pathname.startsWith('/_next/data')) {
Expand Down
Loading