Friday, 9 June 2023

getServerSideProps props are undefined on client-side when using middleware

I'm trying to do a redirect on every page if a certain condition is true using Nextjs middleware.

For some reason, whenever the matcher in middleware.ts matches a page, all props from getServerSideProps on that page are undefined when they reach the client side. When I remove pages from the matcher regex, they work as expected with the correct values.

Middleware.ts

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

export default async function middleware(req: NextRequest) {
  return NextResponse.next();
}

export const config = {
  matcher: ['/(tag|about)(.)*'],
};

How can I make sure getServerSideProps still fires on pages that also trigger the middleware function?

(getServerSideProps is firing, and I see the correct values in the terminal, but I'm still getting undefined on the client-side specifically)

enter image description here



from getServerSideProps props are undefined on client-side when using middleware

No comments:

Post a Comment