Imported from heisdeku/sanity-content-architecture-kit (
astro/.claude/skills/basic-auth-and-redirects/SKILL.md). Install upstream withnpx skills add heisdeku/sanity-content-architecture-kit --skill basic-auth-and-redirects. Copyright stays with the author.
Basic Auth and redirects
Both live in src/middleware.ts and src/features/site/{basic-auth,security,redirects}.ts.
- Order (spec section 6): pass-through for assets,
/studio,/api/*(except the rewrite-only Markdown route) -> Basic Auth -> redirects -> Markdown negotiation -> 404s. SITE_SECURITY_QUERYreturnsbasicAuthEnabledand the paths withpasswordProtect; it is cached 60 s in memory. Site-wide wins. Credentials areBASIC_AUTH_USERandBASIC_AUTH_PASSWORD(env only), compared withtimingSafeEqual.- If Sanity is unreachable the middleware fails open and logs a warning. If protection is on but credentials are missing it also fails open with a warning.
- Protected responses are
private, no-storeand never enter the route cache. - Redirects come from
site.redirects[](REDIRECTS_QUERY, cached 60 s): exactfrommatch,tois an appLink resolved withresolveLink, status 301 or 302 from the document. /api/revalidateclears both TTL caches when the Site document changes.