2026-02-25 20:31:13 -05:00
|
|
|
// src/middleware.ts
|
|
|
|
|
import { clerkMiddleware, createRouteMatcher } from '@clerk/astro/server';
|
|
|
|
|
import type { AstroMiddlewareRequest, AstroMiddlewareResponse } from 'astro';
|
2026-02-25 18:47:33 -05:00
|
|
|
|
2026-02-25 20:31:13 -05:00
|
|
|
const isProtectedRoute = createRouteMatcher([
|
|
|
|
|
'/pokemon',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
export const onRequest = clerkMiddleware((auth, context) => {
|
|
|
|
|
if (!auth().userId && isProtectedRoute(context.request)) {
|
|
|
|
|
// Redirect unauthenticated users to the sign-in page
|
|
|
|
|
return auth().redirectToSignIn();
|
|
|
|
|
}
|
|
|
|
|
});
|