feat: Enhance login page UI with delayed redirect instead of transparent 307
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 8s
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 8s
This commit is contained in:
@@ -1,12 +1,31 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import {
|
||||
adminUnauthorizedResponse,
|
||||
attachAdminHeaders,
|
||||
isAdminRequestAuthorized,
|
||||
} from "@/lib/admin-auth";
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const url = request.nextUrl;
|
||||
|
||||
const isAdminPath = url.pathname.startsWith("/admin");
|
||||
|
||||
if (isAdminPath) {
|
||||
if (!isAdminRequestAuthorized(request)) {
|
||||
return adminUnauthorizedResponse();
|
||||
}
|
||||
|
||||
const headers = attachAdminHeaders(request);
|
||||
return NextResponse.next({
|
||||
request: {
|
||||
headers,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Check if there is a referral parameter ?ref=
|
||||
const ref = url.searchParams.get('ref');
|
||||
|
||||
|
||||
if (ref) {
|
||||
const response = NextResponse.redirect(url.pathname);
|
||||
// Set cookie for 30 days
|
||||
@@ -25,13 +44,6 @@ export function middleware(request: NextRequest) {
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
/*
|
||||
* Match all request paths except for the ones starting with:
|
||||
* - api (API routes)
|
||||
* - _next/static (static files)
|
||||
* - _next/image (image optimization files)
|
||||
* - favicon.ico (favicon file)
|
||||
*/
|
||||
'/((?!api|_next/static|_next/image|favicon.ico).*)',
|
||||
'/((?!_next/static|_next/image|favicon.ico).*)',
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user