Link bookmarking tool built on aproto (early alpha)
at main 683 B view raw
1import { createMiddleware } from "@solidjs/start/middleware" 2import { getAuthSession } from "@/lib/auth/utils.ts" 3 4const protectedPrefixes = ["/profile", "/account", "/pins"] 5 6export default createMiddleware({ 7 onRequest: async (event) => { 8 const { pathname, origin } = new URL(event.request.url) 9 if ( 10 protectedPrefixes.some((prefix) => pathname.startsWith(prefix)) 11 ) { 12 const session = await getAuthSession() 13 if (!session) { 14 return Response.redirect( 15 `${origin}/login?next=${encodeURIComponent(pathname)}`, 16 302, 17 ) 18 } 19 } 20 }, 21})