@better-auth-ui/react 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import { useAuth, useAuthMutation, useSession } from "@better-auth-ui/react";
1
+ import { useAuth, useAuthMutation } from "@better-auth-ui/react";
2
+ import { useQueryClient } from "@tanstack/react-query";
2
3
  export { useAuthMutation } from "./use-auth-mutation";
3
4
  /**
4
5
  * Hook that creates a mutation for email/password sign-up.
@@ -10,13 +11,13 @@ export { useAuthMutation } from "./use-auth-mutation";
10
11
  */
11
12
  export function useSignUpEmail(options) {
12
13
  const { authClient } = useAuth();
13
- const { refetch } = useSession({ refetchOnMount: false });
14
+ const queryClient = useQueryClient();
14
15
  return useAuthMutation({
15
16
  authFn: authClient.signUp.email,
16
17
  options: {
17
18
  ...options,
18
19
  onSuccess: async (...args) => {
19
- await refetch();
20
+ queryClient.resetQueries({ queryKey: ["auth", "getSession"] });
20
21
  await options?.onSuccess?.(...args);
21
22
  }
22
23
  }
@@ -0,0 +1,43 @@
1
+ import type { AuthClient } from "../../lib/auth-client";
2
+ import { type UseAuthMutationOptions } from "../auth/use-auth-mutation";
3
+ /**
4
+ * Hook that creates a mutation for adding a new passkey.
5
+ *
6
+ * Refetches the passkeys list on success.
7
+ *
8
+ * @returns The `useMutation` result.
9
+ */
10
+ export declare function useAddPasskey(options?: UseAuthMutationOptions<AuthClient["passkey"]["addPasskey"]>): import("../auth/use-auth-mutation").UseAuthMutationResult<(opts?: {
11
+ fetchOptions?: import("better-auth").ClientFetchOption;
12
+ name?: string;
13
+ authenticatorAttachment?: "platform" | "cross-platform";
14
+ context?: string | null;
15
+ extensions?: import("@better-auth/passkey/client").AuthenticationExtensionsClientInputs;
16
+ useAutoRegister?: boolean;
17
+ returnWebAuthnResponse?: boolean;
18
+ } | undefined, fetchOpts?: import("better-auth").ClientFetchOption | undefined) => Promise<{
19
+ data: null;
20
+ error: {
21
+ message?: string | undefined;
22
+ status: number;
23
+ statusText: string;
24
+ };
25
+ } | {
26
+ data: import("@better-auth/passkey/client").Passkey;
27
+ error: null;
28
+ } | {
29
+ webauthn: {
30
+ response: import("@better-auth/passkey/client").RegistrationResponseJSON;
31
+ clientExtensionResults: import("@better-auth/passkey/client").AuthenticationExtensionsClientOutputs;
32
+ };
33
+ data: import("@better-auth/passkey/client").Passkey;
34
+ error: null;
35
+ } | {
36
+ data: null;
37
+ error: {
38
+ code: string;
39
+ message: string;
40
+ status: number;
41
+ statusText: string;
42
+ };
43
+ }>>;
@@ -0,0 +1,24 @@
1
+ import { useAuth } from "../../components/auth/auth-provider";
2
+ import { useAuthMutation } from "../auth/use-auth-mutation";
3
+ import { useListUserPasskeys } from "./use-list-user-passkeys";
4
+ /**
5
+ * Hook that creates a mutation for adding a new passkey.
6
+ *
7
+ * Refetches the passkeys list on success.
8
+ *
9
+ * @returns The `useMutation` result.
10
+ */
11
+ export function useAddPasskey(options) {
12
+ const { authClient } = useAuth();
13
+ const { refetch } = useListUserPasskeys();
14
+ return useAuthMutation({
15
+ authFn: authClient.passkey.addPasskey,
16
+ options: {
17
+ ...options,
18
+ onSuccess: async (...args) => {
19
+ await refetch();
20
+ await options?.onSuccess?.(...args);
21
+ }
22
+ }
23
+ });
24
+ }
@@ -0,0 +1,21 @@
1
+ import type { AuthClient } from "../../lib/auth-client";
2
+ import { type UseAuthMutationOptions } from "../auth/use-auth-mutation";
3
+ /**
4
+ * Hook that creates a mutation for deleting a passkey.
5
+ *
6
+ * Refetches the passkeys list on success.
7
+ *
8
+ * @returns The `useMutation` result.
9
+ */
10
+ export declare function useDeletePasskey(options?: UseAuthMutationOptions<AuthClient["passkey"]["deletePasskey"]>): import("../auth/use-auth-mutation").UseAuthMutationResult<(<FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
11
+ id: string;
12
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth").Prettify<{
13
+ id: string;
14
+ } & {
15
+ fetchOptions?: FetchOptions | undefined;
16
+ }>, data_1?: FetchOptions | undefined) => Promise<import("better-auth/react").BetterFetchResponse<{
17
+ status: boolean;
18
+ }, {
19
+ code?: string | undefined;
20
+ message?: string | undefined;
21
+ }, FetchOptions["throw"] extends true ? true : false>>)>;
@@ -0,0 +1,24 @@
1
+ import { useAuth } from "../../components/auth/auth-provider";
2
+ import { useAuthMutation } from "../auth/use-auth-mutation";
3
+ import { useListUserPasskeys } from "./use-list-user-passkeys";
4
+ /**
5
+ * Hook that creates a mutation for deleting a passkey.
6
+ *
7
+ * Refetches the passkeys list on success.
8
+ *
9
+ * @returns The `useMutation` result.
10
+ */
11
+ export function useDeletePasskey(options) {
12
+ const { authClient } = useAuth();
13
+ const { refetch } = useListUserPasskeys();
14
+ return useAuthMutation({
15
+ authFn: authClient.passkey.deletePasskey,
16
+ options: {
17
+ ...options,
18
+ onSuccess: async (...args) => {
19
+ await refetch();
20
+ await options?.onSuccess?.(...args);
21
+ }
22
+ }
23
+ });
24
+ }
@@ -0,0 +1,11 @@
1
+ import { type AuthClient } from "@better-auth-ui/react";
2
+ import { type UseAuthQueryOptions } from "../auth/use-auth-query";
3
+ /**
4
+ * Retrieve the passkeys registered for the current user.
5
+ *
6
+ * The underlying query is enabled only when session data is available.
7
+ *
8
+ * @param options - Optional React Query options to customize the query behavior.
9
+ * @returns The React Query result for the passkeys list.
10
+ */
11
+ export declare function useListUserPasskeys(options?: Partial<UseAuthQueryOptions<AuthClient["passkey"]["listUserPasskeys"]>>): import("@tanstack/react-query").UseQueryResult<import("@better-auth/passkey/client").Passkey[] | null, import("better-auth/react").BetterFetchError>;
@@ -0,0 +1,22 @@
1
+ import { useAuth, useSession } from "@better-auth-ui/react";
2
+ import { useAuthQuery } from "../auth/use-auth-query";
3
+ /**
4
+ * Retrieve the passkeys registered for the current user.
5
+ *
6
+ * The underlying query is enabled only when session data is available.
7
+ *
8
+ * @param options - Optional React Query options to customize the query behavior.
9
+ * @returns The React Query result for the passkeys list.
10
+ */
11
+ export function useListUserPasskeys(options) {
12
+ const { authClient } = useAuth();
13
+ const { data: session } = useSession({ refetchOnMount: false });
14
+ return useAuthQuery({
15
+ authFn: authClient.passkey.listUserPasskeys,
16
+ options: {
17
+ queryKey: ["auth", "listUserPasskeys", session?.user.id],
18
+ enabled: !!session,
19
+ ...options
20
+ }
21
+ });
22
+ }
package/dist/index.d.ts CHANGED
@@ -9,18 +9,22 @@ export * from "./hooks/auth/use-send-verification-email";
9
9
  export * from "./hooks/auth/use-session";
10
10
  export * from "./hooks/auth/use-sign-in-email";
11
11
  export * from "./hooks/auth/use-sign-in-magic-link";
12
+ export * from "./hooks/auth/use-sign-in-passkey";
12
13
  export * from "./hooks/auth/use-sign-in-social";
13
14
  export * from "./hooks/auth/use-sign-out";
14
15
  export * from "./hooks/auth/use-sign-up-email";
15
16
  export * from "./hooks/auth/use-user";
16
17
  export * from "./hooks/settings/use-account-info";
18
+ export * from "./hooks/settings/use-add-passkey";
17
19
  export * from "./hooks/settings/use-change-email";
18
20
  export * from "./hooks/settings/use-change-password";
21
+ export * from "./hooks/settings/use-delete-passkey";
19
22
  export * from "./hooks/settings/use-delete-user";
20
23
  export * from "./hooks/settings/use-link-social";
21
24
  export * from "./hooks/settings/use-list-accounts";
22
25
  export * from "./hooks/settings/use-list-device-sessions";
23
26
  export * from "./hooks/settings/use-list-sessions";
27
+ export * from "./hooks/settings/use-list-user-passkeys";
24
28
  export * from "./hooks/settings/use-revoke-multi-session";
25
29
  export * from "./hooks/settings/use-revoke-session";
26
30
  export * from "./hooks/settings/use-set-active-session";
package/dist/index.js CHANGED
@@ -10,18 +10,22 @@ export * from "./hooks/auth/use-send-verification-email";
10
10
  export * from "./hooks/auth/use-session";
11
11
  export * from "./hooks/auth/use-sign-in-email";
12
12
  export * from "./hooks/auth/use-sign-in-magic-link";
13
+ export * from "./hooks/auth/use-sign-in-passkey";
13
14
  export * from "./hooks/auth/use-sign-in-social";
14
15
  export * from "./hooks/auth/use-sign-out";
15
16
  export * from "./hooks/auth/use-sign-up-email";
16
17
  export * from "./hooks/auth/use-user";
17
18
  export * from "./hooks/settings/use-account-info";
19
+ export * from "./hooks/settings/use-add-passkey";
18
20
  export * from "./hooks/settings/use-change-email";
19
21
  export * from "./hooks/settings/use-change-password";
22
+ export * from "./hooks/settings/use-delete-passkey";
20
23
  export * from "./hooks/settings/use-delete-user";
21
24
  export * from "./hooks/settings/use-link-social";
22
25
  export * from "./hooks/settings/use-list-accounts";
23
26
  export * from "./hooks/settings/use-list-device-sessions";
24
27
  export * from "./hooks/settings/use-list-sessions";
28
+ export * from "./hooks/settings/use-list-user-passkeys";
25
29
  export * from "./hooks/settings/use-revoke-multi-session";
26
30
  export * from "./hooks/settings/use-revoke-session";
27
31
  export * from "./hooks/settings/use-set-active-session";