18 lines
510 B
TypeScript
18 lines
510 B
TypeScript
// src/middleware.ts
|
|
import { clerkMiddleware, createRouteMatcher } from '@clerk/astro/server';
|
|
import type { AstroMiddlewareRequest, AstroMiddlewareResponse } from 'astro';
|
|
|
|
const isProtectedRoute = createRouteMatcher([
|
|
'/pokemon',
|
|
]);
|
|
|
|
export const onRequest = clerkMiddleware((auth, context) => {
|
|
const { isAuthenticated, redirectToSignIn } = auth()
|
|
|
|
if (!isAuthenticated && isProtectedRoute(context.request)) {
|
|
// Add custom logic to run before redirecting
|
|
|
|
return redirectToSignIn()
|
|
}
|
|
});
|