mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-02 12:26:43 -05:00
fix(client): baseURL is undefined for SSR (#4760)
This commit is contained in:
25
packages/better-auth/src/client/client-ssr.test.ts
Normal file
25
packages/better-auth/src/client/client-ssr.test.ts
Normal 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();
|
||||
});
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user