Files
spoon/apps/next/src/proxy.ts
T
Gabriel Brown 2dfa97ee4f
Build and Push Next App / quality (push) Failing after 48s
Build and Push Next App / build-next (push) Has been skipped
Add agent workflows & stuff
2026-06-21 21:15:15 -05:00

39 lines
1.0 KiB
TypeScript

import {
convexAuthNextjsMiddleware,
createRouteMatcher,
nextjsMiddlewareRedirect,
} from '@convex-dev/auth/nextjs/server';
const isAuthRoute = createRouteMatcher(['/sign-in', '/forgot-password']);
const isProtectedRoute = createRouteMatcher([
'/dashboard(.*)',
'/spoons(.*)',
'/updates(.*)',
'/agents(.*)',
'/github(.*)',
'/settings(.*)',
'/profile(.*)',
]);
export default convexAuthNextjsMiddleware(
async (request, { convexAuth }) => {
const isAuthenticated = await convexAuth.isAuthenticated();
if (isAuthRoute(request) && isAuthenticated) {
return nextjsMiddlewareRedirect(request, '/dashboard');
}
if (isProtectedRoute(request) && !isAuthenticated) {
return nextjsMiddlewareRedirect(request, '/sign-in');
}
},
{ cookieConfig: { maxAge: 60 * 60 * 24 * 30 } },
);
export const config = {
matcher: [
'/((?!_next/static|_next/image|favicon.ico|monitoring-tunnel|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
'/((?!.*\\..*|_next).*)',
'/',
'/(api)(.*)',
],
};