mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +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
|
// eslint-disable-next-line consistent-return
|
||||||
export function middleware(req: NextRequest, ev: NextFetchEvent) {
|
export function middleware(req: NextRequest, ev: NextFetchEvent) {
|
||||||
const { cookies } = req;
|
const { cookies } = req;
|
||||||
const passwordCookie = cookies.get('password')?.value;
|
// Don't even bother with the middleware if there is no defined password
|
||||||
const isCorrectPassword = passwordCookie?.toString() === process.env.PASSWORD;
|
if (!process.env.PASSWORD) return NextResponse.next();
|
||||||
|
|
||||||
const url = req.nextUrl.clone();
|
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'
|
// Skip the middleware if the URL is 'login', 'api/configs/tryPassword', '_next/*', 'favicon.ico', '404', 'migrate' or 'pages/_app'
|
||||||
const skippedUrls = [
|
const skippedUrls = [
|
||||||
'/login',
|
'/login',
|
||||||
|
|||||||
Reference in New Issue
Block a user