-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
39 lines (35 loc) · 1 KB
/
middleware.js
File metadata and controls
39 lines (35 loc) · 1 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
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
// Routes that require authentication
const isProtectedRoute = createRouteMatcher([
'/dashboard(.*)',
'/onboarding(.*)',
'/profile(.*)',
'/clubs(.*)',
'/api/users(.*)',
'/api/sport-profiles(.*)',
'/api/stats(.*)',
'/api/goals(.*)',
'/api/clubs(.*)',
'/api/tournaments(.*)',
'/api/matches(.*)',
]);
// Routes that are always public (no auth required)
const isPublicRoute = createRouteMatcher([
'/',
'/sign-in(.*)',
'/sign-up(.*)',
'/api/webhooks(.*)',
]);
export default clerkMiddleware(async (auth, req) => {
// If the route is protected and user is not signed in, redirect to sign-in
if (isProtectedRoute(req)) {
await auth.protect();
}
});
export const config = {
// Next.js middleware matcher — run on all routes except static files
matcher: [
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
'/(api|trpc)(.*)',
],
};