mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
⚡️ Improve middleware performance
This commit also aims to fix a bug when the password cookie is undefined
This commit is contained in:
@@ -3,9 +3,13 @@ import { NextFetchEvent, NextRequest, NextResponse } from 'next/server';
|
||||
// eslint-disable-next-line consistent-return
|
||||
export function middleware(req: NextRequest, ev: NextFetchEvent) {
|
||||
const { cookies } = req;
|
||||
const passwordCookie = cookies.get('password')?.value;
|
||||
const isCorrectPassword = passwordCookie?.toString() === process.env.PASSWORD;
|
||||
// Don't even bother with the middleware if there is no defined password
|
||||
if (!process.env.PASSWORD) return NextResponse.next();
|
||||
|
||||
const url = req.nextUrl.clone();
|
||||
const passwordCookie = cookies.get('password')?.value;
|
||||
|
||||
const isCorrectPassword = passwordCookie?.toString() === process.env.PASSWORD;
|
||||
// Skip the middleware if the URL is 'login', 'api/configs/tryPassword', '_next/*', 'favicon.ico', '404', 'migrate' or 'pages/_app'
|
||||
const skippedUrls = [
|
||||
'/login',
|
||||
|
||||
Reference in New Issue
Block a user