-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmiddleware.ts
53 lines (49 loc) · 1.64 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
45
46
47
48
49
50
51
52
53
import { authMiddleware } from '@clerk/nextjs';
import { NextApiRequest, NextApiResponse } from 'next';
// Define a custom type for the afterAuth handler
type AfterAuthHandler = (options: {
req: NextApiRequest,
res: NextApiResponse,
user: any
}) => Promise<NextApiResponse>;
// Define the custom afterAuth function
const customAfterAuth: AfterAuthHandler = async ({ req, res, user }) => {
// Check if the user is authenticated
if (!user) {
// If not authenticated, modify the response object to remove the X-User-Authenticated header
res.setHeader('X-User-Authenticated', '');
}
// Return the modified response object
return res;
};
// Apply authMiddleware with custom afterAuth function
export default authMiddleware({
// Define public routes accessible to both signed-in and signed-out users
publicRoutes: [
'/',
'/events/:id',
'/api/webhook/clerk',
'/api/webhook/stripe',
'/api/webhook/uploadthing',
'/favicon.ico',
'/assets/images/logo1.svg',
'/assets/gif/event.gif'
],
// Define routes to be ignored by Clerk authentication
ignoredRoutes: [
'/api/webhook/clerk',
'/api/webhook/stripe',
'/api/uploadthing',
'/favicon.ico',
'/assets/images/logo1.svg',
'/assets/gif/event.gif'
],
});
// Define the configuration for routes matching patterns
export const config = {
matcher: [
"/((?!.+.[w]+$|_next).*)", // Exclude files with specific extensions
"/", // Root route
"/(api|trpc)(.*)" // API routes
],
};