import { defineMiddleware } from "astro:middleware"; // Keep dev traffic on 127.0.0.1: ATProto OAuth callbacks always come back on // 127.0.0.1, so a stray localhost session ends up with cookies on a different // origin than the post-login session — login appears to silently fail. export const onRequest = defineMiddleware(async (context, next) => { if (import.meta.env.DEV && context.url.hostname === "localhost") { const url = new URL(context.url); url.hostname = "127.0.0.1"; return context.redirect(url.toString(), 307); } return next(); });