-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
25 lines (20 loc) · 738 Bytes
/
Copy pathproxy.ts
File metadata and controls
25 lines (20 loc) · 738 Bytes
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
import { auth } from "@/lib/auth-edge";
import { NextResponse } from "next/server";
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const isLoginPage = nextUrl.pathname === "/login";
const isAppRoute = nextUrl.pathname.startsWith("/app");
// If user is logged in and trying to access /login, redirect to /app
if (isLoggedIn && isLoginPage) {
return NextResponse.redirect(new URL("/app", nextUrl));
}
// If user is not logged in and trying to access /app, redirect to /login
if (!isLoggedIn && isAppRoute) {
return NextResponse.redirect(new URL("/login", nextUrl));
}
return NextResponse.next();
});
export const config = {
matcher: ["/app/:path*", "/login"],
};