-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
57 lines (47 loc) · 1.94 KB
/
Copy pathmiddleware.ts
File metadata and controls
57 lines (47 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
// // Get token from session storage via headers or cookies
// const token =
// request.cookies.get("auth-token")?.value ||
// request.headers.get("authorization")?.replace("Bearer ", "") ||
// null;
// // Define public routes accessible without authentication
// const publicRoutes = ["/auth/login", "/auth/signup", "/"];
// const isPublicRoute = publicRoutes.includes(pathname);
// // Define protected routes (require authentication)
// const protectedRoutes = ["/dashboard"];
// const isProtectedRoute = protectedRoutes.some((route) =>
// pathname.startsWith(route)
// );
// // If user is not authenticated and trying to access protected route
// if (!token && isProtectedRoute) {
// return NextResponse.redirect(new URL("/auth/login", request.url));
// }
// // If user is authenticated and trying to access auth pages (login/auth/signup)
// if (token && (pathname === "/auth/login" || pathname === "/auth/signup")) {
// return NextResponse.redirect(new URL("/dashboard", request.url));
// }
// // If user is authenticated and on home page, redirect to dashboard
// if (token && pathname === "/") {
// return NextResponse.redirect(new URL("/dashboard", request.url));
// }
// // If user is not authenticated and on home page, redirect to login
// if (!token && pathname === "/") {
// return NextResponse.redirect(new URL("/auth/login", request.url));
// }
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)
*/
"/((?!api|_next/static|_next/image|favicon.ico).*)",
],
};