From 7668fa69ccf10d0045fadf9af930675f934ca242 Mon Sep 17 00:00:00 2001 From: -Puter <22245429+puterhimself@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:01:22 +0530 Subject: [PATCH] fix: route web auth through same origin --- apps/web/src/lib/auth.server.ts | 9 ++++----- packages/auth/src/web/auth-client.ts | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/web/src/lib/auth.server.ts b/apps/web/src/lib/auth.server.ts index c18079b..fff41b6 100644 --- a/apps/web/src/lib/auth.server.ts +++ b/apps/web/src/lib/auth.server.ts @@ -1,12 +1,8 @@ -import { env } from "@code/env/web"; import { redirect } from "react-router"; interface AuthLoaderData { readonly token: string | null; } - -const tokenUrl = new URL("/api/auth/convex/token", env.VITE_AUTH_URL); - export const loadAuthToken = async ( request: Request ): Promise => { @@ -14,9 +10,12 @@ export const loadAuthToken = async ( if (!cookie) { return { token: null }; } + const tokenUrl = new URL( + "/api/auth/convex/token", + new URL(request.url).origin + ); const headers = new Headers({ cookie }); - headers.set("host", tokenUrl.host); const response = await fetch(tokenUrl, { headers }); if (response.status === 401) { return { token: null }; diff --git a/packages/auth/src/web/auth-client.ts b/packages/auth/src/web/auth-client.ts index c8f3554..64edd8e 100644 --- a/packages/auth/src/web/auth-client.ts +++ b/packages/auth/src/web/auth-client.ts @@ -1,8 +1,7 @@ -import { env } from "@code/env/web"; import { convexClient } from "@convex-dev/better-auth/client/plugins"; import { createAuthClient } from "better-auth/react"; export const authClient = createAuthClient({ - baseURL: env.VITE_AUTH_URL, + baseURL: typeof window === "undefined" ? undefined : window.location.origin, plugins: [convexClient()], });