-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmiddleware.ts
44 lines (40 loc) · 1.03 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
42
43
44
import { NextRequest, NextResponse } from "next/server"
import { auth } from "./app/auth"
export default async function middleware(request: NextRequest) {
const nextUrl = request.nextUrl
const pathname = nextUrl.pathname
const session = await auth()
if (
pathname.startsWith("/chart") ||
pathname.startsWith("/exchange-diary") ||
pathname.startsWith("/mydiary") ||
pathname.startsWith("/mypage") ||
pathname.startsWith("/welcome")
) {
if (!session?.user) {
return NextResponse.redirect(`${nextUrl.origin}/`)
}
} else if (
pathname === "/" ||
pathname.startsWith("/login") ||
pathname.startsWith("/signup") ||
pathname.startsWith("/onboarding")
) {
if (session?.user) {
return NextResponse.redirect(`${nextUrl.origin}/mydiary`)
}
}
}
export const config = {
matcher: [
"/chart/:path*",
"/exchange-diary/:path*",
"/mydiary/:path*",
"/mypage/:path*",
"/welcome/:path*",
"/login/:path*",
"/signup/:path*",
"/onboarding/:path*",
"/",
],
}