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,
|
method,
|
||||||
async onSuccess(context) {
|
async onSuccess(context) {
|
||||||
await options?.onSuccess?.(context);
|
await options?.onSuccess?.(context);
|
||||||
|
if (!atomListeners) return;
|
||||||
/**
|
/**
|
||||||
* We trigger listeners
|
* We trigger listeners
|
||||||
*/
|
*/
|
||||||
const matches = atomListeners?.find((s) => s.matcher(routePath));
|
const matches = atomListeners.filter((s) => s.matcher(routePath));
|
||||||
if (!matches) return;
|
if (!matches.length) return;
|
||||||
const signal = atoms[matches.signal as any];
|
for (const match of matches) {
|
||||||
|
const signal = atoms[match.signal as any];
|
||||||
if (!signal) return;
|
if (!signal) return;
|
||||||
/**
|
/**
|
||||||
* To avoid race conditions we set the signal in a setTimeout
|
* 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
|
//@ts-expect-error
|
||||||
signal.set(!val);
|
signal.set(!val);
|
||||||
}, 10);
|
}, 10);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type {
|
|||||||
import type { Session } from "inspector";
|
import type { Session } from "inspector";
|
||||||
import type { User } from "../../types";
|
import type { User } from "../../types";
|
||||||
import type { passkey as passkeyPl, Passkey } from ".";
|
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 { useAuthQuery } from "../../client";
|
||||||
import { atom } from "nanostores";
|
import { atom } from "nanostores";
|
||||||
|
|
||||||
@@ -19,8 +19,10 @@ export const getPasskeyActions = (
|
|||||||
$fetch: BetterFetch,
|
$fetch: BetterFetch,
|
||||||
{
|
{
|
||||||
$listPasskeys,
|
$listPasskeys,
|
||||||
|
$store,
|
||||||
}: {
|
}: {
|
||||||
$listPasskeys: ReturnType<typeof atom<any>>;
|
$listPasskeys: ReturnType<typeof atom<any>>;
|
||||||
|
$store: Store;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const signInPasskey = async (
|
const signInPasskey = async (
|
||||||
@@ -55,6 +57,8 @@ export const getPasskeyActions = (
|
|||||||
...options,
|
...options,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
$listPasskeys.set(Math.random());
|
||||||
|
$store.notify("$sessionSignal");
|
||||||
|
|
||||||
return verified;
|
return verified;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -204,9 +208,10 @@ export const passkeyClient = () => {
|
|||||||
return {
|
return {
|
||||||
id: "passkey",
|
id: "passkey",
|
||||||
$InferServerPlugin: {} as ReturnType<typeof passkeyPl>,
|
$InferServerPlugin: {} as ReturnType<typeof passkeyPl>,
|
||||||
getActions: ($fetch) =>
|
getActions: ($fetch, $store) =>
|
||||||
getPasskeyActions($fetch, {
|
getPasskeyActions($fetch, {
|
||||||
$listPasskeys,
|
$listPasskeys,
|
||||||
|
$store,
|
||||||
}),
|
}),
|
||||||
getAtoms($fetch) {
|
getAtoms($fetch) {
|
||||||
const listPasskeys = useAuthQuery<Passkey[]>(
|
const listPasskeys = useAuthQuery<Passkey[]>(
|
||||||
@@ -232,10 +237,15 @@ export const passkeyClient = () => {
|
|||||||
return (
|
return (
|
||||||
path === "/passkey/verify-registration" ||
|
path === "/passkey/verify-registration" ||
|
||||||
path === "/passkey/delete-passkey" ||
|
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;
|
} satisfies BetterAuthClientPlugin;
|
||||||
|
|||||||
Reference in New Issue
Block a user