-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmiddleware.ts
41 lines (35 loc) · 1.11 KB
/
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
33
34
35
36
37
38
39
40
41
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
import { auth } from "@/auth"
export async function middleware(request: NextRequest) {
const session = await auth()
if (!session && (
request.nextUrl.pathname.startsWith('/dashboard') ||
request.nextUrl.pathname.startsWith('/business') ||
request.nextUrl.pathname.startsWith('/customers') ||
request.nextUrl.pathname.startsWith('/chat') ||
request.nextUrl.pathname.startsWith('/email-campaign') ||
request.nextUrl.pathname.startsWith('/leads')
)) {
return NextResponse.redirect(new URL('/', request.url))
}
if (session && request.nextUrl.pathname === '/signin') {
return NextResponse.redirect(new URL('/dashboard', request.url))
}
if (session && request.nextUrl.pathname === '/') {
return NextResponse.redirect(new URL('/dashboard', request.url))
}
return NextResponse.next()
}
export const config = {
matcher: [
"/dashboard/:path*",
"/business/:path*",
"/customers/:path*",
"/chat/:path*",
"/email-campaign/:path*",
"/leads/:path*",
"/signin",
"/"
]
}