refactor: remove ProfileForm and update loading state display
- Removed the ProfileForm component from HomePage, simplifying the UI during loading. - Added a loading spinner and message to indicate redirection to the login page, enhancing user experience.
This commit is contained in:
54
middleware.ts
Normal file
54
middleware.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const COOKIE_NAME = "peakSkills_userId";
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
// Pages qui ne nécessitent pas d'authentification
|
||||
const publicPaths = ["/login"];
|
||||
|
||||
// Pages API qui ne nécessitent pas d'authentification
|
||||
const publicApiPaths = ["/api/auth", "/api/teams"];
|
||||
|
||||
// Vérifier si c'est une route publique
|
||||
if (
|
||||
publicPaths.includes(pathname) ||
|
||||
publicApiPaths.some((path) => pathname.startsWith(path))
|
||||
) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
// Vérifier si c'est un fichier statique
|
||||
if (
|
||||
pathname.includes("/_next/") ||
|
||||
pathname.includes("/favicon.ico") ||
|
||||
pathname.includes("/public/")
|
||||
) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
// Vérifier le cookie d'authentification
|
||||
const userId = request.cookies.get(COOKIE_NAME)?.value;
|
||||
|
||||
if (!userId) {
|
||||
// Rediriger vers la page de login si pas authentifié
|
||||
const loginUrl = new URL("/login", request.url);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
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)
|
||||
*/
|
||||
"/((?!_next/static|_next/image|favicon.ico).*)",
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user