tasko/middleware.ts

36 lines
903 B
TypeScript
Raw Normal View History

2024-03-21 21:15:27 +00:00
/**
* New Middleware
*/
import { clerkMiddleware } from '@clerk/nextjs/server';
export default clerkMiddleware();
export const config = {
matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};
/**
* Old Middleware
*/
/* import { authMiddleware, redirectToSignIn } from '@clerk/nextjs';
2024-02-16 01:49:19 +00:00
import { NextResponse } from 'next/server';
2024-02-15 02:30:10 +00:00
export default authMiddleware({
publicRoutes: ['/', '/api/webhook', '/privacy-policy', '/terms-of-service'],
2024-02-15 02:30:10 +00:00
afterAuth(auth, req) {
if (!auth.userId && !auth.isPublicRoute) {
return redirectToSignIn({ returnBackUrl: req.url });
}
2024-02-16 01:49:19 +00:00
if (auth.userId && !auth.orgId && req.nextUrl.pathname !== '/select-org') {
const orgSelection = new URL('/select-org', req.url);
2024-02-15 02:30:10 +00:00
return NextResponse.redirect(orgSelection);
}
},
});
export const config = {
2024-02-16 01:49:19 +00:00
matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
2024-03-21 21:15:27 +00:00
}; */