Improve dashboard prefetching and analytics charts
All checks were successful
Build Frontend / build (push) Successful in 1m14s
All checks were successful
Build Frontend / build (push) Successful in 1m14s
Removed dashboard prefetching from the login page to avoid unnecessary middleware redirects for unauthenticated users. Added delayed prefetching of dashboard routes after initial load for better navigation performance. Updated AdminAnalytics to use AreaChart instead of BarChart for daily metrics, improving visual clarity. Enhanced middleware to allow prefetch requests through without redirecting to login, supporting better caching and navigation.
This commit is contained in:
@@ -4,12 +4,19 @@ import type { NextRequest } from 'next/server';
|
||||
export function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
// Protect dashboard routes
|
||||
if (pathname.startsWith('/dashboard')) {
|
||||
const authToken = request.cookies.get('Authorization')?.value;
|
||||
|
||||
const isPrefetch =
|
||||
request.headers.get('Next-Router-Prefetch') === '1' ||
|
||||
request.headers.get('purpose') === 'prefetch';
|
||||
|
||||
if (!authToken) {
|
||||
// Redirect to login if no token is found
|
||||
if (isPrefetch) {
|
||||
// Let prefetch requests through so caching works
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
const loginUrl = new URL('/auth/login', request.url);
|
||||
loginUrl.searchParams.set('redirectUrl', pathname);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
@@ -19,7 +26,6 @@ export function middleware(request: NextRequest) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
// See "Matching Paths" below to learn more
|
||||
export const config = {
|
||||
matcher: ['/dashboard/:path*'],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user