24 lines
580 B
TypeScript
24 lines
580 B
TypeScript
import { auth } from "@/auth";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export default auth((req) => {
|
|
const isAuthenticated = !!req.auth;
|
|
const { pathname } = req.nextUrl;
|
|
|
|
if (!isAuthenticated && pathname !== "/login") {
|
|
return NextResponse.redirect(new URL("/login", req.url));
|
|
}
|
|
|
|
if (isAuthenticated && pathname === "/login") {
|
|
return NextResponse.redirect(new URL("/", req.url));
|
|
}
|
|
|
|
return NextResponse.next();
|
|
});
|
|
|
|
export const config = {
|
|
matcher: [
|
|
"/((?!api/auth|_next/static|_next/image|favicon.ico|icon.svg|logo.svg|public/).*)",
|
|
],
|
|
};
|