mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
fix(client): avoid atom to be proxy (#4079)
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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";
|
||||
|
||||
12
packages/better-auth/src/utils/is-atom.ts
Normal file
12
packages/better-auth/src/utils/is-atom.ts
Normal 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"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user