@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.
- package/dist/hooks/auth/use-sign-in-email.js +4 -3
- package/dist/hooks/auth/use-sign-in-passkey.d.ts +58 -0
- package/dist/hooks/auth/use-sign-in-passkey.js +25 -0
- package/dist/hooks/auth/use-sign-up-email.d.ts +744 -0
- package/dist/hooks/auth/use-sign-up-email.js +4 -3
- package/dist/hooks/settings/use-add-passkey.d.ts +43 -0
- package/dist/hooks/settings/use-add-passkey.js +24 -0
- package/dist/hooks/settings/use-delete-passkey.d.ts +21 -0
- package/dist/hooks/settings/use-delete-passkey.js +24 -0
- package/dist/hooks/settings/use-list-user-passkeys.d.ts +11 -0
- package/dist/hooks/settings/use-list-user-passkeys.js +22 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/lib/auth-client.d.ts +1935 -223
- package/dist/lib/auth-client.js +7 -1
- package/package.json +8 -1
- package/src/hooks/auth/use-sign-in-email.ts +5 -4
- package/src/hooks/auth/use-sign-in-passkey.ts +34 -0
- package/src/hooks/auth/use-sign-up-email.ts +5 -4
- package/src/hooks/settings/use-add-passkey.ts +32 -0
- package/src/hooks/settings/use-delete-passkey.ts +32 -0
- package/src/hooks/settings/use-list-user-passkeys.ts +28 -0
- package/src/index.ts +4 -0
- package/src/lib/auth-client.ts +7 -1
- package/dist/hooks/auth/use-forgot-password.d.ts +0 -20
- package/dist/hooks/auth/use-forgot-password.js +0 -14
- package/dist/hooks/use-hydrated.d.ts +0 -6
- package/dist/hooks/use-hydrated.js +0 -18
- package/dist/lib/auth-hook-options.d.ts +0 -8
- package/dist/lib/auth-hook-options.js +0 -1
package/dist/lib/auth-client.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { passkeyClient } from "@better-auth/passkey/client";
|
|
1
2
|
import { magicLinkClient, multiSessionClient, usernameClient } from "better-auth/client/plugins";
|
|
2
3
|
import { createAuthClient } from "better-auth/react";
|
|
3
4
|
const authClient = createAuthClient({
|
|
4
|
-
plugins: [
|
|
5
|
+
plugins: [
|
|
6
|
+
magicLinkClient(),
|
|
7
|
+
multiSessionClient(),
|
|
8
|
+
passkeyClient(),
|
|
9
|
+
usernameClient()
|
|
10
|
+
]
|
|
5
11
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth-ui/react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@types/react": "^19.2.14",
|
|
34
34
|
"@vitejs/plugin-react": "^6.0.1",
|
|
35
35
|
"@vitest/browser-playwright": "^4.1.4",
|
|
36
|
+
"@better-auth/passkey": "^1.6.4",
|
|
36
37
|
"better-auth": "^1.6.4",
|
|
37
38
|
"clsx": "^2.1.1",
|
|
38
39
|
"playwright": "^1.59.1",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"peerDependencies": {
|
|
51
52
|
"@react-email/components": ">=1.0.12",
|
|
52
53
|
"@tanstack/react-query": ">=5.99.0",
|
|
54
|
+
"@better-auth/passkey": ">=1.6.4",
|
|
53
55
|
"better-auth": ">=1.6.4",
|
|
54
56
|
"clsx": ">=2.0.0",
|
|
55
57
|
"react": ">=19.2.5",
|
|
@@ -58,6 +60,11 @@
|
|
|
58
60
|
"tailwindcss": ">=4.2.2",
|
|
59
61
|
"zod": ">=4.3.0"
|
|
60
62
|
},
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "https://github.com/better-auth-ui/better-auth-ui",
|
|
66
|
+
"directory": "packages/react"
|
|
67
|
+
},
|
|
61
68
|
"publishConfig": {
|
|
62
69
|
"access": "public"
|
|
63
70
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AuthClient,
|
|
3
3
|
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
useSession
|
|
4
|
+
useAuthMutation
|
|
6
5
|
} from "@better-auth-ui/react"
|
|
6
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
7
|
+
|
|
7
8
|
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
8
9
|
|
|
9
10
|
export { useAuthMutation } from "./use-auth-mutation"
|
|
@@ -20,14 +21,14 @@ export function useSignInEmail(
|
|
|
20
21
|
options?: UseAuthMutationOptions<AuthClient["signIn"]["email"]>
|
|
21
22
|
) {
|
|
22
23
|
const { authClient } = useAuth()
|
|
23
|
-
const
|
|
24
|
+
const queryClient = useQueryClient()
|
|
24
25
|
|
|
25
26
|
return useAuthMutation({
|
|
26
27
|
authFn: authClient.signIn.email,
|
|
27
28
|
options: {
|
|
28
29
|
...options,
|
|
29
30
|
onSuccess: async (...args) => {
|
|
30
|
-
|
|
31
|
+
queryClient.resetQueries({ queryKey: ["auth", "getSession"] })
|
|
31
32
|
await options?.onSuccess?.(...args)
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
2
|
+
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import {
|
|
6
|
+
type UseAuthMutationOptions,
|
|
7
|
+
useAuthMutation
|
|
8
|
+
} from "./use-auth-mutation"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for passkey sign-in.
|
|
12
|
+
*
|
|
13
|
+
* The mutation sends a passkey sign-in request and
|
|
14
|
+
* refetches the session on completion.
|
|
15
|
+
*
|
|
16
|
+
* @returns The `useMutation` result.
|
|
17
|
+
*/
|
|
18
|
+
export function useSignInPasskey(
|
|
19
|
+
options?: UseAuthMutationOptions<AuthClient["signIn"]["passkey"]>
|
|
20
|
+
) {
|
|
21
|
+
const { authClient } = useAuth()
|
|
22
|
+
const queryClient = useQueryClient()
|
|
23
|
+
|
|
24
|
+
return useAuthMutation({
|
|
25
|
+
authFn: authClient.signIn.passkey,
|
|
26
|
+
options: {
|
|
27
|
+
...options,
|
|
28
|
+
onSuccess: async (...args) => {
|
|
29
|
+
queryClient.resetQueries({ queryKey: ["auth", "getSession"] })
|
|
30
|
+
await options?.onSuccess?.(...args)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AuthClient,
|
|
3
3
|
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
useSession
|
|
4
|
+
useAuthMutation
|
|
6
5
|
} from "@better-auth-ui/react"
|
|
6
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
7
|
+
|
|
7
8
|
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
8
9
|
|
|
9
10
|
export { useAuthMutation } from "./use-auth-mutation"
|
|
@@ -20,14 +21,14 @@ export function useSignUpEmail(
|
|
|
20
21
|
options?: UseAuthMutationOptions<AuthClient["signUp"]["email"]>
|
|
21
22
|
) {
|
|
22
23
|
const { authClient } = useAuth()
|
|
23
|
-
const
|
|
24
|
+
const queryClient = useQueryClient()
|
|
24
25
|
|
|
25
26
|
return useAuthMutation({
|
|
26
27
|
authFn: authClient.signUp.email,
|
|
27
28
|
options: {
|
|
28
29
|
...options,
|
|
29
30
|
onSuccess: async (...args) => {
|
|
30
|
-
|
|
31
|
+
queryClient.resetQueries({ queryKey: ["auth", "getSession"] })
|
|
31
32
|
await options?.onSuccess?.(...args)
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import {
|
|
4
|
+
type UseAuthMutationOptions,
|
|
5
|
+
useAuthMutation
|
|
6
|
+
} from "../auth/use-auth-mutation"
|
|
7
|
+
import { useListUserPasskeys } from "./use-list-user-passkeys"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hook that creates a mutation for adding a new passkey.
|
|
11
|
+
*
|
|
12
|
+
* Refetches the passkeys list on success.
|
|
13
|
+
*
|
|
14
|
+
* @returns The `useMutation` result.
|
|
15
|
+
*/
|
|
16
|
+
export function useAddPasskey(
|
|
17
|
+
options?: UseAuthMutationOptions<AuthClient["passkey"]["addPasskey"]>
|
|
18
|
+
) {
|
|
19
|
+
const { authClient } = useAuth()
|
|
20
|
+
const { refetch } = useListUserPasskeys()
|
|
21
|
+
|
|
22
|
+
return useAuthMutation({
|
|
23
|
+
authFn: authClient.passkey.addPasskey,
|
|
24
|
+
options: {
|
|
25
|
+
...options,
|
|
26
|
+
onSuccess: async (...args) => {
|
|
27
|
+
await refetch()
|
|
28
|
+
await options?.onSuccess?.(...args)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import {
|
|
4
|
+
type UseAuthMutationOptions,
|
|
5
|
+
useAuthMutation
|
|
6
|
+
} from "../auth/use-auth-mutation"
|
|
7
|
+
import { useListUserPasskeys } from "./use-list-user-passkeys"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hook that creates a mutation for deleting a passkey.
|
|
11
|
+
*
|
|
12
|
+
* Refetches the passkeys list on success.
|
|
13
|
+
*
|
|
14
|
+
* @returns The `useMutation` result.
|
|
15
|
+
*/
|
|
16
|
+
export function useDeletePasskey(
|
|
17
|
+
options?: UseAuthMutationOptions<AuthClient["passkey"]["deletePasskey"]>
|
|
18
|
+
) {
|
|
19
|
+
const { authClient } = useAuth()
|
|
20
|
+
const { refetch } = useListUserPasskeys()
|
|
21
|
+
|
|
22
|
+
return useAuthMutation({
|
|
23
|
+
authFn: authClient.passkey.deletePasskey,
|
|
24
|
+
options: {
|
|
25
|
+
...options,
|
|
26
|
+
onSuccess: async (...args) => {
|
|
27
|
+
await refetch()
|
|
28
|
+
await options?.onSuccess?.(...args)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AuthClient, useAuth, useSession } from "@better-auth-ui/react"
|
|
2
|
+
import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieve the passkeys registered for the current user.
|
|
6
|
+
*
|
|
7
|
+
* The underlying query is enabled only when session data is available.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Optional React Query options to customize the query behavior.
|
|
10
|
+
* @returns The React Query result for the passkeys list.
|
|
11
|
+
*/
|
|
12
|
+
export function useListUserPasskeys(
|
|
13
|
+
options?: Partial<
|
|
14
|
+
UseAuthQueryOptions<AuthClient["passkey"]["listUserPasskeys"]>
|
|
15
|
+
>
|
|
16
|
+
) {
|
|
17
|
+
const { authClient } = useAuth()
|
|
18
|
+
const { data: session } = useSession({ refetchOnMount: false })
|
|
19
|
+
|
|
20
|
+
return useAuthQuery({
|
|
21
|
+
authFn: authClient.passkey.listUserPasskeys,
|
|
22
|
+
options: {
|
|
23
|
+
queryKey: ["auth", "listUserPasskeys", session?.user.id],
|
|
24
|
+
enabled: !!session,
|
|
25
|
+
...options
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -11,18 +11,22 @@ export * from "./hooks/auth/use-send-verification-email"
|
|
|
11
11
|
export * from "./hooks/auth/use-session"
|
|
12
12
|
export * from "./hooks/auth/use-sign-in-email"
|
|
13
13
|
export * from "./hooks/auth/use-sign-in-magic-link"
|
|
14
|
+
export * from "./hooks/auth/use-sign-in-passkey"
|
|
14
15
|
export * from "./hooks/auth/use-sign-in-social"
|
|
15
16
|
export * from "./hooks/auth/use-sign-out"
|
|
16
17
|
export * from "./hooks/auth/use-sign-up-email"
|
|
17
18
|
export * from "./hooks/auth/use-user"
|
|
18
19
|
export * from "./hooks/settings/use-account-info"
|
|
20
|
+
export * from "./hooks/settings/use-add-passkey"
|
|
19
21
|
export * from "./hooks/settings/use-change-email"
|
|
20
22
|
export * from "./hooks/settings/use-change-password"
|
|
23
|
+
export * from "./hooks/settings/use-delete-passkey"
|
|
21
24
|
export * from "./hooks/settings/use-delete-user"
|
|
22
25
|
export * from "./hooks/settings/use-link-social"
|
|
23
26
|
export * from "./hooks/settings/use-list-accounts"
|
|
24
27
|
export * from "./hooks/settings/use-list-device-sessions"
|
|
25
28
|
export * from "./hooks/settings/use-list-sessions"
|
|
29
|
+
export * from "./hooks/settings/use-list-user-passkeys"
|
|
26
30
|
export * from "./hooks/settings/use-revoke-multi-session"
|
|
27
31
|
export * from "./hooks/settings/use-revoke-session"
|
|
28
32
|
export * from "./hooks/settings/use-set-active-session"
|
package/src/lib/auth-client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { passkeyClient } from "@better-auth/passkey/client"
|
|
1
2
|
import {
|
|
2
3
|
magicLinkClient,
|
|
3
4
|
multiSessionClient,
|
|
@@ -17,7 +18,12 @@ export type { PathToObject } from "better-auth/client"
|
|
|
17
18
|
export type AnyAuthClient = Omit<ReturnType<typeof createAuthClient>, "signUp">
|
|
18
19
|
|
|
19
20
|
const authClient = createAuthClient({
|
|
20
|
-
plugins: [
|
|
21
|
+
plugins: [
|
|
22
|
+
magicLinkClient(),
|
|
23
|
+
multiSessionClient(),
|
|
24
|
+
passkeyClient(),
|
|
25
|
+
usernameClient()
|
|
26
|
+
]
|
|
21
27
|
})
|
|
22
28
|
|
|
23
29
|
/**
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type AuthClient } from "@better-auth-ui/react";
|
|
2
|
-
import type { UseAuthMutationOptions } from "./use-auth-mutation";
|
|
3
|
-
export { useAuthMutation } from "./use-auth-mutation";
|
|
4
|
-
/**
|
|
5
|
-
* Hook that creates a mutation for the forgot-password flow.
|
|
6
|
-
*
|
|
7
|
-
* The mutation sends a password reset request for the submitted email,
|
|
8
|
-
* and navigates to the sign-in view on success.
|
|
9
|
-
*
|
|
10
|
-
* @returns The `useMutation` result.
|
|
11
|
-
*/
|
|
12
|
-
export declare function useRequestPasswordReset(options?: UseAuthMutationOptions<AuthClient["requestPasswordReset"]>): import("@tanstack/react-query").UseMutationResult<any, import("better-auth/react").BetterFetchError, Omit<import("better-auth").Prettify<{
|
|
13
|
-
email: string;
|
|
14
|
-
redirectTo?: string | undefined;
|
|
15
|
-
} & {
|
|
16
|
-
fetchOptions?: import("better-auth").ClientFetchOption<Partial<{
|
|
17
|
-
email: string;
|
|
18
|
-
redirectTo?: string | undefined;
|
|
19
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined> | undefined;
|
|
20
|
-
}>, "fetchOptions">>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useAuth, useAuthMutation } from "@better-auth-ui/react";
|
|
2
|
-
export { useAuthMutation } from "./use-auth-mutation";
|
|
3
|
-
/**
|
|
4
|
-
* Hook that creates a mutation for the forgot-password flow.
|
|
5
|
-
*
|
|
6
|
-
* The mutation sends a password reset request for the submitted email,
|
|
7
|
-
* and navigates to the sign-in view on success.
|
|
8
|
-
*
|
|
9
|
-
* @returns The `useMutation` result.
|
|
10
|
-
*/
|
|
11
|
-
export function useRequestPasswordReset(options) {
|
|
12
|
-
const { authClient } = useAuth();
|
|
13
|
-
return useAuthMutation(authClient.requestPasswordReset, options);
|
|
14
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
/**
|
|
4
|
-
* Indicates whether the current rendering context is hydrated (client-side).
|
|
5
|
-
*
|
|
6
|
-
* @returns `true` when running on the client (hydrated), `false` when rendering on the server
|
|
7
|
-
*/
|
|
8
|
-
export function useHydrated() {
|
|
9
|
-
return useSyncExternalStore(subscribe, () => true, () => false);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Create a subscription handler that does nothing and returns a no-op cleanup.
|
|
13
|
-
*
|
|
14
|
-
* @returns A cleanup function that performs no action when invoked.
|
|
15
|
-
*/
|
|
16
|
-
function subscribe() {
|
|
17
|
-
return () => { };
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|