-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
67 lines (59 loc) · 2.19 KB
/
Copy pathmiddleware.ts
File metadata and controls
67 lines (59 loc) · 2.19 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { withAuth } from "next-auth/middleware"
import { NextResponse } from "next/server"
export default withAuth(
async function middleware(req) {
// Allow access to auth routes, API routes, and home page
if (req.nextUrl.pathname.startsWith('/auth') ||
req.nextUrl.pathname.startsWith('/api') ||
req.nextUrl.pathname === '/' ||
req.nextUrl.pathname.startsWith('/events')) {
return NextResponse.next()
}
// For authenticated users, we'll rely on client-side validation
// since Prisma doesn't work on Edge Runtime in middleware
// Allow access to profile completion routes
if (req.nextUrl.pathname.startsWith('/member/complete-profile') ||
req.nextUrl.pathname.startsWith('/partner/complete-profile')) {
return NextResponse.next()
}
// Allow access to dashboard routes - client-side validation will handle redirects
if (req.nextUrl.pathname === '/dashboard' ||
req.nextUrl.pathname.startsWith('/partner/dashboard')) {
return NextResponse.next()
}
// For other protected routes, continue
return NextResponse.next()
},
{
callbacks: {
authorized: ({ token, req }) => {
// Allow unauthenticated access to public pages
if (req.nextUrl.pathname === '/' ||
req.nextUrl.pathname.startsWith('/auth') ||
req.nextUrl.pathname.startsWith('/events') ||
req.nextUrl.pathname.startsWith('/api/auth')) {
return true
}
// Allow access to profile completion pages for authenticated users
if ((req.nextUrl.pathname.startsWith('/member/complete-profile') ||
req.nextUrl.pathname.startsWith('/partner/complete-profile')) && token) {
return true
}
// Require authentication for protected routes
return !!token
},
},
}
)
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
*/
'/((?!_next/static|_next/image|favicon.ico|public|.*\\.).*)',
],
}