@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,29 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createAuthPlugin } from "@better-auth-ui/core";
|
|
4
|
+
import { useCallback, useEffect } from "react";
|
|
5
|
+
import { useFetchOptions } from "../components/auth/fetch-options-provider";
|
|
6
|
+
import { useAuthPlugin } from "../hooks/use-auth-plugin";
|
|
7
|
+
function CaptchaWidget() {
|
|
8
|
+
const { render: Render } = useAuthPlugin(captchaPlugin);
|
|
9
|
+
const { setFetchOptions, registerReset } = useFetchOptions();
|
|
10
|
+
const setToken = useCallback((token) => {
|
|
11
|
+
setFetchOptions({ headers: { "x-captcha-response": token } });
|
|
12
|
+
}, [setFetchOptions]);
|
|
13
|
+
const clearToken = useCallback(() => {
|
|
14
|
+
setFetchOptions(undefined);
|
|
15
|
+
}, [setFetchOptions]);
|
|
16
|
+
const setReset = useCallback((reset) => {
|
|
17
|
+
registerReset(reset);
|
|
18
|
+
}, [registerReset]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
return () => {
|
|
21
|
+
setFetchOptions(undefined);
|
|
22
|
+
registerReset(null);
|
|
23
|
+
};
|
|
24
|
+
}, [setFetchOptions, registerReset]);
|
|
25
|
+
return (_jsx(Render, { setToken: setToken, clearToken: clearToken, setReset: setReset }));
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Provider-agnostic captcha plugin. Forwards the resolved token via the
|
|
29
|
+
* `x-captcha-response` header on Better Auth requests.
|
|
30
|
+
*/
|
|
31
|
+
export const captchaPlugin = createAuthPlugin("captcha", ({ render }) => ({
|
|
32
|
+
render,
|
|
33
|
+
captchaComponent: _jsx(CaptchaWidget, {})
|
|
27
34
|
}));
|
|
28
|
-
//#endregion
|
|
29
|
-
export { s as captchaPlugin };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./plugins/captcha-plugin";
|
package/dist/plugins.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { DataTag, QueryClient } from
|
|
2
|
-
import { BetterFetchError } from
|
|
3
|
-
import { ApiKeyAuthClient, InferData } from
|
|
4
|
-
export type ListApiKeysData<TAuthClient extends ApiKeyAuthClient> = InferData<TAuthClient["apiKey"]["list"]>;
|
|
5
|
-
export type ListApiKeysParams<TAuthClient extends ApiKeyAuthClient> = Parameters<TAuthClient["apiKey"]["list"]>[0];
|
|
1
|
+
import { type DataTag, type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { BetterFetchError } from "better-auth/react";
|
|
3
|
+
import type { ApiKeyAuthClient, InferData } from "../../lib/auth-client";
|
|
4
|
+
export type ListApiKeysData<TAuthClient extends ApiKeyAuthClient = ApiKeyAuthClient> = InferData<TAuthClient["apiKey"]["list"]>;
|
|
5
|
+
export type ListApiKeysParams<TAuthClient extends ApiKeyAuthClient = ApiKeyAuthClient> = Parameters<TAuthClient["apiKey"]["list"]>[0];
|
|
6
6
|
export type ListedApiKey<TAuthClient extends ApiKeyAuthClient = ApiKeyAuthClient> = NonNullable<ListApiKeysData<TAuthClient>>["apiKeys"][number];
|
|
7
|
-
export type ListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> = Omit<ReturnType<typeof listApiKeysOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
7
|
+
export type ListApiKeysOptions<TAuthClient extends ApiKeyAuthClient = ApiKeyAuthClient> = Omit<ReturnType<typeof listApiKeysOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
8
8
|
/**
|
|
9
9
|
* Query options factory for the current user's API keys.
|
|
10
10
|
*
|
|
11
|
+
* Shares a query key with the server-side `listApiKeysOptions` from
|
|
12
|
+
* `@better-auth-ui/react/server`, so SSR-hydrated data is reused from the
|
|
13
|
+
* cache without an immediate refetch.
|
|
14
|
+
*
|
|
11
15
|
* @param authClient - The Better Auth client with the API key plugin.
|
|
12
16
|
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
17
|
* @param params - Parameters forwarded to `authClient.apiKey.list`.
|
|
14
18
|
*/
|
|
15
|
-
export declare function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListApiKeysParams<TAuthClient>): (import(
|
|
19
|
+
export declare function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListApiKeysParams<TAuthClient>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<InferData<TAuthClient["apiKey"]["list"]>, BetterFetchError, InferData<TAuthClient["apiKey"]["list"]>, readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
16
20
|
configId?: string | undefined;
|
|
17
21
|
organizationId?: string | undefined;
|
|
18
22
|
limit?: unknown;
|
|
@@ -20,7 +24,7 @@ export declare function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>
|
|
|
20
24
|
sortBy?: string | undefined;
|
|
21
25
|
sortDirection?: "asc" | "desc" | undefined;
|
|
22
26
|
} | null]>, "queryFn"> & {
|
|
23
|
-
queryFn?: import(
|
|
27
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<InferData<TAuthClient["apiKey"]["list"]>, readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
24
28
|
configId?: string | undefined;
|
|
25
29
|
organizationId?: string | undefined;
|
|
26
30
|
limit?: unknown;
|
|
@@ -29,7 +33,7 @@ export declare function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>
|
|
|
29
33
|
sortDirection?: "asc" | "desc" | undefined;
|
|
30
34
|
} | null], never> | undefined;
|
|
31
35
|
} & {
|
|
32
|
-
queryKey: readonly ["auth", "user", string | undefined, "
|
|
36
|
+
queryKey: readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
33
37
|
configId?: string | undefined;
|
|
34
38
|
organizationId?: string | undefined;
|
|
35
39
|
limit?: unknown;
|
|
@@ -41,7 +45,7 @@ export declare function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>
|
|
|
41
45
|
[dataTagErrorSymbol]: BetterFetchError;
|
|
42
46
|
};
|
|
43
47
|
}) & {
|
|
44
|
-
queryKey: DataTag<readonly ["auth", "user", string | undefined, "
|
|
48
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "apiKey", "list", {
|
|
45
49
|
configId?: string | undefined;
|
|
46
50
|
organizationId?: string | undefined;
|
|
47
51
|
limit?: unknown;
|
|
@@ -57,8 +61,13 @@ export type UseListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> = ListAp
|
|
|
57
61
|
/**
|
|
58
62
|
* Subscribe to the current user's API keys via TanStack Query.
|
|
59
63
|
*
|
|
64
|
+
* Shares a query key with the server-side `listApiKeysOptions`, so
|
|
65
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
66
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
67
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
68
|
+
*
|
|
60
69
|
* @param authClient - The Better Auth client with the API key plugin.
|
|
61
70
|
* @param options - `apiKey.list` params merged with `useQuery` options.
|
|
62
71
|
* @param queryClient - Optional custom `QueryClient`.
|
|
63
72
|
*/
|
|
64
|
-
export declare function useListApiKeys<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, options?: UseListApiKeysOptions<TAuthClient>, queryClient?: QueryClient): import(
|
|
73
|
+
export declare function useListApiKeys<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, options?: UseListApiKeysOptions<TAuthClient>, queryClient?: QueryClient): import("@tanstack/react-query").UseQueryResult<NoInfer<InferData<TAuthClient["apiKey"]["list"]>>, BetterFetchError>;
|
|
@@ -1,31 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { apiKeyQueryKeys } 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 API keys.
|
|
6
|
+
*
|
|
7
|
+
* Shares a query key with the server-side `listApiKeysOptions` from
|
|
8
|
+
* `@better-auth-ui/react/server`, so SSR-hydrated data is reused from the
|
|
9
|
+
* cache without an immediate refetch.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
12
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.apiKey.list`.
|
|
14
|
+
*/
|
|
15
|
+
export function listApiKeysOptions(authClient, userId, params) {
|
|
16
|
+
const queryKey = apiKeyQueryKeys.list(userId, params?.query);
|
|
17
|
+
const options = queryOptions({
|
|
18
|
+
queryKey,
|
|
19
|
+
queryFn: ({ signal }) => authClient.apiKey.list({
|
|
20
|
+
...params,
|
|
21
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
return options;
|
|
17
25
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
export const ensureListApiKeys = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(listApiKeysOptions(authClient, userId, params));
|
|
27
|
+
export const prefetchListApiKeys = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(listApiKeysOptions(authClient, userId, params));
|
|
28
|
+
export const fetchListApiKeys = (queryClient, authClient, userId, params) => queryClient.fetchQuery(listApiKeysOptions(authClient, userId, params));
|
|
29
|
+
/**
|
|
30
|
+
* Subscribe to the current user's API keys via TanStack Query.
|
|
31
|
+
*
|
|
32
|
+
* Shares a query key with the server-side `listApiKeysOptions`, so
|
|
33
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
34
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
35
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
36
|
+
*
|
|
37
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
38
|
+
* @param options - `apiKey.list` params merged with `useQuery` options.
|
|
39
|
+
* @param queryClient - Optional custom `QueryClient`.
|
|
40
|
+
*/
|
|
41
|
+
export function useListApiKeys(authClient, options = {}, queryClient) {
|
|
42
|
+
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
43
|
+
const userId = session?.user.id;
|
|
44
|
+
const { query, fetchOptions, ...queryOptionsRest } = options;
|
|
45
|
+
const baseOptions = listApiKeysOptions(authClient, userId, {
|
|
46
|
+
query,
|
|
47
|
+
fetchOptions
|
|
48
|
+
});
|
|
49
|
+
return useQuery({
|
|
50
|
+
...queryOptionsRest,
|
|
51
|
+
...baseOptions,
|
|
52
|
+
queryFn: userId ? baseOptions.queryFn : skipToken
|
|
53
|
+
}, queryClient);
|
|
29
54
|
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { o as ensureListApiKeys, c as fetchListApiKeys, a as listApiKeysOptions, s as prefetchListApiKeys, l as useListApiKeys };
|
|
@@ -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 SessionData<TAuthClient extends AuthClient = AuthClient> = InferData<TAuthClient["getSession"]>;
|
|
5
5
|
export type Session<TAuthClient extends AuthClient = AuthClient> = NonNullable<SessionData<TAuthClient>>;
|
|
6
6
|
export type SessionParams<TAuthClient extends AuthClient> = Parameters<TAuthClient["getSession"]>[0];
|
|
@@ -14,8 +14,8 @@ export type SessionOptions<TAuthClient extends AuthClient> = Omit<ReturnType<typ
|
|
|
14
14
|
* @param authClient - The Better Auth client.
|
|
15
15
|
* @param params - Parameters forwarded to `authClient.getSession`.
|
|
16
16
|
*/
|
|
17
|
-
export declare function sessionOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, params?: SessionParams<TAuthClient>): (import(
|
|
18
|
-
queryFn?: import(
|
|
17
|
+
export declare function sessionOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, params?: SessionParams<TAuthClient>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<InferData<TAuthClient["getSession"]>, BetterFetchError, InferData<TAuthClient["getSession"]>, readonly ["auth", "getSession"]>, "queryFn"> & {
|
|
18
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<InferData<TAuthClient["getSession"]>, readonly ["auth", "getSession"], never> | undefined;
|
|
19
19
|
} & {
|
|
20
20
|
queryKey: readonly ["auth", "getSession"] & {
|
|
21
21
|
[dataTagSymbol]: InferData<TAuthClient["getSession"]>;
|
|
@@ -68,4 +68,4 @@ export type UseSessionOptions<TAuthClient extends AuthClient> = SessionOptions<T
|
|
|
68
68
|
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
69
69
|
* from the nearest `QueryClientProvider`.
|
|
70
70
|
*/
|
|
71
|
-
export declare function useSession<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseSessionOptions<TAuthClient>, queryClient?: QueryClient): import(
|
|
71
|
+
export declare function useSession<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseSessionOptions<TAuthClient>, queryClient?: QueryClient): import("@tanstack/react-query").UseQueryResult<NoInfer<InferData<TAuthClient["getSession"]>>, BetterFetchError>;
|
|
@@ -1,30 +1,72 @@
|
|
|
1
|
-
import { authQueryKeys
|
|
2
|
-
import { queryOptions
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
3
|
+
/**
|
|
4
|
+
* Query options factory for the current session.
|
|
5
|
+
*
|
|
6
|
+
* Shares a query key with the server-side `sessionOptions` so that data
|
|
7
|
+
* prefetched during SSR hydrates seamlessly into the client cache.
|
|
8
|
+
*
|
|
9
|
+
* @param authClient - The Better Auth client.
|
|
10
|
+
* @param params - Parameters forwarded to `authClient.getSession`.
|
|
11
|
+
*/
|
|
12
|
+
export function sessionOptions(authClient, params) {
|
|
13
|
+
const queryKey = authQueryKeys.session;
|
|
14
|
+
const options = queryOptions({
|
|
15
|
+
queryKey,
|
|
16
|
+
queryFn: ({ signal }) => authClient.getSession({
|
|
17
|
+
...params,
|
|
18
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
19
|
+
})
|
|
20
|
+
});
|
|
21
|
+
return options;
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Get the current session from the query cache, calling `fetchSession` under
|
|
25
|
+
* the hood if no cached entry exists. Resolves with the session data, making
|
|
26
|
+
* it ideal for loaders or `beforeLoad` guards.
|
|
27
|
+
*
|
|
28
|
+
* @param queryClient - The React Query client.
|
|
29
|
+
* @param authClient - The Better Auth client.
|
|
30
|
+
* @param params - Parameters forwarded to `authClient.getSession`.
|
|
31
|
+
*/
|
|
32
|
+
export const ensureSession = (queryClient, authClient, params) => queryClient.ensureQueryData(sessionOptions(authClient, params));
|
|
33
|
+
/**
|
|
34
|
+
* Prefetch the current session into the query cache. Behaves like
|
|
35
|
+
* `fetchSession`, but does not throw on error and does not return the data —
|
|
36
|
+
* 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 params - Parameters forwarded to `authClient.getSession`.
|
|
41
|
+
*/
|
|
42
|
+
export const prefetchSession = (queryClient, authClient, params) => queryClient.prefetchQuery(sessionOptions(authClient, params));
|
|
43
|
+
/**
|
|
44
|
+
* Fetch and cache the current session, resolving with the data or throwing
|
|
45
|
+
* on error. If a cached entry exists and is neither invalidated nor older
|
|
46
|
+
* than `staleTime`, the cached value is returned without a network call;
|
|
47
|
+
* otherwise the latest data is fetched.
|
|
48
|
+
*
|
|
49
|
+
* @param queryClient - The React Query client.
|
|
50
|
+
* @param authClient - The Better Auth client.
|
|
51
|
+
* @param params - Parameters forwarded to `authClient.getSession`.
|
|
52
|
+
*/
|
|
53
|
+
export const fetchSession = (queryClient, authClient, params) => queryClient.fetchQuery(sessionOptions(authClient, params));
|
|
54
|
+
/**
|
|
55
|
+
* Subscribe to the current session via TanStack Query.
|
|
56
|
+
*
|
|
57
|
+
* Shares a query key with the server-side `sessionOptions`, so SSR-hydrated
|
|
58
|
+
* session data is reused from the cache without an immediate refetch.
|
|
59
|
+
*
|
|
60
|
+
* @param authClient - The Better Auth client.
|
|
61
|
+
* @param options - `getSession` params (`query`, `fetchOptions`) merged
|
|
62
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
63
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
64
|
+
* from the nearest `QueryClientProvider`.
|
|
65
|
+
*/
|
|
66
|
+
export function useSession(authClient, options = {}, queryClient) {
|
|
67
|
+
const { query, fetchOptions, ...queryOptions } = options;
|
|
68
|
+
return useQuery({
|
|
69
|
+
...sessionOptions(authClient, { query, fetchOptions }),
|
|
70
|
+
...queryOptions
|
|
71
|
+
}, queryClient);
|
|
28
72
|
}
|
|
29
|
-
//#endregion
|
|
30
|
-
export { i as ensureSession, o as fetchSession, a as prefetchSession, r as sessionOptions, s as useSession };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataTag, QueryKey, UseQueryOptions } from
|
|
2
|
-
import { BetterFetchError, BetterFetchOption } from
|
|
1
|
+
import { type DataTag, type QueryKey, type UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
import type { BetterFetchError, BetterFetchOption } from "better-auth/client";
|
|
3
3
|
/**
|
|
4
4
|
* Read-style Better Auth client method (params shape `{ query?, fetchOptions? }`).
|
|
5
5
|
* Mutation-style endpoints use `AuthMutationFn` / `useAuthMutation` instead.
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { queryOptions
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { queryOptions } from "@tanstack/react-query";
|
|
2
|
+
/**
|
|
3
|
+
* Build `queryOptions` for a Better Auth endpoint.
|
|
4
|
+
*
|
|
5
|
+
* Injects React Query's `signal` and `throw: true` into `fetchOptions` so the
|
|
6
|
+
* request is cancelled on unmount and errors surface as `BetterFetchError`
|
|
7
|
+
* instead of `{ data, error }`.
|
|
8
|
+
*
|
|
9
|
+
* @param authFn - Better Auth client method (e.g. `authClient.getSession`).
|
|
10
|
+
* @param queryKey - Scope prefix for the key. `params.query` is appended automatically.
|
|
11
|
+
* @param params - Parameters forwarded to `authFn`.
|
|
12
|
+
*/
|
|
13
|
+
export function authQueryOptions(authFn, queryKey, params) {
|
|
14
|
+
return queryOptions({
|
|
15
|
+
queryKey: [...queryKey, params?.query ?? null],
|
|
16
|
+
queryFn: ({ signal }) => authFn({
|
|
17
|
+
...params,
|
|
18
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
19
|
+
})
|
|
20
|
+
});
|
|
15
21
|
}
|
|
16
|
-
//#endregion
|
|
17
|
-
export { t as authQueryOptions };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataTag, QueryClient } from
|
|
2
|
-
import { BetterFetchError } from
|
|
3
|
-
import { InferData, MultiSessionAuthClient } from
|
|
1
|
+
import { type DataTag, type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { BetterFetchError } from "better-auth/react";
|
|
3
|
+
import type { InferData, MultiSessionAuthClient } from "../../lib/auth-client";
|
|
4
4
|
export type ListDeviceSessionsData<TAuthClient extends MultiSessionAuthClient = MultiSessionAuthClient> = InferData<TAuthClient["multiSession"]["listDeviceSessions"]>;
|
|
5
5
|
export type ListDeviceSession<TAuthClient extends MultiSessionAuthClient = MultiSessionAuthClient> = NonNullable<ListDeviceSessionsData<TAuthClient>>[number];
|
|
6
6
|
export type ListDeviceSessionsParams<TAuthClient extends MultiSessionAuthClient> = Parameters<TAuthClient["multiSession"]["listDeviceSessions"]>[0];
|
|
@@ -12,15 +12,15 @@ export type ListDeviceSessionsOptions<TAuthClient extends MultiSessionAuthClient
|
|
|
12
12
|
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
13
|
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
14
14
|
*/
|
|
15
|
-
export declare function listDeviceSessionsOptions<TAuthClient extends MultiSessionAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListDeviceSessionsParams<TAuthClient>): (import(
|
|
16
|
-
queryFn?: import(
|
|
15
|
+
export declare function listDeviceSessionsOptions<TAuthClient extends MultiSessionAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListDeviceSessionsParams<TAuthClient>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, BetterFetchError, InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, readonly ["auth", "user", string | undefined, "multiSession", "list", Record<string, any> | null]>, "queryFn"> & {
|
|
16
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, readonly ["auth", "user", string | undefined, "multiSession", "list", Record<string, any> | null], never> | undefined;
|
|
17
17
|
} & {
|
|
18
|
-
queryKey: readonly ["auth", "user", string | undefined, "
|
|
18
|
+
queryKey: readonly ["auth", "user", string | undefined, "multiSession", "list", Record<string, any> | null] & {
|
|
19
19
|
[dataTagSymbol]: InferData<TAuthClient["multiSession"]["listDeviceSessions"]>;
|
|
20
20
|
[dataTagErrorSymbol]: BetterFetchError;
|
|
21
21
|
};
|
|
22
22
|
}) & {
|
|
23
|
-
queryKey: DataTag<readonly ["auth", "user", string | undefined, "
|
|
23
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "multiSession", "list", Record<string, any> | null], InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, BetterFetchError>;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
26
|
* Get the current user's device sessions from the query cache, calling
|
|
@@ -73,4 +73,4 @@ export type UseListDeviceSessionsOptions<TAuthClient extends MultiSessionAuthCli
|
|
|
73
73
|
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
74
74
|
* from the nearest `QueryClientProvider`.
|
|
75
75
|
*/
|
|
76
|
-
export declare function useListDeviceSessions<TAuthClient extends MultiSessionAuthClient>(authClient: TAuthClient, options?: UseListDeviceSessionsOptions<TAuthClient>, queryClient?: QueryClient): import(
|
|
76
|
+
export declare function useListDeviceSessions<TAuthClient extends MultiSessionAuthClient>(authClient: TAuthClient, options?: UseListDeviceSessionsOptions<TAuthClient>, queryClient?: QueryClient): import("@tanstack/react-query").UseQueryResult<NoInfer<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>>, 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 { multiSessionQueryKeys } 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 device sessions.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
8
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
9
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
10
|
+
*/
|
|
11
|
+
export function listDeviceSessionsOptions(authClient, userId, params) {
|
|
12
|
+
const queryKey = multiSessionQueryKeys.list(userId, params?.query);
|
|
13
|
+
const options = queryOptions({
|
|
14
|
+
queryKey,
|
|
15
|
+
queryFn: ({ signal }) => authClient.multiSession.listDeviceSessions({
|
|
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 device sessions from the query cache, calling
|
|
24
|
+
* `fetchListDeviceSessions` under the hood if no cached entry exists.
|
|
25
|
+
* Resolves with the device session 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 with the multi-session plugin.
|
|
30
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
31
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
32
|
+
*/
|
|
33
|
+
export const ensureListDeviceSessions = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(listDeviceSessionsOptions(authClient, userId, params));
|
|
34
|
+
/**
|
|
35
|
+
* Prefetch the current user's device sessions into the query cache. Behaves
|
|
36
|
+
* like `fetchListDeviceSessions`, but does not throw on error and does not
|
|
37
|
+
* return the data — use this to warm the cache without blocking navigation.
|
|
38
|
+
*
|
|
39
|
+
* @param queryClient - The React Query client.
|
|
40
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
41
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
42
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
43
|
+
*/
|
|
44
|
+
export const prefetchListDeviceSessions = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(listDeviceSessionsOptions(authClient, userId, params));
|
|
45
|
+
/**
|
|
46
|
+
* Fetch and cache the current user's device sessions, resolving with the
|
|
47
|
+
* data or throwing on error. If a cached entry exists and is neither
|
|
48
|
+
* invalidated nor older than `staleTime`, the cached value is returned
|
|
49
|
+
* without a network call; otherwise the latest data is fetched.
|
|
50
|
+
*
|
|
51
|
+
* @param queryClient - The React Query client.
|
|
52
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
53
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
54
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
55
|
+
*/
|
|
56
|
+
export const fetchListDeviceSessions = (queryClient, authClient, userId, params) => queryClient.fetchQuery(listDeviceSessionsOptions(authClient, userId, params));
|
|
57
|
+
/**
|
|
58
|
+
* Subscribe to the current user's device sessions (multi-session account
|
|
59
|
+
* switcher) via TanStack Query.
|
|
60
|
+
*
|
|
61
|
+
* Shares a query key with the server-side `listDeviceSessionsOptions`, 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 with the multi-session plugin.
|
|
67
|
+
* @param options - `listDeviceSessions` params (`query`, `fetchOptions`)
|
|
68
|
+
* merged 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 useListDeviceSessions(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 = listDeviceSessionsOptions(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 ensureListDeviceSessions, c as fetchListDeviceSessions, a as listDeviceSessionsOptions, s as prefetchListDeviceSessions, l as useListDeviceSessions };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type DataTag, type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { BetterFetchError } from "better-auth/react";
|
|
3
|
+
import type { OrganizationAuthClient } from "../../lib/auth-client";
|
|
4
|
+
import type { FullOrganizationParams } from "./full-organization-query";
|
|
5
|
+
import type { ListOrganization } from "./list-organizations-query";
|
|
6
|
+
export type ActiveOrganizationData<TAuthClient extends OrganizationAuthClient = OrganizationAuthClient> = ListOrganization<TAuthClient>;
|
|
7
|
+
export type ActiveOrganizationParams<TAuthClient extends OrganizationAuthClient = OrganizationAuthClient> = FullOrganizationParams<TAuthClient>;
|
|
8
|
+
export type ActiveOrganizationOptions<TAuthClient extends OrganizationAuthClient = OrganizationAuthClient> = Omit<ReturnType<typeof activeOrganizationOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
9
|
+
export declare function activeOrganizationOptions<TAuthClient extends OrganizationAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ActiveOrganizationParams<TAuthClient>): (import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<ActiveOrganizationData<TAuthClient>, BetterFetchError, ActiveOrganizationData<TAuthClient>, readonly ["auth", "user", string | undefined, "organization", "active", {
|
|
10
|
+
organizationId?: string | undefined;
|
|
11
|
+
organizationSlug?: string | undefined;
|
|
12
|
+
membersLimit?: string | number | undefined;
|
|
13
|
+
} | null]>, "queryFn"> & {
|
|
14
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<ActiveOrganizationData<TAuthClient>, readonly ["auth", "user", string | undefined, "organization", "active", {
|
|
15
|
+
organizationId?: string | undefined;
|
|
16
|
+
organizationSlug?: string | undefined;
|
|
17
|
+
membersLimit?: string | number | undefined;
|
|
18
|
+
} | null], never> | undefined;
|
|
19
|
+
} & {
|
|
20
|
+
queryKey: readonly ["auth", "user", string | undefined, "organization", "active", {
|
|
21
|
+
organizationId?: string | undefined;
|
|
22
|
+
organizationSlug?: string | undefined;
|
|
23
|
+
membersLimit?: string | number | undefined;
|
|
24
|
+
} | null] & {
|
|
25
|
+
[dataTagSymbol]: ActiveOrganizationData<TAuthClient>;
|
|
26
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
27
|
+
};
|
|
28
|
+
}) & {
|
|
29
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "organization", "active", {
|
|
30
|
+
organizationId?: string | undefined;
|
|
31
|
+
organizationSlug?: string | undefined;
|
|
32
|
+
membersLimit?: string | number | undefined;
|
|
33
|
+
} | null], ActiveOrganizationData<TAuthClient>, BetterFetchError>;
|
|
34
|
+
};
|
|
35
|
+
export declare const ensureActiveOrganization: <TAuthClient extends OrganizationAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string | undefined, params?: ActiveOrganizationParams<TAuthClient>) => Promise<ActiveOrganizationData<TAuthClient>>;
|
|
36
|
+
export declare const prefetchActiveOrganization: <TAuthClient extends OrganizationAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string | undefined, params?: ActiveOrganizationParams<TAuthClient>) => Promise<void>;
|
|
37
|
+
export declare const fetchActiveOrganization: <TAuthClient extends OrganizationAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string | undefined, params?: ActiveOrganizationParams<TAuthClient>) => Promise<ActiveOrganizationData<TAuthClient>>;
|
|
38
|
+
export type UseActiveOrganizationOptions<TAuthClient extends OrganizationAuthClient> = ActiveOrganizationOptions<TAuthClient> & ActiveOrganizationParams<TAuthClient>;
|
|
39
|
+
export declare function useActiveOrganization<TAuthClient extends OrganizationAuthClient>(authClient: TAuthClient, options?: UseActiveOrganizationOptions<TAuthClient>, queryClient?: QueryClient): import("@tanstack/react-query").UseQueryResult<NoInfer<ActiveOrganizationData<TAuthClient>>, BetterFetchError>;
|