2024-02-16 01:49:19 +00:00
|
|
|
import { authMiddleware, redirectToSignIn } from '@clerk/nextjs';
|
|
|
|
import { NextResponse } from 'next/server';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
|
|
|
export default authMiddleware({
|
2024-02-21 22:33:57 +00:00
|
|
|
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-02-15 02:30:10 +00:00
|
|
|
};
|