@better-auth-ui/react 1.6.9 → 1.6.11
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 +2 -2
- package/dist/components/auth/auth-provider.d.ts +4 -4
- package/dist/components/auth/email/email-changed.d.ts +2 -2
- package/dist/components/auth/email/email-verification.d.ts +2 -2
- package/dist/components/auth/email/index.d.ts +10 -10
- package/dist/components/auth/email/magic-link.d.ts +2 -2
- package/dist/components/auth/email/new-device.d.ts +2 -2
- package/dist/components/auth/email/organization-invitation.d.ts +2 -2
- package/dist/components/auth/email/otp-email.d.ts +2 -2
- package/dist/components/auth/email/password-changed.d.ts +2 -2
- package/dist/components/auth/email/reset-password.d.ts +2 -2
- package/dist/components/auth/fetch-options-provider.d.ts +1 -1
- package/dist/components/icons/apple.d.ts +1 -1
- package/dist/components/icons/atlassian.d.ts +1 -1
- package/dist/components/icons/cognito.d.ts +1 -1
- package/dist/components/icons/discord.d.ts +1 -1
- package/dist/components/icons/dropbox.d.ts +1 -1
- package/dist/components/icons/facebook.d.ts +1 -1
- package/dist/components/icons/figma.d.ts +1 -1
- package/dist/components/icons/github.d.ts +1 -1
- package/dist/components/icons/gitlab.d.ts +1 -1
- package/dist/components/icons/google.d.ts +1 -1
- package/dist/components/icons/huggingface.d.ts +1 -1
- package/dist/components/icons/index.d.ts +35 -35
- package/dist/components/icons/kakao.d.ts +1 -1
- package/dist/components/icons/kick.d.ts +1 -1
- package/dist/components/icons/line.d.ts +1 -1
- package/dist/components/icons/linear.d.ts +1 -1
- package/dist/components/icons/linkedin.d.ts +1 -1
- package/dist/components/icons/microsoft.d.ts +1 -1
- package/dist/components/icons/naver.d.ts +1 -1
- package/dist/components/icons/notion.d.ts +1 -1
- package/dist/components/icons/paybin.d.ts +1 -1
- package/dist/components/icons/paypal.d.ts +1 -1
- package/dist/components/icons/polar.d.ts +1 -1
- package/dist/components/icons/railway.d.ts +1 -1
- package/dist/components/icons/reddit.d.ts +1 -1
- package/dist/components/icons/roblox.d.ts +1 -1
- package/dist/components/icons/salesforce.d.ts +1 -1
- package/dist/components/icons/slack.d.ts +1 -1
- package/dist/components/icons/spotify.d.ts +1 -1
- package/dist/components/icons/tiktok.d.ts +1 -1
- package/dist/components/icons/twitch.d.ts +1 -1
- package/dist/components/icons/vercel.d.ts +1 -1
- package/dist/components/icons/vk.d.ts +1 -1
- package/dist/components/icons/wechat.d.ts +1 -1
- package/dist/components/icons/x.d.ts +1 -1
- package/dist/components/icons/zoom.d.ts +1 -1
- package/dist/email.d.ts +1 -1
- package/dist/email.js +1348 -1
- package/dist/hooks/auth/use-authenticate.d.ts +3 -3
- package/dist/hooks/auth/use-user.d.ts +34 -34
- package/dist/hooks/use-auth-mutation.d.ts +4 -4
- package/dist/hooks/use-auth-plugin.d.ts +1 -1
- package/dist/hooks/use-auth-query.d.ts +3 -3
- package/dist/index.d.ts +48 -48
- package/dist/index.js +2469 -47
- package/dist/lib/auth-client.d.ts +4 -4
- package/dist/lib/auth-plugin.d.ts +4 -4
- package/dist/lib/auth-server.d.ts +4 -4
- package/dist/lib/provider-icons.d.ts +2 -2
- package/dist/lib/settings-tab.d.ts +2 -2
- package/dist/lib/utils.d.ts +1 -1
- package/dist/mutations/api-key/create-api-key-mutation.d.ts +5 -5
- package/dist/mutations/api-key/delete-api-key-mutation.d.ts +5 -5
- package/dist/mutations/auth/request-password-reset-mutation.d.ts +4 -4
- package/dist/mutations/auth/reset-password-mutation.d.ts +4 -4
- package/dist/mutations/auth/send-verification-email-mutation.d.ts +4 -4
- package/dist/mutations/auth/sign-in-email-mutation.d.ts +7 -7
- package/dist/mutations/auth/sign-in-social-mutation.d.ts +6 -6
- package/dist/mutations/auth/sign-out-mutation.d.ts +5 -5
- package/dist/mutations/auth/sign-up-email-mutation.d.ts +9 -9
- package/dist/mutations/auth-mutation-options.d.ts +2 -2
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.d.ts +4 -4
- package/dist/mutations/multi-session/revoke-multi-session-mutation.d.ts +5 -5
- package/dist/mutations/multi-session/set-active-session-mutation.d.ts +5 -5
- package/dist/mutations/organization/accept-invitation-mutation.d.ts +7 -7
- package/dist/mutations/organization/cancel-invitation-mutation.d.ts +7 -7
- package/dist/mutations/organization/check-slug-mutation.d.ts +4 -4
- package/dist/mutations/organization/create-organization-mutation.d.ts +5 -5
- package/dist/mutations/organization/delete-organization-mutation.d.ts +5 -5
- package/dist/mutations/organization/index.d.ts +12 -12
- package/dist/mutations/organization/invite-member-mutation.d.ts +9 -9
- package/dist/mutations/organization/leave-organization-mutation.d.ts +5 -5
- package/dist/mutations/organization/reject-invitation-mutation.d.ts +7 -7
- package/dist/mutations/organization/remove-member-mutation.d.ts +5 -5
- package/dist/mutations/organization/set-active-organization-mutation.d.ts +7 -7
- package/dist/mutations/organization/update-member-role-mutation.d.ts +5 -5
- package/dist/mutations/organization/update-organization-mutation.d.ts +5 -5
- package/dist/mutations/passkey/add-passkey-mutation.d.ts +13 -13
- package/dist/mutations/passkey/delete-passkey-mutation.d.ts +5 -5
- package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +21 -21
- package/dist/mutations/settings/change-email-mutation.d.ts +5 -5
- package/dist/mutations/settings/change-password-mutation.d.ts +6 -6
- package/dist/mutations/settings/delete-user-mutation.d.ts +4 -4
- package/dist/mutations/settings/link-social-mutation.d.ts +4 -4
- package/dist/mutations/settings/revoke-session-mutation.d.ts +5 -5
- package/dist/mutations/settings/unlink-account-mutation.d.ts +5 -5
- package/dist/mutations/settings/update-user-mutation.d.ts +5 -5
- package/dist/mutations/username/is-username-available-mutation.d.ts +4 -4
- package/dist/mutations/username/sign-in-username-mutation.d.ts +7 -7
- package/dist/plugins/captcha-plugin.d.ts +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +27 -1
- package/dist/queries/api-key/list-api-keys-query.d.ts +6 -6
- package/dist/queries/auth/session-query.d.ts +6 -6
- package/dist/queries/auth-query-options.d.ts +2 -2
- package/dist/queries/multi-session/list-device-sessions-query.d.ts +6 -6
- package/dist/queries/organization/active-organization-query.d.ts +8 -8
- package/dist/queries/organization/full-organization-query.d.ts +6 -6
- package/dist/queries/organization/has-permission-query.d.ts +6 -6
- package/dist/queries/organization/index.d.ts +7 -7
- package/dist/queries/organization/list-invitations-query.d.ts +6 -6
- package/dist/queries/organization/list-members-query.d.ts +6 -6
- package/dist/queries/organization/list-organizations-query.d.ts +6 -6
- package/dist/queries/organization/list-user-invitations-query.d.ts +6 -6
- package/dist/queries/passkey/list-passkeys-query.d.ts +6 -6
- package/dist/queries/settings/account-info-query.d.ts +6 -6
- package/dist/queries/settings/list-accounts-query.d.ts +6 -6
- package/dist/queries/settings/list-sessions-query.d.ts +6 -6
- package/dist/server/queries/api-key/list-api-keys-query.d.ts +5 -5
- package/dist/server/queries/auth/session-query.d.ts +5 -5
- package/dist/server/queries/multi-session/list-device-sessions-query.d.ts +5 -5
- package/dist/server/queries/organization/active-organization-query.d.ts +7 -7
- package/dist/server/queries/organization/full-organization-query.d.ts +5 -5
- package/dist/server/queries/organization/has-permission-query.d.ts +5 -5
- package/dist/server/queries/organization/list-invitations-query.d.ts +5 -5
- package/dist/server/queries/organization/list-members-query.d.ts +5 -5
- package/dist/server/queries/organization/list-organizations-query.d.ts +5 -5
- package/dist/server/queries/organization/list-user-invitations-query.d.ts +5 -5
- package/dist/server/queries/passkey/list-passkeys-query.d.ts +5 -5
- package/dist/server/queries/settings/account-info-query.d.ts +5 -5
- package/dist/server/queries/settings/list-accounts-query.d.ts +5 -5
- package/dist/server/queries/settings/list-sessions-query.d.ts +5 -5
- package/dist/server.d.ts +15 -15
- package/dist/server.js +131 -14
- package/dist/use-auth-plugin-ClcP84Uz.js +80 -0
- package/package.json +2 -2
- package/dist/components/auth/auth-context.js +0 -4
- package/dist/components/auth/auth-provider.js +0 -68
- package/dist/components/auth/email/email-changed.js +0 -70
- package/dist/components/auth/email/email-localization.js +0 -26
- package/dist/components/auth/email/email-styles.js +0 -129
- package/dist/components/auth/email/email-verification.js +0 -75
- package/dist/components/auth/email/index.js +0 -10
- package/dist/components/auth/email/magic-link.js +0 -72
- package/dist/components/auth/email/new-device.js +0 -90
- package/dist/components/auth/email/organization-invitation.js +0 -110
- package/dist/components/auth/email/otp-email.js +0 -65
- package/dist/components/auth/email/password-changed.js +0 -76
- package/dist/components/auth/email/reset-password.js +0 -68
- package/dist/components/auth/fetch-options-provider.js +0 -31
- package/dist/components/icons/apple.js +0 -10
- package/dist/components/icons/atlassian.js +0 -14
- package/dist/components/icons/cognito.js +0 -10
- package/dist/components/icons/discord.js +0 -10
- package/dist/components/icons/dropbox.js +0 -10
- package/dist/components/icons/facebook.js +0 -12
- package/dist/components/icons/figma.js +0 -13
- package/dist/components/icons/github.js +0 -12
- package/dist/components/icons/gitlab.js +0 -10
- package/dist/components/icons/google.js +0 -10
- package/dist/components/icons/huggingface.js +0 -10
- package/dist/components/icons/index.js +0 -35
- package/dist/components/icons/kakao.js +0 -12
- package/dist/components/icons/kick.js +0 -12
- package/dist/components/icons/line.js +0 -10
- package/dist/components/icons/linear.js +0 -10
- package/dist/components/icons/linkedin.js +0 -10
- package/dist/components/icons/microsoft.js +0 -10
- package/dist/components/icons/naver.js +0 -10
- package/dist/components/icons/notion.js +0 -10
- package/dist/components/icons/paybin.js +0 -9
- package/dist/components/icons/paypal.js +0 -10
- package/dist/components/icons/polar.js +0 -10
- package/dist/components/icons/railway.js +0 -10
- package/dist/components/icons/reddit.js +0 -10
- package/dist/components/icons/roblox.js +0 -13
- package/dist/components/icons/salesforce.js +0 -10
- package/dist/components/icons/slack.js +0 -10
- package/dist/components/icons/spotify.js +0 -10
- package/dist/components/icons/tiktok.js +0 -11
- package/dist/components/icons/twitch.js +0 -13
- package/dist/components/icons/vercel.js +0 -10
- package/dist/components/icons/vk.js +0 -10
- package/dist/components/icons/wechat.js +0 -10
- package/dist/components/icons/x.js +0 -10
- package/dist/components/icons/zoom.js +0 -12
- package/dist/components/mutation-invalidator.js +0 -31
- package/dist/components/settings/account/theme-preview.js +0 -10
- package/dist/hooks/auth/use-authenticate.js +0 -29
- package/dist/hooks/auth/use-user.js +0 -15
- package/dist/hooks/use-auth-mutation.js +0 -19
- package/dist/hooks/use-auth-plugin.js +0 -28
- package/dist/hooks/use-auth-query.js +0 -21
- package/dist/lib/auth-client.js +0 -1
- package/dist/lib/auth-plugin.js +0 -1
- package/dist/lib/auth-server.js +0 -1
- package/dist/lib/provider-icons.js +0 -48
- package/dist/lib/settings-tab.js +0 -1
- package/dist/lib/utils.js +0 -5
- package/dist/mutations/api-key/create-api-key-mutation.js +0 -39
- package/dist/mutations/api-key/delete-api-key-mutation.js +0 -39
- package/dist/mutations/auth/request-password-reset-mutation.js +0 -33
- package/dist/mutations/auth/reset-password-mutation.js +0 -34
- package/dist/mutations/auth/send-verification-email-mutation.js +0 -33
- package/dist/mutations/auth/sign-in-email-mutation.js +0 -40
- package/dist/mutations/auth/sign-in-social-mutation.js +0 -38
- package/dist/mutations/auth/sign-out-mutation.js +0 -41
- package/dist/mutations/auth/sign-up-email-mutation.js +0 -36
- package/dist/mutations/auth-mutation-options.js +0 -23
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.js +0 -33
- package/dist/mutations/multi-session/revoke-multi-session-mutation.js +0 -39
- package/dist/mutations/multi-session/set-active-session-mutation.js +0 -40
- package/dist/mutations/organization/accept-invitation-mutation.js +0 -32
- package/dist/mutations/organization/cancel-invitation-mutation.js +0 -28
- package/dist/mutations/organization/check-slug-mutation.js +0 -30
- package/dist/mutations/organization/create-organization-mutation.js +0 -29
- package/dist/mutations/organization/delete-organization-mutation.js +0 -29
- package/dist/mutations/organization/index.js +0 -12
- package/dist/mutations/organization/invite-member-mutation.js +0 -35
- package/dist/mutations/organization/leave-organization-mutation.js +0 -32
- package/dist/mutations/organization/reject-invitation-mutation.js +0 -25
- package/dist/mutations/organization/remove-member-mutation.js +0 -29
- package/dist/mutations/organization/set-active-organization-mutation.js +0 -72
- package/dist/mutations/organization/update-member-role-mutation.js +0 -36
- package/dist/mutations/organization/update-organization-mutation.js +0 -36
- package/dist/mutations/passkey/add-passkey-mutation.js +0 -40
- package/dist/mutations/passkey/delete-passkey-mutation.js +0 -39
- package/dist/mutations/passkey/sign-in-passkey-mutation.js +0 -38
- package/dist/mutations/settings/change-email-mutation.js +0 -37
- package/dist/mutations/settings/change-password-mutation.js +0 -33
- package/dist/mutations/settings/delete-user-mutation.js +0 -33
- package/dist/mutations/settings/link-social-mutation.js +0 -33
- package/dist/mutations/settings/revoke-session-mutation.js +0 -39
- package/dist/mutations/settings/unlink-account-mutation.js +0 -39
- package/dist/mutations/settings/update-user-mutation.js +0 -36
- package/dist/mutations/username/is-username-available-mutation.js +0 -36
- package/dist/mutations/username/sign-in-username-mutation.js +0 -37
- package/dist/plugins/captcha-plugin.js +0 -34
- package/dist/queries/api-key/list-api-keys-query.js +0 -54
- package/dist/queries/auth/session-query.js +0 -72
- package/dist/queries/auth-query-options.js +0 -21
- package/dist/queries/multi-session/list-device-sessions-query.js +0 -85
- package/dist/queries/organization/active-organization-query.js +0 -37
- package/dist/queries/organization/full-organization-query.js +0 -31
- package/dist/queries/organization/has-permission-query.js +0 -38
- package/dist/queries/organization/index.js +0 -7
- package/dist/queries/organization/list-invitations-query.js +0 -37
- package/dist/queries/organization/list-members-query.js +0 -37
- package/dist/queries/organization/list-organizations-query.js +0 -31
- package/dist/queries/organization/list-user-invitations-query.js +0 -31
- package/dist/queries/passkey/list-passkeys-query.js +0 -83
- package/dist/queries/settings/account-info-query.js +0 -87
- package/dist/queries/settings/list-accounts-query.js +0 -85
- package/dist/queries/settings/list-sessions-query.js +0 -83
- package/dist/server/queries/api-key/list-api-keys-query.js +0 -49
- package/dist/server/queries/auth/session-query.js +0 -51
- package/dist/server/queries/multi-session/list-device-sessions-query.js +0 -54
- package/dist/server/queries/organization/active-organization-query.js +0 -25
- package/dist/server/queries/organization/full-organization-query.js +0 -21
- package/dist/server/queries/organization/has-permission-query.js +0 -23
- package/dist/server/queries/organization/list-invitations-query.js +0 -21
- package/dist/server/queries/organization/list-members-query.js +0 -21
- package/dist/server/queries/organization/list-organizations-query.js +0 -21
- package/dist/server/queries/organization/list-user-invitations-query.js +0 -21
- package/dist/server/queries/passkey/list-passkeys-query.js +0 -54
- package/dist/server/queries/settings/account-info-query.js +0 -54
- package/dist/server/queries/settings/list-accounts-query.js +0 -54
- package/dist/server/queries/settings/list-sessions-query.js +0 -54
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
-
import { mutationOptions, useMutation } from "@tanstack/react-query";
|
|
3
|
-
import { useSession } from "../../queries/auth/session-query";
|
|
4
|
-
/**
|
|
5
|
-
* Mutation options factory for revoking a user session.
|
|
6
|
-
*
|
|
7
|
-
* @param authClient - The Better Auth client.
|
|
8
|
-
*/
|
|
9
|
-
export function revokeSessionOptions(authClient) {
|
|
10
|
-
const mutationKey = authMutationKeys.revokeSession;
|
|
11
|
-
const mutationFn = (params) => authClient.revokeSession({
|
|
12
|
-
...params,
|
|
13
|
-
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
14
|
-
});
|
|
15
|
-
return mutationOptions({
|
|
16
|
-
mutationKey,
|
|
17
|
-
mutationFn
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create a mutation for revoking a user session.
|
|
22
|
-
*
|
|
23
|
-
* On success, `MutationInvalidator` awaits invalidation of the sessions
|
|
24
|
-
* list (see `meta.awaits`).
|
|
25
|
-
*
|
|
26
|
-
* @param authClient - The Better Auth client.
|
|
27
|
-
* @param options - React Query options forwarded to `useMutation`.
|
|
28
|
-
*/
|
|
29
|
-
export function useRevokeSession(authClient, options, queryClient) {
|
|
30
|
-
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
31
|
-
const userId = session?.user.id;
|
|
32
|
-
return useMutation({
|
|
33
|
-
...revokeSessionOptions(authClient),
|
|
34
|
-
...options,
|
|
35
|
-
meta: {
|
|
36
|
-
awaits: [authQueryKeys.listSessions(userId)]
|
|
37
|
-
}
|
|
38
|
-
}, queryClient);
|
|
39
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
-
import { mutationOptions, useMutation } from "@tanstack/react-query";
|
|
3
|
-
import { useSession } from "../../queries/auth/session-query";
|
|
4
|
-
/**
|
|
5
|
-
* Mutation options factory for unlinking a social provider from the current user.
|
|
6
|
-
*
|
|
7
|
-
* @param authClient - The Better Auth client.
|
|
8
|
-
*/
|
|
9
|
-
export function unlinkAccountOptions(authClient) {
|
|
10
|
-
const mutationKey = authMutationKeys.unlinkAccount;
|
|
11
|
-
const mutationFn = (params) => authClient.unlinkAccount({
|
|
12
|
-
...params,
|
|
13
|
-
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
14
|
-
});
|
|
15
|
-
return mutationOptions({
|
|
16
|
-
mutationKey,
|
|
17
|
-
mutationFn
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create a mutation for unlinking a social provider from the current user.
|
|
22
|
-
*
|
|
23
|
-
* On success, `MutationInvalidator` awaits invalidation of the linked
|
|
24
|
-
* accounts list (see `meta.awaits`).
|
|
25
|
-
*
|
|
26
|
-
* @param authClient - The Better Auth client.
|
|
27
|
-
* @param options - React Query options forwarded to `useMutation`.
|
|
28
|
-
*/
|
|
29
|
-
export function useUnlinkAccount(authClient, options, queryClient) {
|
|
30
|
-
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
31
|
-
const userId = session?.user.id;
|
|
32
|
-
return useMutation({
|
|
33
|
-
...unlinkAccountOptions(authClient),
|
|
34
|
-
...options,
|
|
35
|
-
meta: {
|
|
36
|
-
awaits: [authQueryKeys.listAccounts(userId)]
|
|
37
|
-
}
|
|
38
|
-
}, queryClient);
|
|
39
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
-
import { mutationOptions, useMutation } from "@tanstack/react-query";
|
|
3
|
-
/**
|
|
4
|
-
* Mutation options factory for updating the authenticated user's profile.
|
|
5
|
-
*
|
|
6
|
-
* @param authClient - The Better Auth client.
|
|
7
|
-
*/
|
|
8
|
-
export function updateUserOptions(authClient) {
|
|
9
|
-
const mutationKey = authMutationKeys.updateUser;
|
|
10
|
-
const mutationFn = (params) => authClient.updateUser({
|
|
11
|
-
...params,
|
|
12
|
-
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
13
|
-
});
|
|
14
|
-
return mutationOptions({
|
|
15
|
-
mutationKey,
|
|
16
|
-
mutationFn
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Create a mutation for updating the authenticated user's profile.
|
|
21
|
-
*
|
|
22
|
-
* On success, `MutationInvalidator` awaits invalidation of the session
|
|
23
|
-
* query so the updated user fields are reflected (see `meta.awaits`).
|
|
24
|
-
*
|
|
25
|
-
* @param authClient - The Better Auth client.
|
|
26
|
-
* @param options - React Query options forwarded to `useMutation`.
|
|
27
|
-
*/
|
|
28
|
-
export function useUpdateUser(authClient, options, queryClient) {
|
|
29
|
-
return useMutation({
|
|
30
|
-
...updateUserOptions(authClient),
|
|
31
|
-
...options,
|
|
32
|
-
meta: {
|
|
33
|
-
awaits: [authQueryKeys.session]
|
|
34
|
-
}
|
|
35
|
-
}, queryClient);
|
|
36
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { usernameMutationKeys } from "@better-auth-ui/core/plugins";
|
|
2
|
-
import { mutationOptions, useMutation } from "@tanstack/react-query";
|
|
3
|
-
/**
|
|
4
|
-
* Mutation options factory for checking username availability.
|
|
5
|
-
*
|
|
6
|
-
* Modeled as a mutation because callers typically trigger the check on
|
|
7
|
-
* user action (debounced input, form submit) rather than on mount.
|
|
8
|
-
*
|
|
9
|
-
* @param authClient - The Better Auth client.
|
|
10
|
-
*/
|
|
11
|
-
export function isUsernameAvailableOptions(authClient) {
|
|
12
|
-
const mutationKey = usernameMutationKeys.isUsernameAvailable;
|
|
13
|
-
const mutationFn = (params) => authClient.isUsernameAvailable({
|
|
14
|
-
...params,
|
|
15
|
-
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
16
|
-
});
|
|
17
|
-
return mutationOptions({
|
|
18
|
-
mutationKey,
|
|
19
|
-
mutationFn
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a mutation for checking whether a username is available.
|
|
24
|
-
*
|
|
25
|
-
* Wraps `authClient.isUsernameAvailable` and forwards React Query mutation
|
|
26
|
-
* options such as `onSuccess`, `onError`, and `retry`.
|
|
27
|
-
*
|
|
28
|
-
* @param authClient - The Better Auth client with the username plugin.
|
|
29
|
-
* @param options - React Query options forwarded to `useMutation`.
|
|
30
|
-
*/
|
|
31
|
-
export function useIsUsernameAvailable(authClient, options) {
|
|
32
|
-
return useMutation({
|
|
33
|
-
...isUsernameAvailableOptions(authClient),
|
|
34
|
-
...options
|
|
35
|
-
});
|
|
36
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { authQueryKeys } from "@better-auth-ui/core";
|
|
2
|
-
import { usernameMutationKeys } from "@better-auth-ui/core/plugins";
|
|
3
|
-
import { mutationOptions, useMutation } from "@tanstack/react-query";
|
|
4
|
-
/**
|
|
5
|
-
* Mutation options factory for username/password sign-in.
|
|
6
|
-
*
|
|
7
|
-
* @param authClient - The Better Auth client.
|
|
8
|
-
*/
|
|
9
|
-
export function signInUsernameOptions(authClient) {
|
|
10
|
-
const mutationKey = usernameMutationKeys.signIn;
|
|
11
|
-
const mutationFn = (params) => authClient.signIn.username({
|
|
12
|
-
...params,
|
|
13
|
-
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
14
|
-
});
|
|
15
|
-
return mutationOptions({
|
|
16
|
-
mutationKey,
|
|
17
|
-
mutationFn
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create a mutation for username/password sign-in.
|
|
22
|
-
*
|
|
23
|
-
* On success, `MutationInvalidator` awaits invalidation of the session
|
|
24
|
-
* query so the new session is refetched (see `meta.awaits`).
|
|
25
|
-
*
|
|
26
|
-
* @param authClient - The Better Auth client with the username plugin.
|
|
27
|
-
* @param options - React Query options forwarded to `useMutation`.
|
|
28
|
-
*/
|
|
29
|
-
export function useSignInUsername(authClient, options, queryClient) {
|
|
30
|
-
return useMutation({
|
|
31
|
-
...signInUsernameOptions(authClient),
|
|
32
|
-
...options,
|
|
33
|
-
meta: {
|
|
34
|
-
awaits: [authQueryKeys.session]
|
|
35
|
-
}
|
|
36
|
-
}, queryClient);
|
|
37
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
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 }));
|
|
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, {})
|
|
34
|
-
}));
|
|
@@ -1,54 +0,0 @@
|
|
|
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;
|
|
25
|
-
}
|
|
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);
|
|
54
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
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;
|
|
22
|
-
}
|
|
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);
|
|
72
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
});
|
|
21
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
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;
|
|
21
|
-
}
|
|
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);
|
|
85
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { organizationPlugin, organizationQueryKeys } from "@better-auth-ui/core/plugins";
|
|
2
|
-
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { useAuthPlugin } from "../../hooks/use-auth-plugin";
|
|
4
|
-
import { useSession } from "../auth/session-query";
|
|
5
|
-
export function activeOrganizationOptions(authClient, userId, params) {
|
|
6
|
-
const queryKey = organizationQueryKeys.activeOrganization(userId, params?.query);
|
|
7
|
-
const options = queryOptions({
|
|
8
|
-
queryKey,
|
|
9
|
-
queryFn: ({ signal }) => authClient.organization.getFullOrganization({
|
|
10
|
-
...params,
|
|
11
|
-
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
return options;
|
|
15
|
-
}
|
|
16
|
-
export const ensureActiveOrganization = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(activeOrganizationOptions(authClient, userId, params));
|
|
17
|
-
export const prefetchActiveOrganization = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(activeOrganizationOptions(authClient, userId, params));
|
|
18
|
-
export const fetchActiveOrganization = (queryClient, authClient, userId, params) => queryClient.fetchQuery(activeOrganizationOptions(authClient, userId, params));
|
|
19
|
-
export function useActiveOrganization(authClient, options = {}, queryClient) {
|
|
20
|
-
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
21
|
-
const userId = session?.user.id;
|
|
22
|
-
const { slug } = useAuthPlugin(organizationPlugin);
|
|
23
|
-
const { query, fetchOptions, ...queryOptions } = options;
|
|
24
|
-
const baseOptions = activeOrganizationOptions(authClient, userId, {
|
|
25
|
-
fetchOptions,
|
|
26
|
-
query: slug ? { organizationSlug: slug } : query
|
|
27
|
-
});
|
|
28
|
-
return useQuery({
|
|
29
|
-
...queryOptions,
|
|
30
|
-
...baseOptions,
|
|
31
|
-
queryFn: slug === null
|
|
32
|
-
? async () => null
|
|
33
|
-
: userId
|
|
34
|
-
? baseOptions.queryFn
|
|
35
|
-
: skipToken
|
|
36
|
-
}, queryClient);
|
|
37
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { organizationQueryKeys } from "@better-auth-ui/core/plugins";
|
|
2
|
-
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { useSession } from "../auth/session-query";
|
|
4
|
-
export function fullOrganizationOptions(authClient, userId, params) {
|
|
5
|
-
const queryKey = organizationQueryKeys.fullDetail(userId, params?.query);
|
|
6
|
-
const options = queryOptions({
|
|
7
|
-
queryKey,
|
|
8
|
-
queryFn: ({ signal }) => authClient.organization.getFullOrganization({
|
|
9
|
-
...params,
|
|
10
|
-
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
11
|
-
})
|
|
12
|
-
});
|
|
13
|
-
return options;
|
|
14
|
-
}
|
|
15
|
-
export const ensureFullOrganization = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(fullOrganizationOptions(authClient, userId, params));
|
|
16
|
-
export const prefetchFullOrganization = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(fullOrganizationOptions(authClient, userId, params));
|
|
17
|
-
export const fetchFullOrganization = (queryClient, authClient, userId, params) => queryClient.fetchQuery(fullOrganizationOptions(authClient, userId, params));
|
|
18
|
-
export function useFullOrganization(authClient, options = {}, queryClient) {
|
|
19
|
-
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
20
|
-
const userId = session?.user.id;
|
|
21
|
-
const { query, fetchOptions, ...queryOptions } = options;
|
|
22
|
-
const baseOptions = fullOrganizationOptions(authClient, userId, {
|
|
23
|
-
query,
|
|
24
|
-
fetchOptions
|
|
25
|
-
});
|
|
26
|
-
return useQuery({
|
|
27
|
-
...queryOptions,
|
|
28
|
-
...baseOptions,
|
|
29
|
-
queryFn: userId ? baseOptions.queryFn : skipToken
|
|
30
|
-
}, queryClient);
|
|
31
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { organizationQueryKeys } from "@better-auth-ui/core/plugins";
|
|
2
|
-
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { useSession } from "../auth/session-query";
|
|
4
|
-
import { useActiveOrganization } from "./active-organization-query";
|
|
5
|
-
export function hasPermissionOptions(authClient, userId, params) {
|
|
6
|
-
// `hasPermission` is the only org client method without a `query` field — its
|
|
7
|
-
// params are flat — so the "query" portion is everything except `fetchOptions`.
|
|
8
|
-
const { fetchOptions, ...query } = params;
|
|
9
|
-
const queryKey = organizationQueryKeys.permissions.has(userId, query);
|
|
10
|
-
const options = queryOptions({
|
|
11
|
-
queryKey,
|
|
12
|
-
queryFn: ({ signal }) => authClient.organization.hasPermission({
|
|
13
|
-
...query,
|
|
14
|
-
fetchOptions: { ...fetchOptions, signal, throw: true }
|
|
15
|
-
})
|
|
16
|
-
});
|
|
17
|
-
return options;
|
|
18
|
-
}
|
|
19
|
-
export const ensureHasPermission = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(hasPermissionOptions(authClient, userId, params));
|
|
20
|
-
export const prefetchHasPermission = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(hasPermissionOptions(authClient, userId, params));
|
|
21
|
-
export const fetchHasPermission = (queryClient, authClient, userId, params) => queryClient.fetchQuery(hasPermissionOptions(authClient, userId, params));
|
|
22
|
-
export function useHasPermission(authClient, options, queryClient) {
|
|
23
|
-
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
24
|
-
const userId = session?.user.id;
|
|
25
|
-
const { fetchOptions, permissions, organizationId: optionsOrganizationId, ...queryOptions } = options;
|
|
26
|
-
const { data: activeOrganization } = useActiveOrganization(authClient, { enabled: !optionsOrganizationId }, queryClient);
|
|
27
|
-
const organizationId = optionsOrganizationId ?? activeOrganization?.id;
|
|
28
|
-
const baseOptions = hasPermissionOptions(authClient, userId, {
|
|
29
|
-
fetchOptions,
|
|
30
|
-
organizationId,
|
|
31
|
-
permissions
|
|
32
|
-
});
|
|
33
|
-
return useQuery({
|
|
34
|
-
...queryOptions,
|
|
35
|
-
...baseOptions,
|
|
36
|
-
queryFn: userId && organizationId ? baseOptions.queryFn : skipToken
|
|
37
|
-
}, queryClient);
|
|
38
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from "./active-organization-query";
|
|
2
|
-
export * from "./full-organization-query";
|
|
3
|
-
export * from "./has-permission-query";
|
|
4
|
-
export * from "./list-invitations-query";
|
|
5
|
-
export * from "./list-members-query";
|
|
6
|
-
export * from "./list-organizations-query";
|
|
7
|
-
export * from "./list-user-invitations-query";
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { organizationQueryKeys } from "@better-auth-ui/core/plugins";
|
|
2
|
-
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { useSession } from "../auth/session-query";
|
|
4
|
-
import { useActiveOrganization } from "./active-organization-query";
|
|
5
|
-
export function listOrganizationInvitationsOptions(authClient, userId, params) {
|
|
6
|
-
const queryKey = organizationQueryKeys.invitations.list(userId, params?.query);
|
|
7
|
-
const options = queryOptions({
|
|
8
|
-
queryKey,
|
|
9
|
-
queryFn: ({ signal }) => authClient.organization.listInvitations({
|
|
10
|
-
...params,
|
|
11
|
-
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
return options;
|
|
15
|
-
}
|
|
16
|
-
export const ensureListOrganizationInvitations = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(listOrganizationInvitationsOptions(authClient, userId, params));
|
|
17
|
-
export const prefetchListOrganizationInvitations = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(listOrganizationInvitationsOptions(authClient, userId, params));
|
|
18
|
-
export const fetchListOrganizationInvitations = (queryClient, authClient, userId, params) => queryClient.fetchQuery(listOrganizationInvitationsOptions(authClient, userId, params));
|
|
19
|
-
export function useListOrganizationInvitations(authClient, options = {}, queryClient) {
|
|
20
|
-
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
21
|
-
const userId = session?.user.id;
|
|
22
|
-
const { query, fetchOptions, ...queryOptions } = options;
|
|
23
|
-
const { data: activeOrganization } = useActiveOrganization(authClient, { enabled: !query?.organizationId }, queryClient);
|
|
24
|
-
const organizationId = query?.organizationId ?? activeOrganization?.id;
|
|
25
|
-
const baseOptions = listOrganizationInvitationsOptions(authClient, userId, {
|
|
26
|
-
query: {
|
|
27
|
-
...query,
|
|
28
|
-
organizationId
|
|
29
|
-
},
|
|
30
|
-
fetchOptions
|
|
31
|
-
});
|
|
32
|
-
return useQuery({
|
|
33
|
-
...queryOptions,
|
|
34
|
-
...baseOptions,
|
|
35
|
-
queryFn: userId && organizationId ? baseOptions.queryFn : skipToken
|
|
36
|
-
}, queryClient);
|
|
37
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { organizationQueryKeys } from "@better-auth-ui/core/plugins";
|
|
2
|
-
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { useSession } from "../auth/session-query";
|
|
4
|
-
import { useActiveOrganization } from "./active-organization-query";
|
|
5
|
-
export function listOrganizationMembersOptions(authClient, userId, params) {
|
|
6
|
-
const queryKey = organizationQueryKeys.members.list(userId, params?.query);
|
|
7
|
-
const options = queryOptions({
|
|
8
|
-
queryKey,
|
|
9
|
-
queryFn: ({ signal }) => authClient.organization.listMembers({
|
|
10
|
-
...params,
|
|
11
|
-
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
return options;
|
|
15
|
-
}
|
|
16
|
-
export const ensureListOrganizationMembers = (queryClient, authClient, userId, params) => queryClient.ensureQueryData(listOrganizationMembersOptions(authClient, userId, params));
|
|
17
|
-
export const prefetchListOrganizationMembers = (queryClient, authClient, userId, params) => queryClient.prefetchQuery(listOrganizationMembersOptions(authClient, userId, params));
|
|
18
|
-
export const fetchListOrganizationMembers = (queryClient, authClient, userId, params) => queryClient.fetchQuery(listOrganizationMembersOptions(authClient, userId, params));
|
|
19
|
-
export function useListOrganizationMembers(authClient, options = {}, queryClient) {
|
|
20
|
-
const { data: session } = useSession(authClient, undefined, queryClient);
|
|
21
|
-
const userId = session?.user.id;
|
|
22
|
-
const { query, fetchOptions, ...queryOptions } = options;
|
|
23
|
-
const { data: activeOrganization } = useActiveOrganization(authClient, { enabled: !query?.organizationId }, queryClient);
|
|
24
|
-
const organizationId = query?.organizationId ?? activeOrganization?.id;
|
|
25
|
-
const baseOptions = listOrganizationMembersOptions(authClient, userId, {
|
|
26
|
-
query: {
|
|
27
|
-
...query,
|
|
28
|
-
organizationId
|
|
29
|
-
},
|
|
30
|
-
fetchOptions
|
|
31
|
-
});
|
|
32
|
-
return useQuery({
|
|
33
|
-
...queryOptions,
|
|
34
|
-
...baseOptions,
|
|
35
|
-
queryFn: userId && organizationId ? baseOptions.queryFn : skipToken
|
|
36
|
-
}, queryClient);
|
|
37
|
-
}
|