bagsy/apps/api/middleware.ts
bananabas 4fe4a98b1c feat: Migrate from self-hosted to Vercel + Neon + Clerk
- Move database from self-hosted Postgres to Neon (free tier)
- Replace better-auth with Clerk authentication (email/password + OAuth)
- Integrate Ably for real-time sync (replaces custom WebSocket)
- Remove passkey authentication (pending Apple Developer account)
- Add Clerk Organizations for household management
- Implement custom household join-code flow with Clerk
- Add secure Ably key fetching via backend API
- Update iOS app for Clerk auth and Ably real-time sync
- Configure Vercel deployment settings
- Update environment configuration for new infrastructure

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-27 18:59:00 +01:00

21 lines
No EOL
527 B
TypeScript

import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
/**
* Clerk middleware for route protection
* Protects all API routes except public endpoints
*/
const isPublicRoute = createRouteMatcher([
'/api/auth(.*)',
'/api/health',
'/api/config(.*)', // Allow config endpoints for iOS to fetch keys
]);
export default clerkMiddleware((auth, req) => {
if (!isPublicRoute(req)) {
auth().protect();
}
});
export const config = {
matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};