diff --git a/packages/better-auth/src/client/proxy.ts b/packages/better-auth/src/client/proxy.ts index 3c108f48..b4a840a2 100644 --- a/packages/better-auth/src/client/proxy.ts +++ b/packages/better-auth/src/client/proxy.ts @@ -93,21 +93,24 @@ export function createDynamicPathProxy>( method, async onSuccess(context) { await options?.onSuccess?.(context); + if (!atomListeners) return; /** * We trigger listeners */ - const matches = atomListeners?.find((s) => s.matcher(routePath)); - if (!matches) return; - const signal = atoms[matches.signal as any]; - if (!signal) return; - /** - * To avoid race conditions we set the signal in a setTimeout - */ - const val = signal.get(); - setTimeout(() => { - //@ts-expect-error - signal.set(!val); - }, 10); + const matches = atomListeners.filter((s) => s.matcher(routePath)); + if (!matches.length) return; + for (const match of matches) { + const signal = atoms[match.signal as any]; + if (!signal) return; + /** + * To avoid race conditions we set the signal in a setTimeout + */ + const val = signal.get(); + setTimeout(() => { + //@ts-expect-error + signal.set(!val); + }, 10); + } }, }); }, diff --git a/packages/better-auth/src/plugins/passkey/client.ts b/packages/better-auth/src/plugins/passkey/client.ts index f5395e72..c5334506 100644 --- a/packages/better-auth/src/plugins/passkey/client.ts +++ b/packages/better-auth/src/plugins/passkey/client.ts @@ -11,7 +11,7 @@ import type { import type { Session } from "inspector"; import type { User } from "../../types"; import type { passkey as passkeyPl, Passkey } from "."; -import type { BetterAuthClientPlugin } from "../../client/types"; +import type { BetterAuthClientPlugin, Store } from "../../client/types"; import { useAuthQuery } from "../../client"; import { atom } from "nanostores"; @@ -19,8 +19,10 @@ export const getPasskeyActions = ( $fetch: BetterFetch, { $listPasskeys, + $store, }: { $listPasskeys: ReturnType>; + $store: Store; }, ) => { const signInPasskey = async ( @@ -55,6 +57,8 @@ export const getPasskeyActions = ( ...options, method: "POST", }); + $listPasskeys.set(Math.random()); + $store.notify("$sessionSignal"); return verified; } catch (e) { @@ -204,9 +208,10 @@ export const passkeyClient = () => { return { id: "passkey", $InferServerPlugin: {} as ReturnType, - getActions: ($fetch) => + getActions: ($fetch, $store) => getPasskeyActions($fetch, { $listPasskeys, + $store, }), getAtoms($fetch) { const listPasskeys = useAuthQuery( @@ -232,10 +237,15 @@ export const passkeyClient = () => { return ( path === "/passkey/verify-registration" || path === "/passkey/delete-passkey" || - path === "/passkey/update-passkey" + path === "/passkey/update-passkey" || + path === "/sign-out" ); }, - signal: "_listPasskeys", + signal: "$listPasskeys", + }, + { + matcher: (path) => path === "/passkey/verify-authentication", + signal: "$sessionSignal", }, ], } satisfies BetterAuthClientPlugin;