mvp-ai's picture
download
raw
2.13 kB
import { clerkMiddleware } from '@clerk/nextjs/server'
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
const STAGING_PASSWORD = process.env.STAGING_PASSWORD
const COOKIE_NAME = "staging_auth"
// Paths that should be accessible without staging auth
const PUBLIC_PATHS = [
'/maintenance',
'/api/staging-auth',
'/api/v1', // Bot API - has its own auth via API keys
'/api/skill.md', // Skill index (links to advisor + review)
'/api/skill.json', // Skill metadata index
'/api/advisor/', // Advisor skill (search, install, security)
'/api/review/', // Review skill (ratings, reviews)
'/_next',
'/favicon.ico',
'/icon.png',
'/apple-icon.png',
]
function isPublicPath(pathname: string): boolean {
return PUBLIC_PATHS.some(path => pathname.startsWith(path))
}
function checkStagingAuth(request: NextRequest): boolean {
// If no staging password is configured, allow all access
if (!STAGING_PASSWORD) {
return true
}
const authCookie = request.cookies.get(COOKIE_NAME)
if (!authCookie) {
return false
}
// Verify the cookie value
const expectedValue = Buffer.from(STAGING_PASSWORD).toString("base64")
return authCookie.value === expectedValue
}
export default clerkMiddleware((auth, request) => {
const { pathname } = request.nextUrl
// Skip staging auth check for public paths
if (isPublicPath(pathname)) {
return
}
// Check staging authentication
if (STAGING_PASSWORD && !checkStagingAuth(request)) {
const maintenanceUrl = new URL('/maintenance', request.url)
return NextResponse.redirect(maintenanceUrl)
}
// All routes are public; auth state is available for client components.
// Protected actions (voting/reviews) check auth in Convex mutations.
})
export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest|md|json)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}

Xet Storage Details

Size:
2.13 kB
·
Xet hash:
590996df277be4732d3bdcbb2a300cb45dffc7f3f7a5905ab9481d4095416165

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.