23 lines
559 B
TypeScript
23 lines
559 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { auth } from "./auth";
|
|
|
|
export default auth((req) => {
|
|
const { nextUrl } = req;
|
|
const isLoggedIn = !!req.auth;
|
|
const isLoginPage = nextUrl.pathname === "/login";
|
|
|
|
if (!isLoggedIn && !isLoginPage) {
|
|
return NextResponse.redirect(new URL("/login", req.url));
|
|
}
|
|
|
|
if (isLoggedIn && isLoginPage) {
|
|
return NextResponse.redirect(new URL("/dashboard", req.url));
|
|
}
|
|
|
|
return NextResponse.next();
|
|
});
|
|
|
|
export const config = {
|
|
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
|
|
};
|