Repository navigation
Description
[REQUIRED] Environment info
firebase-tools:
12.4.0
Platform:
Manjaro
NextJS 13 (typescript)
I am also using next-firebase-auth-edge for authentication with Firebase and NextJS 13: https://github.com/awinogrodzki/next-firebase-auth-edge
[REQUIRED] Test case
This is the middleware:
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { authentication } from "next-firebase-auth-edge/lib/next/middleware";
import { serverConfig, tokenConfig } from "./config/server-config";
const commonOptions = {
...tokenConfig,
cookieSerializeOptions: {
path: "/",
httpOnly: true,
secure: serverConfig.useSecureCookies, // Set this to true on HTTPS environments
sameSite: "lax" as const,
maxAge: 12 * 60 * 60 * 24 * 1000, // twelve days
},
};
export async function middleware(request: NextRequest) {
return authentication(request, {
loginPath: "/api/login",
logoutPath: "/api/logout",
...commonOptions,
handleValidToken: async ({}) => {
if (request.nextUrl.pathname === "/api/custom-claims") {
const response = new NextResponse("", {
status: 200,
headers: { "content-type": "application/json" },
});
return response;
}
return NextResponse.next();
},
handleError: async (error) => {
// Avoid redirect loop
if (request.nextUrl.pathname === "/login") {
return NextResponse.next();
}
const url = request.nextUrl.clone();
url.pathname = "/login";
url.search = `redirect=${request.nextUrl.pathname}${url.search}`;
return NextResponse.redirect(url);
},
});
}
export const config = {
matcher: ["/", "/((?!_next/static|favicon.ico|logo.svg).*)"],
};
[REQUIRED] Steps to reproduce
Follow the steps below, clone this public repo: https://github.com/pinkpigeonltd/minimal_example
Then:
npm install
firebase init (choosing only to setup hosting, nothing else needed)
firebase deploy (to a project of your choice)
You will see there is an error 500. The cloud console logs just seem to show "exited with status 1" which doesn't include much more info.
Remove middleware.ts and deploy again. The app shows up fine!
[REQUIRED] Expected behavior
For the app to work after deploying (or for the deployment process to see an error and alert the user that there's a problem)
[REQUIRED] Actual behavior
App returns error 500 with middleware.ts present
Activity
alexastrum commentedon Jun 24, 2023
Fixed in https://www.npmjs.com/package/firebase-frameworks/v/0.10.4
JSON-FS commentedon Jul 12, 2023
Hi, I am still encountering this issue. My firebase-tools version is
12.4.3. Same information as the OP - withmiddleware.ts, the app returns http500, if I delete themiddleware.tsthen there are no problems. I guess the only difference with OP is that my app is freshly installed usingnpx create-next-app@latestjust a day agoAlso, just to add more information, my
middleware.tsbarely contains any code. It was just for testing