-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
32 lines (27 loc) · 868 Bytes
/
middleware.ts
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
import { NextResponse } from "next/server";
import { auth } from "@/server/auth/auth";
import { authRoutes, DEFAULT_LOGIN_REDIRECT } from "@/utils/apiRoutes";
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const isAuthRoute = authRoutes.includes(nextUrl.pathname);
// Redirect authenticated users to `/DEFAULT_LOGIN_REDIRECT`
if (isAuthRoute && isLoggedIn) {
return NextResponse.redirect(new URL(DEFAULT_LOGIN_REDIRECT, nextUrl));
}
return NextResponse.next();
});
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - public folder
*/
"/((?!.+\\.[\\w]+$|_next).*)",
"/",
"/api/mobile/:path*",
],
};