@better-auth-ui/react 1.6.8 → 1.6.9
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/components/auth/auth-context.d.ts +3 -0
- package/dist/components/auth/auth-context.js +4 -0
- package/dist/components/auth/auth-provider.d.ts +4 -4
- package/dist/components/auth/auth-provider.js +65 -41
- package/dist/components/auth/email/email-changed.d.ts +2 -2
- package/dist/components/auth/email/email-changed.js +68 -154
- package/dist/components/auth/email/email-localization.d.ts +11 -3
- package/dist/components/auth/email/email-localization.js +25 -18
- package/dist/components/auth/email/email-styles.js +77 -52
- package/dist/components/auth/email/email-verification.d.ts +2 -2
- package/dist/components/auth/email/email-verification.js +73 -138
- package/dist/components/auth/email/index.d.ts +10 -9
- package/dist/components/auth/email/index.js +10 -9
- package/dist/components/auth/email/magic-link.d.ts +2 -2
- package/dist/components/auth/email/magic-link.js +70 -139
- package/dist/components/auth/email/new-device.d.ts +2 -2
- package/dist/components/auth/email/new-device.js +88 -221
- package/dist/components/auth/email/organization-invitation.d.ts +121 -0
- package/dist/components/auth/email/organization-invitation.js +110 -0
- package/dist/components/auth/email/otp-email.d.ts +2 -2
- package/dist/components/auth/email/otp-email.js +63 -127
- package/dist/components/auth/email/password-changed.d.ts +2 -2
- package/dist/components/auth/email/password-changed.js +74 -157
- package/dist/components/auth/email/reset-password.d.ts +2 -2
- package/dist/components/auth/email/reset-password.js +66 -138
- package/dist/components/auth/fetch-options-provider.d.ts +1 -1
- package/dist/components/auth/fetch-options-provider.js +28 -27
- package/dist/components/icons/apple.d.ts +1 -1
- package/dist/components/icons/apple.js +9 -16
- package/dist/components/icons/atlassian.d.ts +1 -1
- package/dist/components/icons/atlassian.js +13 -38
- package/dist/components/icons/cognito.d.ts +1 -1
- package/dist/components/icons/cognito.js +9 -19
- package/dist/components/icons/discord.d.ts +1 -1
- package/dist/components/icons/discord.js +9 -16
- package/dist/components/icons/dropbox.d.ts +1 -1
- package/dist/components/icons/dropbox.js +9 -16
- package/dist/components/icons/facebook.d.ts +1 -1
- package/dist/components/icons/facebook.js +11 -19
- package/dist/components/icons/figma.d.ts +1 -1
- package/dist/components/icons/figma.js +12 -34
- package/dist/components/icons/github.d.ts +1 -1
- package/dist/components/icons/github.js +11 -16
- package/dist/components/icons/gitlab.d.ts +1 -1
- package/dist/components/icons/gitlab.js +9 -30
- package/dist/components/icons/google.d.ts +1 -1
- package/dist/components/icons/google.js +9 -39
- package/dist/components/icons/huggingface.d.ts +1 -1
- package/dist/components/icons/huggingface.js +9 -38
- package/dist/components/icons/index.d.ts +35 -35
- package/dist/components/icons/index.js +35 -35
- package/dist/components/icons/kakao.d.ts +1 -1
- package/dist/components/icons/kakao.js +11 -16
- package/dist/components/icons/kick.d.ts +1 -1
- package/dist/components/icons/kick.js +11 -20
- package/dist/components/icons/line.d.ts +1 -1
- package/dist/components/icons/line.js +9 -16
- package/dist/components/icons/linear.d.ts +1 -1
- package/dist/components/icons/linear.js +9 -16
- package/dist/components/icons/linkedin.d.ts +1 -1
- package/dist/components/icons/linkedin.js +9 -33
- package/dist/components/icons/microsoft.d.ts +1 -1
- package/dist/components/icons/microsoft.js +9 -30
- package/dist/components/icons/naver.d.ts +1 -1
- package/dist/components/icons/naver.js +9 -16
- package/dist/components/icons/notion.d.ts +1 -1
- package/dist/components/icons/notion.js +9 -16
- package/dist/components/icons/paybin.d.ts +1 -1
- package/dist/components/icons/paybin.js +8 -32
- package/dist/components/icons/paypal.d.ts +1 -1
- package/dist/components/icons/paypal.js +9 -30
- package/dist/components/icons/polar.d.ts +1 -1
- package/dist/components/icons/polar.js +9 -24
- package/dist/components/icons/railway.d.ts +1 -1
- package/dist/components/icons/railway.js +9 -16
- package/dist/components/icons/reddit.d.ts +1 -1
- package/dist/components/icons/reddit.js +9 -21
- package/dist/components/icons/roblox.d.ts +1 -1
- package/dist/components/icons/roblox.js +12 -17
- package/dist/components/icons/salesforce.d.ts +1 -1
- package/dist/components/icons/salesforce.js +9 -16
- package/dist/components/icons/slack.d.ts +1 -1
- package/dist/components/icons/slack.js +9 -30
- package/dist/components/icons/spotify.d.ts +1 -1
- package/dist/components/icons/spotify.js +9 -16
- package/dist/components/icons/tiktok.d.ts +1 -1
- package/dist/components/icons/tiktok.js +10 -23
- package/dist/components/icons/twitch.d.ts +1 -1
- package/dist/components/icons/twitch.js +12 -43
- package/dist/components/icons/vercel.d.ts +1 -1
- package/dist/components/icons/vercel.js +9 -16
- package/dist/components/icons/vk.d.ts +1 -1
- package/dist/components/icons/vk.js +9 -16
- package/dist/components/icons/wechat.d.ts +1 -1
- package/dist/components/icons/wechat.js +9 -16
- package/dist/components/icons/x.d.ts +1 -1
- package/dist/components/icons/x.js +9 -16
- package/dist/components/icons/zoom.d.ts +1 -1
- package/dist/components/icons/zoom.js +11 -69
- package/dist/components/mutation-invalidator.d.ts +1 -0
- package/dist/components/mutation-invalidator.js +31 -0
- package/dist/components/settings/account/theme-preview.js +7 -286
- package/dist/email.d.ts +1 -1
- package/dist/email.js +1 -11
- package/dist/hooks/auth/use-authenticate.d.ts +3 -3
- package/dist/hooks/auth/use-authenticate.js +28 -22
- package/dist/hooks/auth/use-user.d.ts +34 -34
- package/dist/hooks/auth/use-user.js +14 -10
- package/dist/hooks/use-auth-mutation.d.ts +4 -4
- package/dist/hooks/use-auth-mutation.js +18 -10
- package/dist/hooks/use-auth-plugin.d.ts +1 -1
- package/dist/hooks/use-auth-plugin.js +26 -8
- package/dist/hooks/use-auth-query.d.ts +3 -3
- package/dist/hooks/use-auth-query.js +20 -14
- package/dist/index.d.ts +48 -45
- package/dist/index.js +47 -79
- package/dist/lib/auth-client.d.ts +7 -4
- package/dist/lib/auth-client.js +1 -0
- package/dist/lib/auth-plugin.d.ts +19 -3
- package/dist/lib/auth-plugin.js +1 -0
- package/dist/lib/auth-server.d.ts +10 -3
- package/dist/lib/auth-server.js +1 -0
- package/dist/lib/provider-icons.d.ts +2 -2
- package/dist/lib/provider-icons.js +47 -75
- package/dist/lib/settings-tab.d.ts +19 -0
- package/dist/lib/settings-tab.js +1 -0
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +4 -7
- package/dist/mutations/api-key/create-api-key-mutation.d.ts +9 -7
- package/dist/mutations/api-key/create-api-key-mutation.js +37 -27
- package/dist/mutations/api-key/delete-api-key-mutation.d.ts +10 -6
- package/dist/mutations/api-key/delete-api-key-mutation.js +37 -27
- package/dist/mutations/auth/request-password-reset-mutation.d.ts +4 -4
- package/dist/mutations/auth/request-password-reset-mutation.js +31 -22
- package/dist/mutations/auth/reset-password-mutation.d.ts +4 -4
- package/dist/mutations/auth/reset-password-mutation.js +32 -22
- package/dist/mutations/auth/send-verification-email-mutation.d.ts +4 -4
- package/dist/mutations/auth/send-verification-email-mutation.js +31 -22
- package/dist/mutations/auth/sign-in-email-mutation.d.ts +10 -10
- package/dist/mutations/auth/sign-in-email-mutation.js +38 -27
- package/dist/mutations/auth/sign-in-social-mutation.d.ts +6 -6
- package/dist/mutations/auth/sign-in-social-mutation.js +36 -22
- package/dist/mutations/auth/sign-out-mutation.d.ts +9 -7
- package/dist/mutations/auth/sign-out-mutation.js +39 -26
- package/dist/mutations/auth/sign-up-email-mutation.d.ts +12 -12
- package/dist/mutations/auth/sign-up-email-mutation.js +34 -27
- package/dist/mutations/auth-mutation-options.d.ts +2 -2
- package/dist/mutations/auth-mutation-options.js +22 -18
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.d.ts +4 -4
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.js +31 -22
- package/dist/mutations/multi-session/revoke-multi-session-mutation.d.ts +8 -8
- package/dist/mutations/multi-session/revoke-multi-session-mutation.js +37 -27
- package/dist/mutations/multi-session/set-active-session-mutation.d.ts +8 -9
- package/dist/mutations/multi-session/set-active-session-mutation.js +38 -29
- package/dist/mutations/organization/accept-invitation-mutation.d.ts +43 -0
- package/dist/mutations/organization/accept-invitation-mutation.js +32 -0
- package/dist/mutations/organization/cancel-invitation-mutation.d.ts +25 -0
- package/dist/mutations/organization/cancel-invitation-mutation.js +28 -0
- package/dist/mutations/organization/check-slug-mutation.d.ts +21 -0
- package/dist/mutations/organization/check-slug-mutation.js +30 -0
- package/dist/mutations/organization/create-organization-mutation.d.ts +39 -0
- package/dist/mutations/organization/create-organization-mutation.js +29 -0
- package/dist/mutations/organization/delete-organization-mutation.d.ts +21 -0
- package/dist/mutations/organization/delete-organization-mutation.js +29 -0
- package/dist/mutations/organization/index.d.ts +12 -0
- package/dist/mutations/organization/index.js +12 -0
- package/dist/mutations/organization/invite-member-mutation.d.ts +43 -0
- package/dist/mutations/organization/invite-member-mutation.js +35 -0
- package/dist/mutations/organization/leave-organization-mutation.d.ts +65 -0
- package/dist/mutations/organization/leave-organization-mutation.js +32 -0
- package/dist/mutations/organization/reject-invitation-mutation.d.ts +31 -0
- package/dist/mutations/organization/reject-invitation-mutation.js +25 -0
- package/dist/mutations/organization/remove-member-mutation.d.ts +35 -0
- package/dist/mutations/organization/remove-member-mutation.js +29 -0
- package/dist/mutations/organization/set-active-organization-mutation.d.ts +71 -0
- package/dist/mutations/organization/set-active-organization-mutation.js +72 -0
- package/dist/mutations/organization/update-member-role-mutation.d.ts +31 -0
- package/dist/mutations/organization/update-member-role-mutation.js +36 -0
- package/dist/mutations/organization/update-organization-mutation.d.ts +21 -0
- package/dist/mutations/organization/update-organization-mutation.js +36 -0
- package/dist/mutations/passkey/add-passkey-mutation.d.ts +16 -16
- package/dist/mutations/passkey/add-passkey-mutation.js +38 -27
- package/dist/mutations/passkey/delete-passkey-mutation.d.ts +8 -8
- package/dist/mutations/passkey/delete-passkey-mutation.js +37 -27
- package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +24 -24
- package/dist/mutations/passkey/sign-in-passkey-mutation.js +36 -27
- package/dist/mutations/settings/change-email-mutation.d.ts +9 -8
- package/dist/mutations/settings/change-email-mutation.js +35 -27
- package/dist/mutations/settings/change-password-mutation.d.ts +6 -6
- package/dist/mutations/settings/change-password-mutation.js +31 -22
- package/dist/mutations/settings/delete-user-mutation.d.ts +4 -4
- package/dist/mutations/settings/delete-user-mutation.js +31 -22
- package/dist/mutations/settings/link-social-mutation.d.ts +4 -4
- package/dist/mutations/settings/link-social-mutation.js +31 -22
- package/dist/mutations/settings/revoke-session-mutation.d.ts +8 -8
- package/dist/mutations/settings/revoke-session-mutation.js +37 -27
- package/dist/mutations/settings/unlink-account-mutation.d.ts +8 -8
- package/dist/mutations/settings/unlink-account-mutation.js +37 -27
- package/dist/mutations/settings/update-user-mutation.d.ts +8 -8
- package/dist/mutations/settings/update-user-mutation.js +34 -33
- package/dist/mutations/username/is-username-available-mutation.d.ts +4 -4
- package/dist/mutations/username/is-username-available-mutation.js +34 -22
- package/dist/mutations/username/sign-in-username-mutation.d.ts +10 -10
- package/dist/mutations/username/sign-in-username-mutation.js +35 -27
- package/dist/plugins/captcha-plugin.d.ts +3 -3
- package/dist/plugins/captcha-plugin.js +31 -26
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +1 -2
- package/dist/queries/api-key/list-api-keys-query.d.ts +20 -11
- package/dist/queries/api-key/list-api-keys-query.js +52 -29
- package/dist/queries/auth/session-query.d.ts +6 -6
- package/dist/queries/auth/session-query.js +70 -28
- package/dist/queries/auth-query-options.d.ts +2 -2
- package/dist/queries/auth-query-options.js +20 -16
- package/dist/queries/multi-session/list-device-sessions-query.d.ts +8 -8
- package/dist/queries/multi-session/list-device-sessions-query.js +83 -29
- package/dist/queries/organization/active-organization-query.d.ts +39 -0
- package/dist/queries/organization/active-organization-query.js +37 -0
- package/dist/queries/organization/full-organization-query.d.ts +37 -0
- package/dist/queries/organization/full-organization-query.js +31 -0
- package/dist/queries/organization/has-permission-query.d.ts +21 -0
- package/dist/queries/organization/has-permission-query.js +38 -0
- package/dist/queries/organization/index.d.ts +7 -0
- package/dist/queries/organization/index.js +7 -0
- package/dist/queries/organization/list-invitations-query.d.ts +29 -0
- package/dist/queries/organization/list-invitations-query.js +37 -0
- package/dist/queries/organization/list-members-query.d.ts +61 -0
- package/dist/queries/organization/list-members-query.js +37 -0
- package/dist/queries/organization/list-organizations-query.d.ts +22 -0
- package/dist/queries/organization/list-organizations-query.js +31 -0
- package/dist/queries/organization/list-user-invitations-query.d.ts +29 -0
- package/dist/queries/organization/list-user-invitations-query.js +31 -0
- package/dist/queries/passkey/list-passkeys-query.d.ts +8 -8
- package/dist/queries/passkey/list-passkeys-query.js +81 -29
- package/dist/queries/settings/account-info-query.d.ts +6 -6
- package/dist/queries/settings/account-info-query.js +85 -29
- package/dist/queries/settings/list-accounts-query.d.ts +6 -6
- package/dist/queries/settings/list-accounts-query.js +83 -29
- package/dist/queries/settings/list-sessions-query.d.ts +6 -6
- package/dist/queries/settings/list-sessions-query.js +81 -29
- package/dist/server/queries/api-key/list-api-keys-query.d.ts +83 -0
- package/dist/server/queries/api-key/list-api-keys-query.js +49 -0
- package/dist/server/queries/auth/session-query.d.ts +5 -5
- package/dist/server/queries/auth/session-query.js +50 -12
- package/dist/server/queries/multi-session/list-device-sessions-query.d.ts +7 -7
- package/dist/server/queries/multi-session/list-device-sessions-query.js +53 -11
- package/dist/server/queries/organization/active-organization-query.d.ts +61 -0
- package/dist/server/queries/organization/active-organization-query.js +25 -0
- package/dist/server/queries/organization/full-organization-query.d.ts +42 -0
- package/dist/server/queries/organization/full-organization-query.js +21 -0
- package/dist/server/queries/organization/has-permission-query.d.ts +66 -0
- package/dist/server/queries/organization/has-permission-query.js +23 -0
- package/dist/server/queries/organization/list-invitations-query.d.ts +34 -0
- package/dist/server/queries/organization/list-invitations-query.js +21 -0
- package/dist/server/queries/organization/list-members-query.d.ts +66 -0
- package/dist/server/queries/organization/list-members-query.js +21 -0
- package/dist/server/queries/organization/list-organizations-query.d.ts +27 -0
- package/dist/server/queries/organization/list-organizations-query.js +21 -0
- package/dist/server/queries/organization/list-user-invitations-query.d.ts +34 -0
- package/dist/server/queries/organization/list-user-invitations-query.js +21 -0
- package/dist/server/queries/passkey/list-passkeys-query.d.ts +7 -7
- package/dist/server/queries/passkey/list-passkeys-query.js +53 -11
- package/dist/server/queries/settings/account-info-query.d.ts +5 -5
- package/dist/server/queries/settings/account-info-query.js +53 -11
- package/dist/server/queries/settings/list-accounts-query.d.ts +5 -5
- package/dist/server/queries/settings/list-accounts-query.js +53 -11
- package/dist/server/queries/settings/list-sessions-query.d.ts +5 -5
- package/dist/server/queries/settings/list-sessions-query.js +53 -11
- package/dist/server.d.ts +15 -7
- package/dist/server.js +14 -7
- package/package.json +20 -17
- package/src/components/auth/auth-context.tsx +7 -0
- package/src/components/auth/auth-provider.tsx +19 -31
- package/src/components/auth/email/email-localization.tsx +5 -3
- package/src/components/auth/email/index.ts +1 -0
- package/src/components/auth/email/organization-invitation.tsx +454 -0
- package/src/components/mutation-invalidator.tsx +67 -0
- package/src/index.ts +3 -0
- package/src/lib/auth-client.ts +7 -0
- package/src/lib/auth-plugin.ts +17 -0
- package/src/lib/auth-server.ts +17 -1
- package/src/lib/settings-tab.ts +21 -0
- package/src/mutations/api-key/create-api-key-mutation.ts +34 -19
- package/src/mutations/api-key/delete-api-key-mutation.ts +36 -19
- package/src/mutations/auth/sign-in-email-mutation.ts +18 -22
- package/src/mutations/auth/sign-out-mutation.ts +19 -13
- package/src/mutations/auth/sign-up-email-mutation.ts +18 -22
- package/src/mutations/multi-session/revoke-multi-session-mutation.ts +31 -20
- package/src/mutations/multi-session/set-active-session-mutation.ts +25 -44
- package/src/mutations/organization/accept-invitation-mutation.ts +71 -0
- package/src/mutations/organization/cancel-invitation-mutation.ts +67 -0
- package/src/mutations/organization/check-slug-mutation.ts +55 -0
- package/src/mutations/organization/create-organization-mutation.ts +71 -0
- package/src/mutations/organization/delete-organization-mutation.ts +71 -0
- package/src/mutations/organization/index.ts +12 -0
- package/src/mutations/organization/invite-member-mutation.ts +81 -0
- package/src/mutations/organization/leave-organization-mutation.ts +74 -0
- package/src/mutations/organization/reject-invitation-mutation.ts +64 -0
- package/src/mutations/organization/remove-member-mutation.ts +67 -0
- package/src/mutations/organization/set-active-organization-mutation.ts +142 -0
- package/src/mutations/organization/update-member-role-mutation.ts +81 -0
- package/src/mutations/organization/update-organization-mutation.ts +84 -0
- package/src/mutations/passkey/add-passkey-mutation.ts +28 -17
- package/src/mutations/passkey/delete-passkey-mutation.ts +27 -17
- package/src/mutations/passkey/sign-in-passkey-mutation.ts +18 -21
- package/src/mutations/settings/change-email-mutation.ts +22 -18
- package/src/mutations/settings/delete-user-mutation.ts +2 -2
- package/src/mutations/settings/revoke-session-mutation.ts +24 -19
- package/src/mutations/settings/unlink-account-mutation.ts +24 -17
- package/src/mutations/settings/update-user-mutation.ts +18 -30
- package/src/mutations/username/is-username-available-mutation.ts +2 -2
- package/src/mutations/username/sign-in-username-mutation.ts +20 -23
- package/src/queries/api-key/list-api-keys-query.ts +20 -8
- package/src/queries/multi-session/list-device-sessions-query.ts +2 -2
- package/src/queries/organization/active-organization-query.ts +140 -0
- package/src/queries/organization/full-organization-query.ts +113 -0
- package/src/queries/organization/has-permission-query.ts +124 -0
- package/src/queries/organization/index.ts +7 -0
- package/src/queries/organization/list-invitations-query.ts +133 -0
- package/src/queries/organization/list-members-query.ts +133 -0
- package/src/queries/organization/list-organizations-query.ts +122 -0
- package/src/queries/organization/list-user-invitations-query.ts +122 -0
- package/src/queries/passkey/list-passkeys-query.ts +2 -2
- package/src/server/queries/api-key/list-api-keys-query.ts +94 -0
- package/src/server/queries/multi-session/list-device-sessions-query.ts +2 -2
- package/src/server/queries/organization/active-organization-query.ts +92 -0
- package/src/server/queries/organization/full-organization-query.ts +64 -0
- package/src/server/queries/organization/has-permission-query.ts +66 -0
- package/src/server/queries/organization/list-invitations-query.ts +81 -0
- package/src/server/queries/organization/list-members-query.ts +75 -0
- package/src/server/queries/organization/list-organizations-query.ts +67 -0
- package/src/server/queries/organization/list-user-invitations-query.ts +68 -0
- package/src/server/queries/passkey/list-passkeys-query.ts +2 -2
- package/src/server.ts +8 -0
|
@@ -1,31 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { passkeyQueryKeys } from "@better-auth-ui/core/plugins";
|
|
2
|
+
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useSession } from "../auth/session-query";
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for the current user's passkeys.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
8
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
9
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
10
|
+
*/
|
|
11
|
+
export function listPasskeysOptions(authClient, userId, params) {
|
|
12
|
+
const queryKey = passkeyQueryKeys.list(userId, params?.query);
|
|
13
|
+
const options = queryOptions({
|
|
14
|
+
queryKey,
|
|
15
|
+
queryFn: ({ signal }) => authClient.passkey.listUserPasskeys({
|
|
16
|
+
...params,
|
|
17
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
return options;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Get the current user's passkeys from the query cache, calling
|
|
24
|
+
* `fetchListPasskeys` under the hood if no cached entry exists. Resolves
|
|
25
|
+
* with the passkey list, making it ideal for loaders or `beforeLoad` guards.
|
|
26
|
+
*
|
|
27
|
+
* @param queryClient - The React Query client.
|
|
28
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
29
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
30
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
31
|
+
*/
|
|
32
|
+
export const ensureListPasskeys = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(listPasskeysOptions(authClient, userId, params));
|
|
33
|
+
/**
|
|
34
|
+
* Prefetch the current user's passkeys into the query cache. Behaves like
|
|
35
|
+
* `fetchListPasskeys`, but does not throw on error and does not return
|
|
36
|
+
* the data — use this to warm the cache without blocking navigation.
|
|
37
|
+
*
|
|
38
|
+
* @param queryClient - The React Query client.
|
|
39
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
40
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
41
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
42
|
+
*/
|
|
43
|
+
export const prefetchListPasskeys = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(listPasskeysOptions(authClient, userId, params));
|
|
44
|
+
/**
|
|
45
|
+
* Fetch and cache the current user's passkeys, resolving with the data or
|
|
46
|
+
* throwing on error. If a cached entry exists and is neither invalidated
|
|
47
|
+
* nor older than `staleTime`, the cached value is returned without a
|
|
48
|
+
* network call; otherwise the latest data is fetched.
|
|
49
|
+
*
|
|
50
|
+
* @param queryClient - The React Query client.
|
|
51
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
52
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
53
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
54
|
+
*/
|
|
55
|
+
export const fetchListPasskeys = (queryClient, authClient, userId, params) => queryClient.fetchQuery(listPasskeysOptions(authClient, userId, params));
|
|
56
|
+
/**
|
|
57
|
+
* Subscribe to the current user's passkeys via TanStack Query.
|
|
58
|
+
*
|
|
59
|
+
* Shares a query key with the server-side `listPasskeysOptions`, so
|
|
60
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
61
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
62
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
63
|
+
*
|
|
64
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
65
|
+
* @param options - `listPasskeys` params (`query`, `fetchOptions`) merged
|
|
66
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
67
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
68
|
+
* from the nearest `QueryClientProvider`.
|
|
69
|
+
*/
|
|
70
|
+
export function useListPasskeys(authClient, options = {}, queryClient) {
|
|
71
|
+
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
72
|
+
const userId = session?.user.id;
|
|
73
|
+
const { query, fetchOptions, ...queryOptions } = options;
|
|
74
|
+
const baseOptions = listPasskeysOptions(authClient, userId, {
|
|
75
|
+
query,
|
|
76
|
+
fetchOptions
|
|
77
|
+
});
|
|
78
|
+
return useQuery({
|
|
79
|
+
...queryOptions,
|
|
80
|
+
...baseOptions,
|
|
81
|
+
queryFn: userId ? baseOptions.queryFn : skipToken
|
|
82
|
+
}, queryClient);
|
|
29
83
|
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { o as ensureListPasskeys, c as fetchListPasskeys, a as listPasskeysOptions, s as prefetchListPasskeys, l as useListPasskeys };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataTag, QueryClient } from
|
|
2
|
-
import { BetterFetchError } from
|
|
3
|
-
import { AuthClient, InferData } from
|
|
1
|
+
import { type DataTag, type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { BetterFetchError } from "better-auth/react";
|
|
3
|
+
import type { AuthClient, InferData } from "../../lib/auth-client";
|
|
4
4
|
export type AccountInfoData<TAuthClient extends AuthClient> = InferData<TAuthClient["accountInfo"]>;
|
|
5
5
|
export type AccountInfoParams<TAuthClient extends AuthClient> = Parameters<TAuthClient["accountInfo"]>[0];
|
|
6
6
|
export type AccountInfo<TAuthClient extends AuthClient = AuthClient> = NonNullable<AccountInfoData<TAuthClient>>;
|
|
@@ -12,10 +12,10 @@ export type AccountInfoOptions<TAuthClient extends AuthClient> = Omit<ReturnType
|
|
|
12
12
|
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
13
|
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
14
14
|
*/
|
|
15
|
-
export declare function accountInfoOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: AccountInfoParams<TAuthClient>): (import(
|
|
15
|
+
export declare function accountInfoOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: AccountInfoParams<TAuthClient>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<InferData<TAuthClient["accountInfo"]>, BetterFetchError, InferData<TAuthClient["accountInfo"]>, readonly ["auth", "user", string | undefined, "accountInfo", {
|
|
16
16
|
accountId?: string | undefined;
|
|
17
17
|
} | null]>, "queryFn"> & {
|
|
18
|
-
queryFn?: import(
|
|
18
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<InferData<TAuthClient["accountInfo"]>, readonly ["auth", "user", string | undefined, "accountInfo", {
|
|
19
19
|
accountId?: string | undefined;
|
|
20
20
|
} | null], never> | undefined;
|
|
21
21
|
} & {
|
|
@@ -82,4 +82,4 @@ export type UseAccountInfoOptions<TAuthClient extends AuthClient> = AccountInfoO
|
|
|
82
82
|
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
83
83
|
* from the nearest `QueryClientProvider`.
|
|
84
84
|
*/
|
|
85
|
-
export declare function useAccountInfo<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseAccountInfoOptions<TAuthClient>, queryClient?: QueryClient): import(
|
|
85
|
+
export declare function useAccountInfo<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseAccountInfoOptions<TAuthClient>, queryClient?: QueryClient): import("@tanstack/react-query").UseQueryResult<NoInfer<InferData<TAuthClient["accountInfo"]>>, BetterFetchError>;
|
|
@@ -1,31 +1,87 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
+
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useSession } from "../auth/session-query";
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for provider-specific account info.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client.
|
|
8
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
9
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
10
|
+
*/
|
|
11
|
+
export function accountInfoOptions(authClient, userId, params) {
|
|
12
|
+
const queryKey = authQueryKeys.accountInfo(userId, params?.query);
|
|
13
|
+
const options = queryOptions({
|
|
14
|
+
queryKey,
|
|
15
|
+
queryFn: ({ signal }) => authClient.accountInfo({
|
|
16
|
+
...params,
|
|
17
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
return options;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Get the current user's provider-specific account info from the query
|
|
24
|
+
* cache, calling `fetchAccountInfo` under the hood if no cached entry
|
|
25
|
+
* exists. Resolves with the data, making it ideal for loaders or
|
|
26
|
+
* `beforeLoad` guards.
|
|
27
|
+
*
|
|
28
|
+
* @param queryClient - The React Query client.
|
|
29
|
+
* @param authClient - The Better Auth client.
|
|
30
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
31
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
32
|
+
*/
|
|
33
|
+
export const ensureAccountInfo = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(accountInfoOptions(authClient, userId, params));
|
|
34
|
+
/**
|
|
35
|
+
* Prefetch the current user's provider-specific account info into the query
|
|
36
|
+
* cache. Behaves like `fetchAccountInfo`, but does not throw on error and
|
|
37
|
+
* does not return the data — use this to warm the cache without blocking
|
|
38
|
+
* navigation.
|
|
39
|
+
*
|
|
40
|
+
* @param queryClient - The React Query client.
|
|
41
|
+
* @param authClient - The Better Auth client.
|
|
42
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
43
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
44
|
+
*/
|
|
45
|
+
export const prefetchAccountInfo = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(accountInfoOptions(authClient, userId, params));
|
|
46
|
+
/**
|
|
47
|
+
* Fetch and cache the current user's provider-specific account info,
|
|
48
|
+
* resolving with the data or throwing on error. If a cached entry exists
|
|
49
|
+
* and is neither invalidated nor older than `staleTime`, the cached value
|
|
50
|
+
* is returned without a network call; otherwise the latest data is fetched.
|
|
51
|
+
*
|
|
52
|
+
* @param queryClient - The React Query client.
|
|
53
|
+
* @param authClient - The Better Auth client.
|
|
54
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
55
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
56
|
+
*/
|
|
57
|
+
export const fetchAccountInfo = (queryClient, authClient, userId, params) => queryClient.fetchQuery(accountInfoOptions(authClient, userId, params));
|
|
58
|
+
/**
|
|
59
|
+
* Subscribe to provider-specific info for a linked account via TanStack Query.
|
|
60
|
+
*
|
|
61
|
+
* Shares a query key with the server-side `accountInfoOptions`, so
|
|
62
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
63
|
+
* The query is gated on both a signed-in user and a resolved `accountId`;
|
|
64
|
+
* until both are present, the underlying `queryFn` is replaced with
|
|
65
|
+
* `skipToken`.
|
|
66
|
+
*
|
|
67
|
+
* @param authClient - The Better Auth client.
|
|
68
|
+
* @param options - `accountInfo` params (`query`, `fetchOptions`) merged
|
|
69
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
70
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
71
|
+
* from the nearest `QueryClientProvider`.
|
|
72
|
+
*/
|
|
73
|
+
export function useAccountInfo(authClient, options = {}, queryClient) {
|
|
74
|
+
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
75
|
+
const userId = session?.user.id;
|
|
76
|
+
const { query, fetchOptions, ...queryOptions } = options;
|
|
77
|
+
const baseOptions = accountInfoOptions(authClient, userId, {
|
|
78
|
+
query,
|
|
79
|
+
fetchOptions
|
|
80
|
+
});
|
|
81
|
+
const canFetch = Boolean(userId && query?.accountId);
|
|
82
|
+
return useQuery({
|
|
83
|
+
...queryOptions,
|
|
84
|
+
...baseOptions,
|
|
85
|
+
queryFn: canFetch ? baseOptions.queryFn : skipToken
|
|
86
|
+
}, queryClient);
|
|
29
87
|
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { a as accountInfoOptions, o as ensureAccountInfo, c as fetchAccountInfo, s as prefetchAccountInfo, l as useAccountInfo };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataTag, QueryClient } from
|
|
2
|
-
import { BetterFetchError } from
|
|
3
|
-
import { AuthClient, InferData } from
|
|
1
|
+
import { type DataTag, type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { BetterFetchError } from "better-auth/react";
|
|
3
|
+
import type { AuthClient, InferData } from "../../lib/auth-client";
|
|
4
4
|
export type ListAccountsData<TAuthClient extends AuthClient> = InferData<TAuthClient["listAccounts"]>;
|
|
5
5
|
export type ListAccountsParams<TAuthClient extends AuthClient> = Parameters<TAuthClient["listAccounts"]>[0];
|
|
6
6
|
export type ListAccount<TAuthClient extends AuthClient = AuthClient> = NonNullable<ListAccountsData<TAuthClient>>[number];
|
|
@@ -12,8 +12,8 @@ export type ListAccountsOptions<TAuthClient extends AuthClient> = Omit<ReturnTyp
|
|
|
12
12
|
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
13
|
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
14
14
|
*/
|
|
15
|
-
export declare function listAccountsOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListAccountsParams<TAuthClient>): (import(
|
|
16
|
-
queryFn?: import(
|
|
15
|
+
export declare function listAccountsOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListAccountsParams<TAuthClient>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<InferData<TAuthClient["listAccounts"]>, BetterFetchError, InferData<TAuthClient["listAccounts"]>, readonly ["auth", "user", string | undefined, "listAccounts", Record<string, any> | null]>, "queryFn"> & {
|
|
16
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<InferData<TAuthClient["listAccounts"]>, readonly ["auth", "user", string | undefined, "listAccounts", Record<string, any> | null], never> | undefined;
|
|
17
17
|
} & {
|
|
18
18
|
queryKey: readonly ["auth", "user", string | undefined, "listAccounts", Record<string, any> | null] & {
|
|
19
19
|
[dataTagSymbol]: InferData<TAuthClient["listAccounts"]>;
|
|
@@ -73,4 +73,4 @@ export type UseListAccountsOptions<TAuthClient extends AuthClient> = ListAccount
|
|
|
73
73
|
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
74
74
|
* from the nearest `QueryClientProvider`.
|
|
75
75
|
*/
|
|
76
|
-
export declare function useListAccounts<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseListAccountsOptions<TAuthClient>, queryClient?: QueryClient): import(
|
|
76
|
+
export declare function useListAccounts<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseListAccountsOptions<TAuthClient>, queryClient?: QueryClient): import("@tanstack/react-query").UseQueryResult<NoInfer<InferData<TAuthClient["listAccounts"]>>, BetterFetchError>;
|
|
@@ -1,31 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
+
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useSession } from "../auth/session-query";
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for a user's linked social accounts.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client.
|
|
8
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
9
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
10
|
+
*/
|
|
11
|
+
export function listAccountsOptions(authClient, userId, params) {
|
|
12
|
+
const queryKey = authQueryKeys.listAccounts(userId, params?.query);
|
|
13
|
+
const options = queryOptions({
|
|
14
|
+
queryKey,
|
|
15
|
+
queryFn: ({ signal }) => authClient.listAccounts({
|
|
16
|
+
...params,
|
|
17
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
return options;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Get the current user's linked social accounts from the query cache,
|
|
24
|
+
* calling `fetchListAccounts` under the hood if no cached entry exists.
|
|
25
|
+
* Resolves with the account list, making it ideal for loaders or
|
|
26
|
+
* `beforeLoad` guards.
|
|
27
|
+
*
|
|
28
|
+
* @param queryClient - The React Query client.
|
|
29
|
+
* @param authClient - The Better Auth client.
|
|
30
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
31
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
32
|
+
*/
|
|
33
|
+
export const ensureListAccounts = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(listAccountsOptions(authClient, userId, params));
|
|
34
|
+
/**
|
|
35
|
+
* Prefetch the current user's linked social accounts into the query cache.
|
|
36
|
+
* Behaves like `fetchListAccounts`, but does not throw on error and does
|
|
37
|
+
* not return the data — use this to warm the cache without blocking
|
|
38
|
+
* navigation.
|
|
39
|
+
*
|
|
40
|
+
* @param queryClient - The React Query client.
|
|
41
|
+
* @param authClient - The Better Auth client.
|
|
42
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
43
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
44
|
+
*/
|
|
45
|
+
export const prefetchListAccounts = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(listAccountsOptions(authClient, userId, params));
|
|
46
|
+
/**
|
|
47
|
+
* Fetch and cache the current user's linked social accounts, resolving
|
|
48
|
+
* with the data or throwing on error. If a cached entry exists and is
|
|
49
|
+
* neither invalidated nor older than `staleTime`, the cached value is
|
|
50
|
+
* returned without a network call; otherwise the latest data is fetched.
|
|
51
|
+
*
|
|
52
|
+
* @param queryClient - The React Query client.
|
|
53
|
+
* @param authClient - The Better Auth client.
|
|
54
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
55
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
56
|
+
*/
|
|
57
|
+
export const fetchListAccounts = (queryClient, authClient, userId, params) => queryClient.fetchQuery(listAccountsOptions(authClient, userId, params));
|
|
58
|
+
/**
|
|
59
|
+
* Subscribe to the current user's linked social accounts via TanStack Query.
|
|
60
|
+
*
|
|
61
|
+
* Shares a query key with the server-side `listAccountsOptions`, so
|
|
62
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
63
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
64
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
65
|
+
*
|
|
66
|
+
* @param authClient - The Better Auth client.
|
|
67
|
+
* @param options - `listAccounts` params (`query`, `fetchOptions`) merged
|
|
68
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
69
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
70
|
+
* from the nearest `QueryClientProvider`.
|
|
71
|
+
*/
|
|
72
|
+
export function useListAccounts(authClient, options = {}, queryClient) {
|
|
73
|
+
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
74
|
+
const userId = session?.user.id;
|
|
75
|
+
const { query, fetchOptions, ...queryOptions } = options;
|
|
76
|
+
const baseOptions = listAccountsOptions(authClient, userId, {
|
|
77
|
+
query,
|
|
78
|
+
fetchOptions
|
|
79
|
+
});
|
|
80
|
+
return useQuery({
|
|
81
|
+
...queryOptions,
|
|
82
|
+
...baseOptions,
|
|
83
|
+
queryFn: userId ? baseOptions.queryFn : skipToken
|
|
84
|
+
}, queryClient);
|
|
29
85
|
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { o as ensureListAccounts, c as fetchListAccounts, a as listAccountsOptions, s as prefetchListAccounts, l as useListAccounts };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataTag, QueryClient } from
|
|
2
|
-
import { BetterFetchError } from
|
|
3
|
-
import { AuthClient, InferData } from
|
|
1
|
+
import { type DataTag, type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { BetterFetchError } from "better-auth/react";
|
|
3
|
+
import type { AuthClient, InferData } from "../../lib/auth-client";
|
|
4
4
|
export type ListSessionsData<TAuthClient extends AuthClient> = InferData<TAuthClient["listSessions"]>;
|
|
5
5
|
export type ListSessionsParams<TAuthClient extends AuthClient> = Parameters<TAuthClient["listSessions"]>[0];
|
|
6
6
|
export type ListSession<TAuthClient extends AuthClient = AuthClient> = NonNullable<ListSessionsData<TAuthClient>>[number];
|
|
@@ -12,8 +12,8 @@ export type ListSessionsOptions<TAuthClient extends AuthClient> = Omit<ReturnTyp
|
|
|
12
12
|
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
13
|
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
14
14
|
*/
|
|
15
|
-
export declare function listSessionsOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListSessionsParams<TAuthClient>): (import(
|
|
16
|
-
queryFn?: import(
|
|
15
|
+
export declare function listSessionsOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListSessionsParams<TAuthClient>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<InferData<TAuthClient["listSessions"]>, BetterFetchError, InferData<TAuthClient["listSessions"]>, readonly ["auth", "user", string | undefined, "listSessions", Record<string, any> | null]>, "queryFn"> & {
|
|
16
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<InferData<TAuthClient["listSessions"]>, readonly ["auth", "user", string | undefined, "listSessions", Record<string, any> | null], never> | undefined;
|
|
17
17
|
} & {
|
|
18
18
|
queryKey: readonly ["auth", "user", string | undefined, "listSessions", Record<string, any> | null] & {
|
|
19
19
|
[dataTagSymbol]: InferData<TAuthClient["listSessions"]>;
|
|
@@ -71,4 +71,4 @@ export type UseListSessionsOptions<TAuthClient extends AuthClient> = ListSession
|
|
|
71
71
|
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
72
72
|
* from the nearest `QueryClientProvider`.
|
|
73
73
|
*/
|
|
74
|
-
export declare function useListSessions<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseListSessionsOptions<TAuthClient>, queryClient?: QueryClient): import(
|
|
74
|
+
export declare function useListSessions<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseListSessionsOptions<TAuthClient>, queryClient?: QueryClient): import("@tanstack/react-query").UseQueryResult<NoInfer<InferData<TAuthClient["listSessions"]>>, BetterFetchError>;
|
|
@@ -1,31 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
+
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useSession } from "../auth/session-query";
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for the current user's active sessions.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client.
|
|
8
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
9
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
10
|
+
*/
|
|
11
|
+
export function listSessionsOptions(authClient, userId, params) {
|
|
12
|
+
const queryKey = authQueryKeys.listSessions(userId, params?.query);
|
|
13
|
+
const options = queryOptions({
|
|
14
|
+
queryKey,
|
|
15
|
+
queryFn: ({ signal }) => authClient.listSessions({
|
|
16
|
+
...params,
|
|
17
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
return options;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Get the current user's active sessions from the query cache, calling
|
|
24
|
+
* `fetchListSessions` under the hood if no cached entry exists. Resolves
|
|
25
|
+
* with the session list, making it ideal for loaders or `beforeLoad` guards.
|
|
26
|
+
*
|
|
27
|
+
* @param queryClient - The React Query client.
|
|
28
|
+
* @param authClient - The Better Auth client.
|
|
29
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
30
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
31
|
+
*/
|
|
32
|
+
export const ensureListSessions = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(listSessionsOptions(authClient, userId, params));
|
|
33
|
+
/**
|
|
34
|
+
* Prefetch the current user's active sessions into the query cache. Behaves
|
|
35
|
+
* like `fetchListSessions`, but does not throw on error and does not return
|
|
36
|
+
* the data — use this to warm the cache without blocking navigation.
|
|
37
|
+
*
|
|
38
|
+
* @param queryClient - The React Query client.
|
|
39
|
+
* @param authClient - The Better Auth client.
|
|
40
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
41
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
42
|
+
*/
|
|
43
|
+
export const prefetchListSessions = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(listSessionsOptions(authClient, userId, params));
|
|
44
|
+
/**
|
|
45
|
+
* Fetch and cache the current user's active sessions, resolving with the
|
|
46
|
+
* data or throwing on error. If a cached entry exists and is neither
|
|
47
|
+
* invalidated nor older than `staleTime`, the cached value is returned
|
|
48
|
+
* without a network call; otherwise the latest data is fetched.
|
|
49
|
+
*
|
|
50
|
+
* @param queryClient - The React Query client.
|
|
51
|
+
* @param authClient - The Better Auth client.
|
|
52
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
53
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
54
|
+
*/
|
|
55
|
+
export const fetchListSessions = (queryClient, authClient, userId, params) => queryClient.fetchQuery(listSessionsOptions(authClient, userId, params));
|
|
56
|
+
/**
|
|
57
|
+
* Subscribe to the current user's active sessions via TanStack Query.
|
|
58
|
+
*
|
|
59
|
+
* Shares a query key with the server-side `listSessionsOptions`, so
|
|
60
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
61
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
62
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
63
|
+
*
|
|
64
|
+
* @param authClient - The Better Auth client.
|
|
65
|
+
* @param options - `listSessions` params (`query`, `fetchOptions`) merged
|
|
66
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
67
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
68
|
+
* from the nearest `QueryClientProvider`.
|
|
69
|
+
*/
|
|
70
|
+
export function useListSessions(authClient, options = {}, queryClient) {
|
|
71
|
+
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
72
|
+
const userId = session?.user.id;
|
|
73
|
+
const { query, fetchOptions, ...queryOptions } = options;
|
|
74
|
+
const baseOptions = listSessionsOptions(authClient, userId, {
|
|
75
|
+
query,
|
|
76
|
+
fetchOptions
|
|
77
|
+
});
|
|
78
|
+
return useQuery({
|
|
79
|
+
...queryOptions,
|
|
80
|
+
...baseOptions,
|
|
81
|
+
queryFn: userId ? baseOptions.queryFn : skipToken
|
|
82
|
+
}, queryClient);
|
|
29
83
|
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { o as ensureListSessions, c as fetchListSessions, a as listSessionsOptions, s as prefetchListSessions, l as useListSessions };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type DataTag, type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { APIError } from "better-auth";
|
|
3
|
+
import type { ApiKeyAuthServer } from "../../../lib/auth-server";
|
|
4
|
+
export type ListApiKeysData<TAuth extends ApiKeyAuthServer = ApiKeyAuthServer> = Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>;
|
|
5
|
+
export type ListedApiKey<TAuth extends ApiKeyAuthServer = ApiKeyAuthServer> = NonNullable<ListApiKeysData<TAuth>>["apiKeys"][number];
|
|
6
|
+
export type ListApiKeysParams<TAuth extends ApiKeyAuthServer = ApiKeyAuthServer> = Parameters<TAuth["api"]["listApiKeys"]>[0];
|
|
7
|
+
/**
|
|
8
|
+
* Query options factory for the current user's API keys on the server.
|
|
9
|
+
*
|
|
10
|
+
* Uses the same query key as the client-side `listApiKeysOptions` so that data
|
|
11
|
+
* fetched during SSR hydrates seamlessly into the client's React Query cache.
|
|
12
|
+
*
|
|
13
|
+
* @param auth - The Better Auth server instance with the API key plugin.
|
|
14
|
+
* @param userId - The signed-in user's ID. Used for cache partitioning.
|
|
15
|
+
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function listApiKeysOptions<TAuth extends ApiKeyAuthServer>(auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>, APIError, Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>, readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
18
|
+
configId?: string | undefined;
|
|
19
|
+
organizationId?: string | undefined;
|
|
20
|
+
limit?: unknown;
|
|
21
|
+
offset?: unknown;
|
|
22
|
+
sortBy?: string | undefined;
|
|
23
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
24
|
+
} | null]>, "queryFn"> & {
|
|
25
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>, readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
26
|
+
configId?: string | undefined;
|
|
27
|
+
organizationId?: string | undefined;
|
|
28
|
+
limit?: unknown;
|
|
29
|
+
offset?: unknown;
|
|
30
|
+
sortBy?: string | undefined;
|
|
31
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
32
|
+
} | null], never> | undefined;
|
|
33
|
+
} & {
|
|
34
|
+
queryKey: readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
35
|
+
configId?: string | undefined;
|
|
36
|
+
organizationId?: string | undefined;
|
|
37
|
+
limit?: unknown;
|
|
38
|
+
offset?: unknown;
|
|
39
|
+
sortBy?: string | undefined;
|
|
40
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
41
|
+
} | null] & {
|
|
42
|
+
[dataTagSymbol]: Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>;
|
|
43
|
+
[dataTagErrorSymbol]: APIError;
|
|
44
|
+
};
|
|
45
|
+
}) & {
|
|
46
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
47
|
+
configId?: string | undefined;
|
|
48
|
+
organizationId?: string | undefined;
|
|
49
|
+
limit?: unknown;
|
|
50
|
+
offset?: unknown;
|
|
51
|
+
sortBy?: string | undefined;
|
|
52
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
53
|
+
} | null], Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>, APIError>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Get the current user's API keys from the query cache, calling
|
|
57
|
+
* `fetchListApiKeys` under the hood if no cached entry exists.
|
|
58
|
+
*
|
|
59
|
+
* @param queryClient - The React Query client used for SSR hydration.
|
|
60
|
+
* @param auth - The Better Auth server instance with the API key plugin.
|
|
61
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
62
|
+
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
|
|
63
|
+
*/
|
|
64
|
+
export declare const ensureListApiKeys: <TAuth extends ApiKeyAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>>;
|
|
65
|
+
/**
|
|
66
|
+
* Prefetch the current user's API keys into the query cache.
|
|
67
|
+
*
|
|
68
|
+
* @param queryClient - The React Query client used for SSR hydration.
|
|
69
|
+
* @param auth - The Better Auth server instance with the API key plugin.
|
|
70
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
71
|
+
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
|
|
72
|
+
*/
|
|
73
|
+
export declare const prefetchListApiKeys: <TAuth extends ApiKeyAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>) => Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Fetch and cache the current user's API keys, resolving with the data or
|
|
76
|
+
* throwing on error.
|
|
77
|
+
*
|
|
78
|
+
* @param queryClient - The React Query client used for SSR hydration.
|
|
79
|
+
* @param auth - The Better Auth server instance with the API key plugin.
|
|
80
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
81
|
+
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
|
|
82
|
+
*/
|
|
83
|
+
export declare const fetchListApiKeys: <TAuth extends ApiKeyAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>>;
|