fix(client): baseURL is undefined for SSR (#4760)

This commit is contained in:
Alex Yang
2025-09-18 21:34:19 -07:00
parent 8709af6fe9
commit c15140549e
2 changed files with 27 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
// @vitest-environment node
import { expect, it, vi } from "vitest";
import { createAuthClient as createVueClient } from "./vue";
it("should call '/api/auth' if no baseURL is provided", async () => {
const customFetchImpl = vi.fn(async (url: string | Request | URL) => {
expect(url).toBe("/api/auth/get-session");
return new Response();
});
const originalEnv = process.env;
process.env = {};
// use DisposableStack when Node.js 24 is the minimum requirement
using _ = {
[Symbol.dispose]() {
process.env = originalEnv;
},
};
const client = createVueClient({
fetchOptions: {
customFetchImpl,
},
});
await client.getSession();
expect(customFetchImpl).toBeCalled();
});

View File

@@ -9,7 +9,8 @@ import { parseJSON } from "./parser";
export const getClientConfig = (options?: ClientOptions) => {
/* check if the credentials property is supported. Useful for cf workers */
const isCredentialsSupported = "credentials" in Request.prototype;
const baseURL = getBaseURL(options?.baseURL, options?.basePath);
const baseURL =
getBaseURL(options?.baseURL, options?.basePath) ?? "/api/auth";
const pluginsFetchPlugins =
options?.plugins
?.flatMap((plugin) => plugin.fetchPlugins)