fix(client): avoid atom to be proxy (#4079)

This commit is contained in:
Alex Yang
2025-08-20 16:30:04 -07:00
committed by GitHub
parent bb634a0f5c
commit 73da454c6c
4 changed files with 25 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import { createAuthClient as createSolidClient } from "./solid";
import { createAuthClient as createReactClient } from "./react";
import { createAuthClient as createVueClient } from "./vue";
import { createAuthClient as createSvelteClient } from "./svelte";
import { createAuthClient as createVanillaClient } from "./vanilla";
import { testClientPlugin, testClientPlugin2 } from "./test-plugin";
import type { Accessor } from "solid-js";
import type { Ref } from "vue";
@@ -12,8 +13,15 @@ import type { Session } from "../types";
import { BetterFetchError } from "@better-fetch/fetch";
import { twoFactorClient } from "../plugins";
import { organizationClient, passkeyClient } from "./plugins";
import { isProxy } from "node:util/types";
describe("run time proxy", async () => {
it("atom in proxy should not be proxy", async () => {
const client = createVanillaClient();
const atom = client.$store.atoms.session;
expect(isProxy(atom)).toBe(false);
});
it("proxy api should be called", async () => {
let apiCalled = false;
const client = createSolidClient({

View File

@@ -2,6 +2,7 @@ import type { BetterFetch, BetterFetchOption } from "@better-fetch/fetch";
import type { Atom, PreinitializedWritableAtom } from "nanostores";
import type { ProxyRequest } from "./path-to-object";
import type { BetterAuthClientPlugin } from "./types";
import { isAtom } from "../utils/is-atom";
function getMethod(
path: string,
@@ -55,6 +56,9 @@ export function createDynamicPathProxy<T extends Record<string, any>>(
if (typeof current === "function") {
return current;
}
if (isAtom(current)) {
return current;
}
return createProxy(fullPath);
},
apply: async (_, __, args) => {

View File

@@ -1,6 +1,6 @@
import fs from "fs/promises";
import { generateRandomString } from "../crypto/random";
import { afterAll, onTestFinished } from "vitest";
import { afterAll } from "vitest";
import { betterAuth } from "../auth";
import { createAuthClient } from "../client/vanilla";
import type { BetterAuthOptions, ClientOptions, Session, User } from "../types";

View File

@@ -0,0 +1,12 @@
import type { Atom } from "nanostores";
export function isAtom(value: unknown): value is Atom<unknown> {
return (
typeof value === "object" &&
value !== null &&
"get" in value &&
typeof (value as any).get === "function" &&
"lc" in value &&
typeof (value as any).lc === "number"
);
}