mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 12:27:44 +00:00
fix(passkey): atom listeners not working (#5096)
This commit is contained in:
@@ -93,12 +93,14 @@ export function createDynamicPathProxy<T extends Record<string, any>>(
|
||||
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];
|
||||
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
|
||||
@@ -108,6 +110,7 @@ export function createDynamicPathProxy<T extends Record<string, any>>(
|
||||
//@ts-expect-error
|
||||
signal.set(!val);
|
||||
}, 10);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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<typeof atom<any>>;
|
||||
$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<typeof passkeyPl>,
|
||||
getActions: ($fetch) =>
|
||||
getActions: ($fetch, $store) =>
|
||||
getPasskeyActions($fetch, {
|
||||
$listPasskeys,
|
||||
$store,
|
||||
}),
|
||||
getAtoms($fetch) {
|
||||
const listPasskeys = useAuthQuery<Passkey[]>(
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user