fix: route web auth through same origin
This commit is contained in:
@@ -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<AuthLoaderData> => {
|
||||
@@ -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 };
|
||||
|
||||
@@ -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()],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user