-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
22 lines (19 loc) · 941 Bytes
/
middleware.ts
File metadata and controls
22 lines (19 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { auth } from "@/auth";
export default auth((req) => {
// Check if the user is not authenticated and is trying to access a protected page
// Then redirect them to the login page
if (!req.auth && req.nextUrl.pathname !== "/login" && req.nextUrl.pathname !== "/register" && req.nextUrl.pathname !== "/") {
const newUrl = new URL("/login", req.nextUrl.origin);
return Response.redirect(newUrl);
}
// Check if the user is authenticated and is trying to access a login or register page
// Then redirect them to the home page
if (req.auth && (req.nextUrl.pathname === "/login" || req.nextUrl.pathname === "/register")) {
const newUrl = new URL("/", req.nextUrl.origin);
return Response.redirect(newUrl);
}
});
export const config = {
// matcher: ["/((?!api|widgets.css|widgets.js|_next/static|_next/image|favicon.ico).*)"],
matcher: ['/login', '/register', '/dashboard', '/integrations', '/widgets'],
};