fix(web): bypass auth proxy for local dev (#1213)
Some checks failed
Publish Tools / publish (push) Has been cancelled

Co-authored-by: Dhravya Shah <dhravya@supermemory.com>
Co-authored-by: Dhravya Shah <dhravyashah@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Gautam Sharma 2026-07-11 08:41:48 +05:30 committed by GitHub
parent 19d7f122b2
commit 2cebe81512
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 10 deletions

View file

@ -36,16 +36,7 @@ Before you begin, ensure you have the following installed:
# You'll need to add your API keys and database URLs
```
4. **Change proxy for local development**
Add this in your `proxy.ts`(apps/web) before retrieving the cookie (`getSessionCookie(request)`):
```ts
if (url.hostname === "localhost") {
return NextResponse.next();
}
5. **Start the Development Server**
4. **Start the Development Server**
```bash
bun run dev:local

View file

@ -2,6 +2,8 @@ import { getSessionCookie } from "better-auth/cookies"
import { NextResponse } from "next/server"
import { getPublicRequestUrl } from "@/lib/url-helpers"
const LOCAL_DEV_HOSTS = new Set(["localhost", "127.0.0.1", "::1"])
function getAuthSessionCookie(request: Request): string | null {
return (
getSessionCookie(request) ??
@ -16,6 +18,18 @@ export default async function proxy(request: Request) {
console.debug("[PROXY] Path:", url.pathname)
console.debug("[PROXY] Method:", request.method)
// Development builds only: getPublicRequestUrl trusts x-forwarded-host, so
// a hostname check alone could be spoofed in production to skip the /api
// 401 gate below. NODE_ENV is inlined at build time, making this dead code
// in production bundles.
if (
process.env.NODE_ENV === "development" &&
LOCAL_DEV_HOSTS.has(url.hostname)
) {
console.debug("[PROXY] Local dev host, allowing access")
return NextResponse.next()
}
const sessionCookie = getAuthSessionCookie(request)
console.debug("[PROXY] Session cookie exists:", !!sessionCookie)