@better-auth-ui/react 1.6.2 → 1.6.3
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-authenticate.d.ts +30 -6
- package/dist/hooks/auth/use-is-username-available.d.ts +12 -11
- package/dist/hooks/auth/use-is-username-available.js +8 -7
- package/dist/hooks/auth/use-request-password-reset.d.ts +11 -15
- package/dist/hooks/auth/use-request-password-reset.js +8 -7
- package/dist/hooks/auth/use-reset-password.d.ts +13 -29
- package/dist/hooks/auth/use-reset-password.js +8 -7
- package/dist/hooks/auth/use-send-verification-email.d.ts +10 -14
- package/dist/hooks/auth/use-send-verification-email.js +8 -7
- package/dist/hooks/auth/use-session.d.ts +30 -4
- package/dist/hooks/auth/use-session.js +11 -10
- package/dist/hooks/auth/use-sign-in-email.d.ts +11 -37
- package/dist/hooks/auth/use-sign-in-email.js +11 -12
- package/dist/hooks/auth/use-sign-in-magic-link.d.ts +14 -18
- package/dist/hooks/auth/use-sign-in-magic-link.js +8 -7
- package/dist/hooks/auth/use-sign-in-passkey.d.ts +10 -47
- package/dist/hooks/auth/use-sign-in-passkey.js +11 -12
- package/dist/hooks/auth/use-sign-in-social.d.ts +30 -59
- package/dist/hooks/auth/use-sign-in-social.js +8 -7
- package/dist/hooks/auth/use-sign-in-username.d.ts +12 -40
- package/dist/hooks/auth/use-sign-in-username.js +11 -12
- package/dist/hooks/auth/use-sign-out.d.ts +10 -10
- package/dist/hooks/auth/use-sign-out.js +10 -12
- package/dist/hooks/auth/use-sign-up-email.d.ts +18 -101
- package/dist/hooks/auth/use-sign-up-email.js +11 -12
- package/dist/hooks/auth/use-user.d.ts +7 -5
- package/dist/hooks/settings/use-account-info.d.ts +9 -9
- package/dist/hooks/settings/use-account-info.js +13 -16
- package/dist/hooks/settings/use-add-passkey.d.ts +8 -30
- package/dist/hooks/settings/use-add-passkey.js +10 -11
- package/dist/hooks/settings/use-change-email.d.ts +11 -14
- package/dist/hooks/settings/use-change-email.js +11 -12
- package/dist/hooks/settings/use-change-password.d.ts +11 -43
- package/dist/hooks/settings/use-change-password.js +8 -7
- package/dist/hooks/settings/use-delete-passkey.d.ts +10 -12
- package/dist/hooks/settings/use-delete-passkey.js +11 -12
- package/dist/hooks/settings/use-delete-user.d.ts +13 -30
- package/dist/hooks/settings/use-delete-user.js +8 -7
- package/dist/hooks/settings/use-link-social.d.ts +22 -25
- package/dist/hooks/settings/use-link-social.js +8 -7
- package/dist/hooks/settings/use-list-accounts.d.ts +8 -6
- package/dist/hooks/settings/use-list-accounts.js +10 -16
- package/dist/hooks/settings/use-list-device-sessions.d.ts +29 -6
- package/dist/hooks/settings/use-list-device-sessions.js +10 -16
- package/dist/hooks/settings/use-list-sessions.d.ts +8 -5
- package/dist/hooks/settings/use-list-sessions.js +10 -16
- package/dist/hooks/settings/use-list-user-passkeys.d.ts +8 -5
- package/dist/hooks/settings/use-list-user-passkeys.js +10 -16
- package/dist/hooks/settings/use-revoke-multi-session.d.ts +11 -11
- package/dist/hooks/settings/use-revoke-multi-session.js +11 -12
- package/dist/hooks/settings/use-revoke-session.d.ts +11 -11
- package/dist/hooks/settings/use-revoke-session.js +11 -12
- package/dist/hooks/settings/use-set-active-session.d.ts +12 -29
- package/dist/hooks/settings/use-set-active-session.js +12 -13
- package/dist/hooks/settings/use-unlink-account.d.ts +12 -12
- package/dist/hooks/settings/use-unlink-account.js +11 -12
- package/dist/hooks/settings/use-update-user.d.ts +1178 -4
- package/dist/hooks/settings/use-update-user.js +17 -18
- package/dist/hooks/use-auth-mutation.d.ts +12 -0
- package/dist/hooks/use-auth-mutation.js +11 -0
- package/dist/hooks/use-auth-query.d.ts +14 -0
- package/dist/hooks/use-auth-query.js +15 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -33
- package/dist/mutations/auth/is-username-available-options.d.ts +19 -0
- package/dist/mutations/auth/is-username-available-options.js +7 -0
- package/dist/mutations/auth/request-password-reset-options.d.ts +15 -0
- package/dist/mutations/auth/request-password-reset-options.js +7 -0
- package/dist/mutations/auth/reset-password-options.d.ts +17 -0
- package/dist/mutations/auth/reset-password-options.js +7 -0
- package/dist/mutations/auth/send-verification-email-options.d.ts +15 -0
- package/dist/mutations/auth/send-verification-email-options.js +7 -0
- package/dist/mutations/auth/sign-in-email-options.d.ts +23 -0
- package/dist/mutations/auth/sign-in-email-options.js +11 -0
- package/dist/mutations/auth/sign-in-magic-link-options.d.ts +23 -0
- package/dist/mutations/auth/sign-in-magic-link-options.js +11 -0
- package/dist/mutations/auth/sign-in-passkey-options.d.ts +15 -0
- package/dist/mutations/auth/sign-in-passkey-options.js +11 -0
- package/dist/mutations/auth/sign-in-social-options.d.ts +61 -0
- package/dist/mutations/auth/sign-in-social-options.js +11 -0
- package/dist/mutations/auth/sign-in-username-options.d.ts +19 -0
- package/dist/mutations/auth/sign-in-username-options.js +11 -0
- package/dist/mutations/auth/sign-out-options.d.ts +12 -0
- package/dist/mutations/auth/sign-out-options.js +7 -0
- package/dist/mutations/auth/sign-up-email-options.d.ts +1180 -0
- package/dist/mutations/auth/sign-up-email-options.js +11 -0
- package/dist/mutations/auth-mutation-options.d.ts +25 -0
- package/dist/mutations/auth-mutation-options.js +19 -0
- package/dist/mutations/settings/add-passkey-options.d.ts +15 -0
- package/dist/mutations/settings/add-passkey-options.js +11 -0
- package/dist/mutations/settings/change-email-options.d.ts +15 -0
- package/dist/mutations/settings/change-email-options.js +7 -0
- package/dist/mutations/settings/change-password-options.d.ts +17 -0
- package/dist/mutations/settings/change-password-options.js +7 -0
- package/dist/mutations/settings/delete-passkey-options.d.ts +13 -0
- package/dist/mutations/settings/delete-passkey-options.js +11 -0
- package/dist/mutations/settings/delete-user-options.d.ts +20 -0
- package/dist/mutations/settings/delete-user-options.js +7 -0
- package/dist/mutations/settings/link-social-options.d.ts +39 -0
- package/dist/mutations/settings/link-social-options.js +7 -0
- package/dist/mutations/settings/revoke-multi-session-options.d.ts +13 -0
- package/dist/mutations/settings/revoke-multi-session-options.js +11 -0
- package/dist/mutations/settings/revoke-session-options.d.ts +13 -0
- package/dist/mutations/settings/revoke-session-options.js +7 -0
- package/dist/mutations/settings/set-active-session-options.d.ts +13 -0
- package/dist/mutations/settings/set-active-session-options.js +11 -0
- package/dist/mutations/settings/unlink-account-options.d.ts +15 -0
- package/dist/mutations/settings/unlink-account-options.js +7 -0
- package/dist/mutations/settings/update-user-options.d.ts +1182 -0
- package/dist/mutations/settings/update-user-options.js +7 -0
- package/dist/queries/auth/session-options.d.ts +110 -0
- package/dist/queries/auth/session-options.js +7 -0
- package/dist/queries/auth-query-options.d.ts +29 -0
- package/dist/queries/auth-query-options.js +17 -0
- package/dist/queries/settings/account-info-options.d.ts +32 -0
- package/dist/queries/settings/account-info-options.js +12 -0
- package/dist/queries/settings/list-accounts-options.d.ts +53 -0
- package/dist/queries/settings/list-accounts-options.js +12 -0
- package/dist/queries/settings/list-device-sessions-options.d.ts +99 -0
- package/dist/queries/settings/list-device-sessions-options.js +12 -0
- package/dist/queries/settings/list-sessions-options.d.ts +54 -0
- package/dist/queries/settings/list-sessions-options.js +12 -0
- package/dist/queries/settings/list-user-passkeys-options.d.ts +18 -0
- package/dist/queries/settings/list-user-passkeys-options.js +12 -0
- package/package.json +1 -1
- package/src/hooks/auth/use-authenticate.ts +7 -10
- package/src/hooks/auth/use-is-username-available.ts +17 -8
- package/src/hooks/auth/use-request-password-reset.ts +19 -8
- package/src/hooks/auth/use-reset-password.ts +19 -9
- package/src/hooks/auth/use-send-verification-email.ts +18 -8
- package/src/hooks/auth/use-session.ts +20 -16
- package/src/hooks/auth/use-sign-in-email.ts +23 -16
- package/src/hooks/auth/use-sign-in-magic-link.ts +18 -10
- package/src/hooks/auth/use-sign-in-passkey.ts +24 -18
- package/src/hooks/auth/use-sign-in-social.ts +18 -8
- package/src/hooks/auth/use-sign-in-username.ts +24 -18
- package/src/hooks/auth/use-sign-out.ts +18 -17
- package/src/hooks/auth/use-sign-up-email.ts +24 -18
- package/src/hooks/auth/use-user.ts +7 -8
- package/src/hooks/settings/use-account-info.ts +29 -20
- package/src/hooks/settings/use-add-passkey.ts +22 -17
- package/src/hooks/settings/use-change-email.ts +21 -17
- package/src/hooks/settings/use-change-password.ts +18 -8
- package/src/hooks/settings/use-delete-passkey.ts +21 -16
- package/src/hooks/settings/use-delete-user.ts +18 -8
- package/src/hooks/settings/use-link-social.ts +18 -8
- package/src/hooks/settings/use-list-accounts.ts +25 -15
- package/src/hooks/settings/use-list-device-sessions.ts +26 -21
- package/src/hooks/settings/use-list-sessions.ts +25 -14
- package/src/hooks/settings/use-list-user-passkeys.ts +25 -16
- package/src/hooks/settings/use-revoke-multi-session.ts +25 -16
- package/src/hooks/settings/use-revoke-session.ts +25 -16
- package/src/hooks/settings/use-set-active-session.ts +35 -24
- package/src/hooks/settings/use-unlink-account.ts +22 -15
- package/src/hooks/settings/use-update-user.ts +29 -22
- package/src/hooks/use-auth-mutation.ts +29 -0
- package/src/hooks/use-auth-query.ts +36 -0
- package/src/index.ts +2 -2
- package/src/mutations/auth/is-username-available-options.ts +18 -0
- package/src/mutations/auth/request-password-reset-options.ts +14 -0
- package/src/mutations/auth/reset-password-options.ts +14 -0
- package/src/mutations/auth/send-verification-email-options.ts +14 -0
- package/src/mutations/auth/sign-in-email-options.ts +19 -0
- package/src/mutations/auth/sign-in-magic-link-options.ts +15 -0
- package/src/mutations/auth/sign-in-passkey-options.ts +15 -0
- package/src/mutations/auth/sign-in-social-options.ts +19 -0
- package/src/mutations/auth/sign-in-username-options.ts +15 -0
- package/src/mutations/auth/sign-out-options.ts +11 -0
- package/src/mutations/auth/sign-up-email-options.ts +15 -0
- package/src/mutations/auth-mutation-options.ts +49 -0
- package/src/mutations/settings/add-passkey-options.ts +15 -0
- package/src/mutations/settings/change-email-options.ts +11 -0
- package/src/mutations/settings/change-password-options.ts +14 -0
- package/src/mutations/settings/delete-passkey-options.ts +15 -0
- package/src/mutations/settings/delete-user-options.ts +11 -0
- package/src/mutations/settings/link-social-options.ts +11 -0
- package/src/mutations/settings/revoke-multi-session-options.ts +15 -0
- package/src/mutations/settings/revoke-session-options.ts +14 -0
- package/src/mutations/settings/set-active-session-options.ts +15 -0
- package/src/mutations/settings/unlink-account-options.ts +14 -0
- package/src/mutations/settings/update-user-options.ts +15 -0
- package/src/queries/auth/session-options.ts +18 -0
- package/src/queries/auth-query-options.ts +34 -0
- package/src/queries/settings/account-info-options.ts +25 -0
- package/src/queries/settings/list-accounts-options.ts +26 -0
- package/src/queries/settings/list-device-sessions-options.ts +24 -0
- package/src/queries/settings/list-sessions-options.ts +23 -0
- package/src/queries/settings/list-user-passkeys-options.ts +23 -0
- package/dist/hooks/auth/use-auth-mutation.d.ts +0 -18
- package/dist/hooks/auth/use-auth-mutation.js +0 -13
- package/dist/hooks/auth/use-auth-query.d.ts +0 -24
- package/dist/hooks/auth/use-auth-query.js +0 -13
- package/src/hooks/auth/use-auth-mutation.ts +0 -56
- package/src/hooks/auth/use-auth-query.ts +0 -50
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
2
|
+
|
|
1
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { changePasswordOptions } from "../../mutations/settings/change-password-options"
|
|
6
|
+
|
|
7
|
+
export type UseChangePasswordParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["changePassword"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseChangePasswordOptions = Omit<
|
|
12
|
+
ReturnType<typeof changePasswordOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Hook that creates a mutation for changing the authenticated user's password.
|
|
10
18
|
*
|
|
19
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
11
20
|
* @returns The `useMutation` result.
|
|
12
21
|
*/
|
|
13
|
-
export function useChangePassword(
|
|
14
|
-
options?: UseAuthMutationOptions<AuthClient["changePassword"]>
|
|
15
|
-
) {
|
|
22
|
+
export function useChangePassword(options?: UseChangePasswordOptions) {
|
|
16
23
|
const { authClient } = useAuth()
|
|
17
24
|
|
|
18
|
-
return
|
|
25
|
+
return useMutation({
|
|
26
|
+
...changePasswordOptions(authClient),
|
|
27
|
+
...options
|
|
28
|
+
})
|
|
19
29
|
}
|
|
@@ -1,32 +1,37 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
2
|
+
|
|
1
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
type UseAuthMutationOptions,
|
|
5
|
-
useAuthMutation
|
|
6
|
-
} from "../auth/use-auth-mutation"
|
|
5
|
+
import { deletePasskeyOptions } from "../../mutations/settings/delete-passkey-options"
|
|
7
6
|
import { useListUserPasskeys } from "./use-list-user-passkeys"
|
|
8
7
|
|
|
8
|
+
export type UseDeletePasskeyParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["passkey"]["deletePasskey"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseDeletePasskeyOptions = Omit<
|
|
13
|
+
ReturnType<typeof deletePasskeyOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* Hook that creates a mutation for deleting a passkey.
|
|
11
19
|
*
|
|
12
|
-
* Refetches the
|
|
20
|
+
* Refetches the user's passkey list on success.
|
|
13
21
|
*
|
|
22
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
14
23
|
* @returns The `useMutation` result.
|
|
15
24
|
*/
|
|
16
|
-
export function useDeletePasskey(
|
|
17
|
-
options?: UseAuthMutationOptions<AuthClient["passkey"]["deletePasskey"]>
|
|
18
|
-
) {
|
|
25
|
+
export function useDeletePasskey(options?: UseDeletePasskeyOptions) {
|
|
19
26
|
const { authClient } = useAuth()
|
|
20
27
|
const { refetch } = useListUserPasskeys()
|
|
21
28
|
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
options
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await options?.onSuccess?.(...args)
|
|
29
|
-
}
|
|
29
|
+
return useMutation({
|
|
30
|
+
...deletePasskeyOptions(authClient),
|
|
31
|
+
...options,
|
|
32
|
+
onSuccess: async (...args) => {
|
|
33
|
+
await refetch()
|
|
34
|
+
await options?.onSuccess?.(...args)
|
|
30
35
|
}
|
|
31
36
|
})
|
|
32
37
|
}
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
2
|
+
|
|
1
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { deleteUserOptions } from "../../mutations/settings/delete-user-options"
|
|
6
|
+
|
|
7
|
+
export type UseDeleteUserParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["deleteUser"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseDeleteUserOptions = Omit<
|
|
12
|
+
ReturnType<typeof deleteUserOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Hook that creates a mutation for deleting the authenticated user account.
|
|
10
18
|
*
|
|
19
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
11
20
|
* @returns The `useMutation` result.
|
|
12
21
|
*/
|
|
13
|
-
export function useDeleteUser(
|
|
14
|
-
options?: UseAuthMutationOptions<AuthClient["deleteUser"]>
|
|
15
|
-
) {
|
|
22
|
+
export function useDeleteUser(options?: UseDeleteUserOptions) {
|
|
16
23
|
const { authClient } = useAuth()
|
|
17
24
|
|
|
18
|
-
return
|
|
25
|
+
return useMutation({
|
|
26
|
+
...deleteUserOptions(authClient),
|
|
27
|
+
...options
|
|
28
|
+
})
|
|
19
29
|
}
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
2
|
+
|
|
1
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { linkSocialOptions } from "../../mutations/settings/link-social-options"
|
|
6
|
+
|
|
7
|
+
export type UseLinkSocialParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["linkSocial"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseLinkSocialOptions = Omit<
|
|
12
|
+
ReturnType<typeof linkSocialOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Hook that creates a mutation for linking a social provider to the current user.
|
|
10
18
|
*
|
|
19
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
11
20
|
* @returns The `useMutation` result.
|
|
12
21
|
*/
|
|
13
|
-
export function useLinkSocial(
|
|
14
|
-
options?: UseAuthMutationOptions<AuthClient["linkSocial"]>
|
|
15
|
-
) {
|
|
22
|
+
export function useLinkSocial(options?: UseLinkSocialOptions) {
|
|
16
23
|
const { authClient } = useAuth()
|
|
17
24
|
|
|
18
|
-
return
|
|
25
|
+
return useMutation({
|
|
26
|
+
...linkSocialOptions(authClient),
|
|
27
|
+
...options
|
|
28
|
+
})
|
|
19
29
|
}
|
|
@@ -1,29 +1,39 @@
|
|
|
1
|
+
import { skipToken, useQuery } from "@tanstack/react-query"
|
|
1
2
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
3
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
+
import { listAccountsOptions } from "../../queries/settings/list-accounts-options"
|
|
4
5
|
import { useSession } from "../auth/use-session"
|
|
5
6
|
|
|
7
|
+
export type UseListAccountsParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["listAccounts"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseListAccountsOptions = Omit<
|
|
12
|
+
ReturnType<typeof listAccountsOptions>,
|
|
13
|
+
"queryKey" | "queryFn"
|
|
14
|
+
> &
|
|
15
|
+
UseListAccountsParams
|
|
16
|
+
|
|
6
17
|
/**
|
|
7
18
|
* Retrieve the current user's linked social accounts.
|
|
8
19
|
*
|
|
9
|
-
*
|
|
10
|
-
* The provided `options` are forwarded to both `useSession` and `useQuery`, allowing customization of initial data and query behavior.
|
|
20
|
+
* Keyed per-user; waits for the active session before firing.
|
|
11
21
|
*
|
|
12
|
-
* @param options -
|
|
13
|
-
*
|
|
22
|
+
* @param options - Better Auth params (`fetchOptions`) and React Query
|
|
23
|
+
* options forwarded to `useQuery`.
|
|
24
|
+
* @returns React Query result for the user's linked accounts.
|
|
14
25
|
*/
|
|
15
|
-
export function useListAccounts(
|
|
16
|
-
options?: Partial<UseAuthQueryOptions<AuthClient["listAccounts"]>>
|
|
17
|
-
) {
|
|
26
|
+
export function useListAccounts(options?: UseListAccountsOptions) {
|
|
18
27
|
const { authClient } = useAuth()
|
|
19
28
|
const { data: session } = useSession({ refetchOnMount: false })
|
|
29
|
+
const userId = session?.user.id
|
|
30
|
+
const disabled = !userId
|
|
31
|
+
|
|
32
|
+
const { fetchOptions, ...queryOptions } = options ?? {}
|
|
20
33
|
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
enabled: !!session,
|
|
26
|
-
...options
|
|
27
|
-
}
|
|
34
|
+
return useQuery({
|
|
35
|
+
...listAccountsOptions(authClient, userId, { fetchOptions }),
|
|
36
|
+
...(disabled && { queryFn: skipToken }),
|
|
37
|
+
...queryOptions
|
|
28
38
|
})
|
|
29
39
|
}
|
|
@@ -1,34 +1,39 @@
|
|
|
1
|
+
import { skipToken, useQuery } from "@tanstack/react-query"
|
|
1
2
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
3
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
type UseAuthQueryOptions,
|
|
5
|
-
type UseAuthQueryResult,
|
|
6
|
-
useAuthQuery
|
|
7
|
-
} from "../auth/use-auth-query"
|
|
4
|
+
import { listDeviceSessionsOptions } from "../../queries/settings/list-device-sessions-options"
|
|
8
5
|
import { useSession } from "../auth/use-session"
|
|
9
6
|
|
|
7
|
+
export type UseListDeviceSessionsParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["multiSession"]["listDeviceSessions"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseListDeviceSessionsOptions = Omit<
|
|
12
|
+
ReturnType<typeof listDeviceSessionsOptions>,
|
|
13
|
+
"queryKey" | "queryFn"
|
|
14
|
+
> &
|
|
15
|
+
UseListDeviceSessionsParams
|
|
16
|
+
|
|
10
17
|
/**
|
|
11
|
-
* Retrieve device sessions
|
|
18
|
+
* Retrieve the device sessions (multi-session account switcher).
|
|
12
19
|
*
|
|
13
|
-
*
|
|
20
|
+
* Keyed per-user; waits for the active session before firing.
|
|
14
21
|
*
|
|
15
|
-
* @param options -
|
|
16
|
-
*
|
|
22
|
+
* @param options - Better Auth params (`fetchOptions`) and React Query
|
|
23
|
+
* options forwarded to `useQuery`.
|
|
24
|
+
* @returns React Query result for the device sessions list.
|
|
17
25
|
*/
|
|
18
|
-
export function useListDeviceSessions(
|
|
19
|
-
options?: Partial<
|
|
20
|
-
UseAuthQueryOptions<AuthClient["multiSession"]["listDeviceSessions"]>
|
|
21
|
-
>
|
|
22
|
-
): UseAuthQueryResult<AuthClient["multiSession"]["listDeviceSessions"]> {
|
|
26
|
+
export function useListDeviceSessions(options?: UseListDeviceSessionsOptions) {
|
|
23
27
|
const { authClient } = useAuth()
|
|
24
28
|
const { data: session } = useSession({ refetchOnMount: false })
|
|
29
|
+
const userId = session?.user.id
|
|
30
|
+
const disabled = !userId
|
|
31
|
+
|
|
32
|
+
const { fetchOptions, ...queryOptions } = options ?? {}
|
|
25
33
|
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
enabled: !!session,
|
|
31
|
-
...options
|
|
32
|
-
}
|
|
34
|
+
return useQuery({
|
|
35
|
+
...listDeviceSessionsOptions(authClient, userId, { fetchOptions }),
|
|
36
|
+
...(disabled && { queryFn: skipToken }),
|
|
37
|
+
...queryOptions
|
|
33
38
|
})
|
|
34
39
|
}
|
|
@@ -1,28 +1,39 @@
|
|
|
1
|
+
import { skipToken, useQuery } from "@tanstack/react-query"
|
|
1
2
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
3
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
+
import { listSessionsOptions } from "../../queries/settings/list-sessions-options"
|
|
4
5
|
import { useSession } from "../auth/use-session"
|
|
5
6
|
|
|
7
|
+
export type UseListSessionsParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["listSessions"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseListSessionsOptions = Omit<
|
|
12
|
+
ReturnType<typeof listSessionsOptions>,
|
|
13
|
+
"queryKey" | "queryFn"
|
|
14
|
+
> &
|
|
15
|
+
UseListSessionsParams
|
|
16
|
+
|
|
6
17
|
/**
|
|
7
18
|
* Retrieve the active sessions (devices where the current user is signed in).
|
|
8
19
|
*
|
|
9
|
-
*
|
|
20
|
+
* Keyed per-user; waits for the active session before firing.
|
|
10
21
|
*
|
|
11
|
-
* @param options -
|
|
12
|
-
*
|
|
22
|
+
* @param options - Better Auth params (`fetchOptions`) and React Query
|
|
23
|
+
* options forwarded to `useQuery`.
|
|
24
|
+
* @returns React Query result for the sessions list.
|
|
13
25
|
*/
|
|
14
|
-
export function useListSessions(
|
|
15
|
-
options?: Partial<UseAuthQueryOptions<AuthClient["listSessions"]>>
|
|
16
|
-
) {
|
|
26
|
+
export function useListSessions(options?: UseListSessionsOptions) {
|
|
17
27
|
const { authClient } = useAuth()
|
|
18
28
|
const { data: session } = useSession({ refetchOnMount: false })
|
|
29
|
+
const userId = session?.user.id
|
|
30
|
+
const disabled = !userId
|
|
31
|
+
|
|
32
|
+
const { fetchOptions, ...queryOptions } = options ?? {}
|
|
19
33
|
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
enabled: !!session,
|
|
25
|
-
...options
|
|
26
|
-
}
|
|
34
|
+
return useQuery({
|
|
35
|
+
...listSessionsOptions(authClient, userId, { fetchOptions }),
|
|
36
|
+
...(disabled && { queryFn: skipToken }),
|
|
37
|
+
...queryOptions
|
|
27
38
|
})
|
|
28
39
|
}
|
|
@@ -1,30 +1,39 @@
|
|
|
1
|
+
import { skipToken, useQuery } from "@tanstack/react-query"
|
|
1
2
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
3
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
+
import { listUserPasskeysOptions } from "../../queries/settings/list-user-passkeys-options"
|
|
4
5
|
import { useSession } from "../auth/use-session"
|
|
5
6
|
|
|
7
|
+
export type UseListUserPasskeysParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["passkey"]["listUserPasskeys"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseListUserPasskeysOptions = Omit<
|
|
12
|
+
ReturnType<typeof listUserPasskeysOptions>,
|
|
13
|
+
"queryKey" | "queryFn"
|
|
14
|
+
> &
|
|
15
|
+
UseListUserPasskeysParams
|
|
16
|
+
|
|
6
17
|
/**
|
|
7
18
|
* Retrieve the passkeys registered for the current user.
|
|
8
19
|
*
|
|
9
|
-
*
|
|
20
|
+
* Keyed per-user; waits for the active session before firing.
|
|
10
21
|
*
|
|
11
|
-
* @param options -
|
|
12
|
-
*
|
|
22
|
+
* @param options - Better Auth params (`fetchOptions`) and React Query
|
|
23
|
+
* options forwarded to `useQuery`.
|
|
24
|
+
* @returns React Query result for the passkeys list.
|
|
13
25
|
*/
|
|
14
|
-
export function useListUserPasskeys(
|
|
15
|
-
options?: Partial<
|
|
16
|
-
UseAuthQueryOptions<AuthClient["passkey"]["listUserPasskeys"]>
|
|
17
|
-
>
|
|
18
|
-
) {
|
|
26
|
+
export function useListUserPasskeys(options?: UseListUserPasskeysOptions) {
|
|
19
27
|
const { authClient } = useAuth()
|
|
20
28
|
const { data: session } = useSession({ refetchOnMount: false })
|
|
29
|
+
const userId = session?.user.id
|
|
30
|
+
const disabled = !userId
|
|
31
|
+
|
|
32
|
+
const { fetchOptions, ...queryOptions } = options ?? {}
|
|
21
33
|
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
enabled: !!session,
|
|
27
|
-
...options
|
|
28
|
-
}
|
|
34
|
+
return useQuery({
|
|
35
|
+
...listUserPasskeysOptions(authClient, userId, { fetchOptions }),
|
|
36
|
+
...(disabled && { queryFn: skipToken }),
|
|
37
|
+
...queryOptions
|
|
29
38
|
})
|
|
30
39
|
}
|
|
@@ -1,30 +1,39 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
2
|
+
|
|
1
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
type UseAuthMutationOptions,
|
|
5
|
-
useAuthMutation
|
|
6
|
-
} from "../auth/use-auth-mutation"
|
|
5
|
+
import { revokeMultiSessionOptions } from "../../mutations/settings/revoke-multi-session-options"
|
|
7
6
|
import { useListDeviceSessions } from "./use-list-device-sessions"
|
|
8
7
|
|
|
8
|
+
export type UseRevokeMultiSessionParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["multiSession"]["revoke"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseRevokeMultiSessionOptions = Omit<
|
|
13
|
+
ReturnType<typeof revokeMultiSessionOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* Hook that creates a mutation for revoking a device session in multi-session mode.
|
|
11
19
|
*
|
|
20
|
+
* Refetches the device sessions list on success.
|
|
21
|
+
*
|
|
22
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
12
23
|
* @returns The `useMutation` result.
|
|
13
24
|
*/
|
|
14
|
-
export function useRevokeMultiSession(
|
|
15
|
-
options?: UseAuthMutationOptions<AuthClient["multiSession"]["revoke"]>
|
|
16
|
-
) {
|
|
25
|
+
export function useRevokeMultiSession(options?: UseRevokeMultiSessionOptions) {
|
|
17
26
|
const { authClient } = useAuth()
|
|
18
|
-
const { refetch } = useListDeviceSessions({
|
|
27
|
+
const { refetch } = useListDeviceSessions({
|
|
28
|
+
refetchOnMount: false
|
|
29
|
+
})
|
|
19
30
|
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
options
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
await options?.onSuccess?.(...args)
|
|
27
|
-
}
|
|
31
|
+
return useMutation({
|
|
32
|
+
...revokeMultiSessionOptions(authClient),
|
|
33
|
+
...options,
|
|
34
|
+
onSuccess: async (...args) => {
|
|
35
|
+
await refetch()
|
|
36
|
+
await options?.onSuccess?.(...args)
|
|
28
37
|
}
|
|
29
38
|
})
|
|
30
39
|
}
|
|
@@ -1,30 +1,39 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
2
|
+
|
|
1
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
type UseAuthMutationOptions,
|
|
5
|
-
useAuthMutation
|
|
6
|
-
} from "../auth/use-auth-mutation"
|
|
5
|
+
import { revokeSessionOptions } from "../../mutations/settings/revoke-session-options"
|
|
7
6
|
import { useListSessions } from "./use-list-sessions"
|
|
8
7
|
|
|
8
|
+
export type UseRevokeSessionParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["revokeSession"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseRevokeSessionOptions = Omit<
|
|
13
|
+
ReturnType<typeof revokeSessionOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* Hook that creates a mutation for revoking a user session.
|
|
11
19
|
*
|
|
20
|
+
* Refetches the sessions list on success.
|
|
21
|
+
*
|
|
22
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
12
23
|
* @returns The `useMutation` result.
|
|
13
24
|
*/
|
|
14
|
-
export function useRevokeSession(
|
|
15
|
-
options?: UseAuthMutationOptions<AuthClient["revokeSession"]>
|
|
16
|
-
) {
|
|
25
|
+
export function useRevokeSession(options?: UseRevokeSessionOptions) {
|
|
17
26
|
const { authClient } = useAuth()
|
|
18
|
-
const { refetch } = useListSessions({
|
|
27
|
+
const { refetch: refetchSessions } = useListSessions({
|
|
28
|
+
refetchOnMount: false
|
|
29
|
+
})
|
|
19
30
|
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
options
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
await options?.onSuccess?.(...args)
|
|
27
|
-
}
|
|
31
|
+
return useMutation({
|
|
32
|
+
...revokeSessionOptions(authClient),
|
|
33
|
+
...options,
|
|
34
|
+
onSuccess: async (...args) => {
|
|
35
|
+
await refetchSessions()
|
|
36
|
+
await options?.onSuccess?.(...args)
|
|
28
37
|
}
|
|
29
38
|
})
|
|
30
39
|
}
|
|
@@ -1,47 +1,58 @@
|
|
|
1
|
-
import { useQueryClient } from "@tanstack/react-query"
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
2
2
|
|
|
3
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
useAuthMutation
|
|
8
|
-
} from "../auth/use-auth-mutation"
|
|
5
|
+
import { setActiveSessionOptions } from "../../mutations/settings/set-active-session-options"
|
|
6
|
+
import { sessionOptions } from "../../queries/auth/session-options"
|
|
9
7
|
import { useSession } from "../auth/use-session"
|
|
10
8
|
import { useListDeviceSessions } from "./use-list-device-sessions"
|
|
11
9
|
|
|
10
|
+
export type UseSetActiveSessionParams = NonNullable<
|
|
11
|
+
Parameters<AuthClient["multiSession"]["setActive"]>[0]
|
|
12
|
+
>
|
|
13
|
+
|
|
14
|
+
export type UseSetActiveSessionOptions = Omit<
|
|
15
|
+
ReturnType<typeof setActiveSessionOptions>,
|
|
16
|
+
"mutationKey" | "mutationFn"
|
|
17
|
+
>
|
|
18
|
+
|
|
12
19
|
/**
|
|
13
20
|
* Hook that sets an active device session in multi-session mode.
|
|
14
21
|
*
|
|
22
|
+
* Optimistically switches the cached session to the matching device session,
|
|
23
|
+
* scrolls to top, and refetches both the session and device-session queries.
|
|
24
|
+
*
|
|
25
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
15
26
|
* @returns The `useMutation` result.
|
|
16
27
|
*/
|
|
17
|
-
export function useSetActiveSession(
|
|
18
|
-
options?: UseAuthMutationOptions<AuthClient["multiSession"]["setActive"]>
|
|
19
|
-
) {
|
|
28
|
+
export function useSetActiveSession(options?: UseSetActiveSessionOptions) {
|
|
20
29
|
const queryClient = useQueryClient()
|
|
21
30
|
const { authClient } = useAuth()
|
|
22
|
-
|
|
23
31
|
const { refetch: refetchSession } = useSession({ refetchOnMount: false })
|
|
24
32
|
const { data: deviceSessions, refetch: refetchDeviceSessions } =
|
|
25
33
|
useListDeviceSessions({ refetchOnMount: false })
|
|
26
34
|
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
options
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
return useMutation({
|
|
36
|
+
...setActiveSessionOptions(authClient),
|
|
37
|
+
...options,
|
|
38
|
+
onSuccess: async (data, variables, ...rest) => {
|
|
39
|
+
const sessionToken = variables?.sessionToken
|
|
40
|
+
const deviceSession = deviceSessions?.find(
|
|
41
|
+
(session) => session.session.token === sessionToken
|
|
42
|
+
)
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
if (deviceSession) {
|
|
45
|
+
queryClient.setQueryData(
|
|
46
|
+
sessionOptions(authClient).queryKey,
|
|
47
|
+
deviceSession
|
|
48
|
+
)
|
|
49
|
+
}
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
window.scrollTo({ top: 0 })
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
53
|
+
await refetchSession()
|
|
54
|
+
await refetchDeviceSessions()
|
|
55
|
+
await options?.onSuccess?.(data, variables, ...rest)
|
|
45
56
|
}
|
|
46
57
|
})
|
|
47
58
|
}
|
|
@@ -1,30 +1,37 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
2
|
+
|
|
1
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
2
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
-
import {
|
|
4
|
-
type UseAuthMutationOptions,
|
|
5
|
-
useAuthMutation
|
|
6
|
-
} from "../auth/use-auth-mutation"
|
|
5
|
+
import { unlinkAccountOptions } from "../../mutations/settings/unlink-account-options"
|
|
7
6
|
import { useListAccounts } from "./use-list-accounts"
|
|
8
7
|
|
|
8
|
+
export type UseUnlinkAccountParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["unlinkAccount"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseUnlinkAccountOptions = Omit<
|
|
13
|
+
ReturnType<typeof unlinkAccountOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* Hook that creates a mutation for unlinking a social provider from the current user.
|
|
11
19
|
*
|
|
20
|
+
* Refetches the linked accounts list on success.
|
|
21
|
+
*
|
|
22
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
12
23
|
* @returns The `useMutation` result.
|
|
13
24
|
*/
|
|
14
|
-
export function useUnlinkAccount(
|
|
15
|
-
options?: UseAuthMutationOptions<AuthClient["unlinkAccount"]>
|
|
16
|
-
) {
|
|
25
|
+
export function useUnlinkAccount(options?: UseUnlinkAccountOptions) {
|
|
17
26
|
const { authClient } = useAuth()
|
|
18
27
|
const { refetch } = useListAccounts({ refetchOnMount: false })
|
|
19
28
|
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
options
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
await options?.onSuccess?.(...args)
|
|
27
|
-
}
|
|
29
|
+
return useMutation({
|
|
30
|
+
...unlinkAccountOptions(authClient),
|
|
31
|
+
...options,
|
|
32
|
+
onSuccess: async (...args) => {
|
|
33
|
+
await refetch()
|
|
34
|
+
await options?.onSuccess?.(...args)
|
|
28
35
|
}
|
|
29
36
|
})
|
|
30
37
|
}
|