@better-auth-ui/solid 1.6.19
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/email/email-changed.d.ts +59 -0
- package/dist/components/auth/email/email-changed.js +264 -0
- package/dist/components/auth/email/email-styles.d.ts +48 -0
- package/dist/components/auth/email/email-styles.js +107 -0
- package/dist/components/auth/email/email-verification.d.ts +51 -0
- package/dist/components/auth/email/email-verification.js +212 -0
- package/dist/components/auth/email/index.d.ts +9 -0
- package/dist/components/auth/email/magic-link.d.ts +53 -0
- package/dist/components/auth/email/magic-link.js +213 -0
- package/dist/components/auth/email/new-device.d.ts +77 -0
- package/dist/components/auth/email/new-device.js +326 -0
- package/dist/components/auth/email/organization-invitation.d.ts +70 -0
- package/dist/components/auth/email/organization-invitation.js +260 -0
- package/dist/components/auth/email/otp-email.d.ts +49 -0
- package/dist/components/auth/email/otp-email.js +191 -0
- package/dist/components/auth/email/password-changed.d.ts +56 -0
- package/dist/components/auth/email/password-changed.js +236 -0
- package/dist/components/auth/email/reset-password.d.ts +51 -0
- package/dist/components/auth/email/reset-password.js +212 -0
- package/dist/email.d.ts +18 -0
- package/dist/email.js +10 -0
- package/dist/hooks/auth/use-authenticate.d.ts +3 -0
- package/dist/hooks/auth/use-authenticate.js +18 -0
- package/dist/hooks/auth/use-sign-out.d.ts +2 -0
- package/dist/hooks/auth/use-sign-out.js +17 -0
- package/dist/hooks/auth/use-user.d.ts +213 -0
- package/dist/hooks/auth/use-user.js +13 -0
- package/dist/hooks/use-auth-mutation.d.ts +6 -0
- package/dist/hooks/use-auth-mutation.js +11 -0
- package/dist/hooks/use-auth-query.d.ts +5 -0
- package/dist/hooks/use-auth-query.js +17 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +68 -0
- package/dist/lib/auth-client.d.ts +26 -0
- package/dist/lib/auth-config.d.ts +12 -0
- package/dist/lib/auth-config.js +21 -0
- package/dist/lib/auth-plugin.d.ts +16 -0
- package/dist/lib/auth-provider.d.ts +12 -0
- package/dist/lib/auth-provider.js +36 -0
- package/dist/lib/auth-server.d.ts +16 -0
- package/dist/lib/auth-utils.d.ts +3 -0
- package/dist/lib/auth-utils.js +12 -0
- package/dist/lib/fetch-options-provider.d.ts +23 -0
- package/dist/lib/fetch-options-provider.js +29 -0
- package/dist/lib/mutation-invalidator.d.ts +11 -0
- package/dist/lib/mutation-invalidator.js +20 -0
- package/dist/lib/provider-icons.d.ts +8 -0
- package/dist/lib/provider-icons.js +5 -0
- package/dist/mutations/api-key/create-api-key-mutation.d.ts +71 -0
- package/dist/mutations/api-key/create-api-key-mutation.js +12 -0
- package/dist/mutations/api-key/delete-api-key-mutation.d.ts +23 -0
- package/dist/mutations/api-key/delete-api-key-mutation.js +12 -0
- package/dist/mutations/auth/request-password-reset-mutation.d.ts +11 -0
- package/dist/mutations/auth/request-password-reset-mutation.js +8 -0
- package/dist/mutations/auth/reset-password-mutation.d.ts +13 -0
- package/dist/mutations/auth/reset-password-mutation.js +8 -0
- package/dist/mutations/auth/send-verification-email-mutation.d.ts +11 -0
- package/dist/mutations/auth/send-verification-email-mutation.js +8 -0
- package/dist/mutations/auth/sign-in-email-mutation.d.ts +15 -0
- package/dist/mutations/auth/sign-in-email-mutation.js +8 -0
- package/dist/mutations/auth/sign-in-social-mutation.d.ts +53 -0
- package/dist/mutations/auth/sign-in-social-mutation.js +8 -0
- package/dist/mutations/auth/sign-out-mutation.d.ts +6 -0
- package/dist/mutations/auth/sign-out-mutation.js +8 -0
- package/dist/mutations/auth/sign-up-email-mutation.d.ts +17 -0
- package/dist/mutations/auth/sign-up-email-mutation.js +8 -0
- package/dist/mutations/auth-mutation-options.d.ts +10 -0
- package/dist/mutations/auth-mutation-options.js +19 -0
- package/dist/mutations/create-auth-mutation.d.ts +10 -0
- package/dist/mutations/create-auth-mutation.js +20 -0
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.d.ts +19 -0
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.js +8 -0
- package/dist/mutations/multi-session/revoke-multi-session-mutation.d.ts +19 -0
- package/dist/mutations/multi-session/revoke-multi-session-mutation.js +12 -0
- package/dist/mutations/multi-session/set-active-session-mutation.d.ts +19 -0
- package/dist/mutations/multi-session/set-active-session-mutation.js +13 -0
- package/dist/mutations/organization/accept-invitation-mutation.d.ts +18 -0
- package/dist/mutations/organization/accept-invitation-mutation.js +12 -0
- package/dist/mutations/organization/cancel-invitation-mutation.d.ts +18 -0
- package/dist/mutations/organization/cancel-invitation-mutation.js +12 -0
- package/dist/mutations/organization/check-slug-mutation.d.ts +18 -0
- package/dist/mutations/organization/check-slug-mutation.js +15 -0
- package/dist/mutations/organization/create-organization-mutation.d.ts +38 -0
- package/dist/mutations/organization/create-organization-mutation.js +12 -0
- package/dist/mutations/organization/delete-organization-mutation.d.ts +18 -0
- package/dist/mutations/organization/delete-organization-mutation.js +12 -0
- package/dist/mutations/organization/index.d.ts +13 -0
- package/dist/mutations/organization/index.js +13 -0
- package/dist/mutations/organization/invite-member-mutation.d.ts +30 -0
- package/dist/mutations/organization/invite-member-mutation.js +12 -0
- package/dist/mutations/organization/leave-organization-mutation.d.ts +18 -0
- package/dist/mutations/organization/leave-organization-mutation.js +12 -0
- package/dist/mutations/organization/metadata.d.ts +13 -0
- package/dist/mutations/organization/metadata.js +27 -0
- package/dist/mutations/organization/reject-invitation-mutation.d.ts +18 -0
- package/dist/mutations/organization/reject-invitation-mutation.js +12 -0
- package/dist/mutations/organization/remove-member-mutation.d.ts +22 -0
- package/dist/mutations/organization/remove-member-mutation.js +12 -0
- package/dist/mutations/organization/set-active-organization-mutation.d.ts +24 -0
- package/dist/mutations/organization/set-active-organization-mutation.js +35 -0
- package/dist/mutations/organization/update-member-role-mutation.d.ts +26 -0
- package/dist/mutations/organization/update-member-role-mutation.js +12 -0
- package/dist/mutations/organization/update-organization-mutation.d.ts +42 -0
- package/dist/mutations/organization/update-organization-mutation.js +12 -0
- package/dist/mutations/organization/utils.d.ts +8 -0
- package/dist/mutations/organization/utils.js +17 -0
- package/dist/mutations/passkey/add-passkey-mutation.d.ts +73 -0
- package/dist/mutations/passkey/add-passkey-mutation.js +12 -0
- package/dist/mutations/passkey/delete-passkey-mutation.d.ts +19 -0
- package/dist/mutations/passkey/delete-passkey-mutation.js +12 -0
- package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +50 -0
- package/dist/mutations/passkey/sign-in-passkey-mutation.js +9 -0
- package/dist/mutations/settings/change-email-mutation.d.ts +11 -0
- package/dist/mutations/settings/change-email-mutation.js +8 -0
- package/dist/mutations/settings/change-password-mutation.d.ts +13 -0
- package/dist/mutations/settings/change-password-mutation.js +8 -0
- package/dist/mutations/settings/delete-user-mutation.d.ts +13 -0
- package/dist/mutations/settings/delete-user-mutation.js +8 -0
- package/dist/mutations/settings/link-social-mutation.d.ts +35 -0
- package/dist/mutations/settings/link-social-mutation.js +8 -0
- package/dist/mutations/settings/revoke-session-mutation.d.ts +19 -0
- package/dist/mutations/settings/revoke-session-mutation.js +12 -0
- package/dist/mutations/settings/unlink-account-mutation.d.ts +23 -0
- package/dist/mutations/settings/unlink-account-mutation.js +12 -0
- package/dist/mutations/settings/update-user-mutation.d.ts +6 -0
- package/dist/mutations/settings/update-user-mutation.js +8 -0
- package/dist/mutations/use-session-scoped-mutation.d.ts +17 -0
- package/dist/mutations/use-session-scoped-mutation.js +17 -0
- package/dist/mutations/username/is-username-available-mutation.d.ts +9 -0
- package/dist/mutations/username/is-username-available-mutation.js +8 -0
- package/dist/mutations/username/sign-in-username-mutation.d.ts +15 -0
- package/dist/mutations/username/sign-in-username-mutation.js +9 -0
- package/dist/plugins/captcha-plugin.d.ts +29 -0
- package/dist/plugins/captcha-plugin.js +26 -0
- package/dist/plugins.d.ts +2 -0
- package/dist/plugins.js +2 -0
- package/dist/queries/api-key/list-api-keys-query.d.ts +44 -0
- package/dist/queries/api-key/list-api-keys-query.js +17 -0
- package/dist/queries/auth/session-query.d.ts +22 -0
- package/dist/queries/auth/session-query.js +32 -0
- package/dist/queries/auth-query-options.d.ts +14 -0
- package/dist/queries/auth-query-options.js +17 -0
- package/dist/queries/create-user-scoped-query.d.ts +25 -0
- package/dist/queries/create-user-scoped-query.js +29 -0
- package/dist/queries/multi-session/list-device-sessions-query.d.ts +23 -0
- package/dist/queries/multi-session/list-device-sessions-query.js +17 -0
- package/dist/queries/organization/active-organization-query.d.ts +37 -0
- package/dist/queries/organization/active-organization-query.js +26 -0
- package/dist/queries/organization/full-organization-query.d.ts +35 -0
- package/dist/queries/organization/full-organization-query.js +25 -0
- package/dist/queries/organization/has-permission-query.d.ts +23 -0
- package/dist/queries/organization/has-permission-query.js +31 -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 +29 -0
- package/dist/queries/organization/list-members-query.d.ts +53 -0
- package/dist/queries/organization/list-members-query.js +29 -0
- package/dist/queries/organization/list-organizations-query.d.ts +23 -0
- package/dist/queries/organization/list-organizations-query.js +25 -0
- package/dist/queries/organization/list-user-invitations-query.d.ts +29 -0
- package/dist/queries/organization/list-user-invitations-query.js +25 -0
- package/dist/queries/organization/plugin.d.ts +1 -0
- package/dist/queries/organization/plugin.js +8 -0
- package/dist/queries/organization/utils.d.ts +16 -0
- package/dist/queries/organization/utils.js +18 -0
- package/dist/queries/passkey/list-passkeys-query.d.ts +23 -0
- package/dist/queries/passkey/list-passkeys-query.js +17 -0
- package/dist/queries/settings/account-info-query.d.ts +35 -0
- package/dist/queries/settings/account-info-query.js +17 -0
- package/dist/queries/settings/list-accounts-query.d.ts +23 -0
- package/dist/queries/settings/list-accounts-query.js +17 -0
- package/dist/queries/settings/list-sessions-query.d.ts +24 -0
- package/dist/queries/settings/list-sessions-query.js +17 -0
- package/dist/server/queries/auth/session-query.d.ts +19 -0
- package/dist/server/queries/auth/session-query.js +13 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +7 -0
- package/package.json +63 -0
- package/src/components/auth/email/email-changed.tsx +305 -0
- package/src/components/auth/email/email-styles.tsx +139 -0
- package/src/components/auth/email/email-verification.tsx +249 -0
- package/src/components/auth/email/index.ts +9 -0
- package/src/components/auth/email/magic-link.tsx +254 -0
- package/src/components/auth/email/new-device.tsx +347 -0
- package/src/components/auth/email/organization-invitation.tsx +322 -0
- package/src/components/auth/email/otp-email.tsx +239 -0
- package/src/components/auth/email/password-changed.tsx +279 -0
- package/src/components/auth/email/reset-password.tsx +250 -0
- package/src/email.ts +49 -0
- package/src/hooks/auth/use-authenticate.ts +30 -0
- package/src/hooks/auth/use-sign-out.ts +23 -0
- package/src/hooks/auth/use-user.ts +19 -0
- package/src/hooks/use-auth-mutation.ts +35 -0
- package/src/hooks/use-auth-query.ts +33 -0
- package/src/index.ts +48 -0
- package/src/lib/auth-client.ts +43 -0
- package/src/lib/auth-config.ts +46 -0
- package/src/lib/auth-plugin.ts +20 -0
- package/src/lib/auth-provider.tsx +60 -0
- package/src/lib/auth-server.ts +25 -0
- package/src/lib/auth-utils.ts +25 -0
- package/src/lib/fetch-options-provider.tsx +77 -0
- package/src/lib/mutation-invalidator.tsx +82 -0
- package/src/lib/provider-icons.ts +10 -0
- package/src/mutations/api-key/create-api-key-mutation.ts +40 -0
- package/src/mutations/api-key/delete-api-key-mutation.ts +40 -0
- package/src/mutations/auth/request-password-reset-mutation.ts +15 -0
- package/src/mutations/auth/reset-password-mutation.ts +16 -0
- package/src/mutations/auth/send-verification-email-mutation.ts +15 -0
- package/src/mutations/auth/sign-in-email-mutation.ts +17 -0
- package/src/mutations/auth/sign-in-social-mutation.ts +16 -0
- package/src/mutations/auth/sign-out-mutation.ts +13 -0
- package/src/mutations/auth/sign-up-email-mutation.ts +17 -0
- package/src/mutations/auth-mutation-options.ts +62 -0
- package/src/mutations/create-auth-mutation.ts +44 -0
- package/src/mutations/magic-link/sign-in-magic-link-mutation.ts +15 -0
- package/src/mutations/multi-session/revoke-multi-session-mutation.ts +40 -0
- package/src/mutations/multi-session/set-active-session-mutation.ts +43 -0
- package/src/mutations/organization/accept-invitation-mutation.ts +38 -0
- package/src/mutations/organization/cancel-invitation-mutation.ts +38 -0
- package/src/mutations/organization/check-slug-mutation.ts +36 -0
- package/src/mutations/organization/create-organization-mutation.ts +37 -0
- package/src/mutations/organization/delete-organization-mutation.ts +37 -0
- package/src/mutations/organization/index.ts +13 -0
- package/src/mutations/organization/invite-member-mutation.ts +38 -0
- package/src/mutations/organization/leave-organization-mutation.ts +37 -0
- package/src/mutations/organization/metadata.ts +103 -0
- package/src/mutations/organization/reject-invitation-mutation.ts +38 -0
- package/src/mutations/organization/remove-member-mutation.ts +38 -0
- package/src/mutations/organization/set-active-organization-mutation.ts +110 -0
- package/src/mutations/organization/update-member-role-mutation.ts +38 -0
- package/src/mutations/organization/update-organization-mutation.ts +37 -0
- package/src/mutations/organization/utils.ts +51 -0
- package/src/mutations/passkey/add-passkey-mutation.ts +40 -0
- package/src/mutations/passkey/delete-passkey-mutation.ts +40 -0
- package/src/mutations/passkey/sign-in-passkey-mutation.ts +17 -0
- package/src/mutations/settings/change-email-mutation.ts +17 -0
- package/src/mutations/settings/change-password-mutation.ts +16 -0
- package/src/mutations/settings/delete-user-mutation.ts +16 -0
- package/src/mutations/settings/link-social-mutation.ts +16 -0
- package/src/mutations/settings/revoke-session-mutation.ts +38 -0
- package/src/mutations/settings/unlink-account-mutation.ts +38 -0
- package/src/mutations/settings/update-user-mutation.ts +17 -0
- package/src/mutations/use-session-scoped-mutation.ts +64 -0
- package/src/mutations/username/is-username-available-mutation.ts +15 -0
- package/src/mutations/username/sign-in-username-mutation.ts +17 -0
- package/src/plugins/captcha-plugin.tsx +64 -0
- package/src/plugins.ts +2 -0
- package/src/queries/api-key/list-api-keys-query.ts +93 -0
- package/src/queries/auth/session-query.ts +81 -0
- package/src/queries/auth-query-options.ts +57 -0
- package/src/queries/create-user-scoped-query.ts +107 -0
- package/src/queries/multi-session/list-device-sessions-query.ts +107 -0
- package/src/queries/organization/active-organization-query.ts +127 -0
- package/src/queries/organization/full-organization-query.ts +111 -0
- package/src/queries/organization/has-permission-query.ts +121 -0
- package/src/queries/organization/index.ts +7 -0
- package/src/queries/organization/list-invitations-query.ts +124 -0
- package/src/queries/organization/list-members-query.ts +124 -0
- package/src/queries/organization/list-organizations-query.ts +113 -0
- package/src/queries/organization/list-user-invitations-query.ts +114 -0
- package/src/queries/organization/plugin.ts +11 -0
- package/src/queries/organization/utils.ts +88 -0
- package/src/queries/passkey/list-passkeys-query.ts +93 -0
- package/src/queries/settings/account-info-query.ts +94 -0
- package/src/queries/settings/list-accounts-query.ts +94 -0
- package/src/queries/settings/list-sessions-query.ts +96 -0
- package/src/server/queries/auth/session-query.ts +56 -0
- package/src/server.ts +7 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
passkeyMutationKeys,
|
|
3
|
+
passkeyQueryKeys
|
|
4
|
+
} from "@better-auth-ui/core/plugins"
|
|
5
|
+
import type { PasskeyAuthClient } from "../../lib/auth-client"
|
|
6
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
7
|
+
import { useSessionScopedMutation } from "../use-session-scoped-mutation"
|
|
8
|
+
|
|
9
|
+
export type AddPasskeyParams<TAuthClient extends PasskeyAuthClient> =
|
|
10
|
+
Parameters<TAuthClient["passkey"]["addPasskey"]>[0]
|
|
11
|
+
|
|
12
|
+
export type AddPasskeyOptions = Parameters<
|
|
13
|
+
typeof useSessionScopedMutation<
|
|
14
|
+
PasskeyAuthClient,
|
|
15
|
+
PasskeyAuthClient["passkey"]["addPasskey"],
|
|
16
|
+
typeof passkeyMutationKeys.addPasskey
|
|
17
|
+
>
|
|
18
|
+
>[4]
|
|
19
|
+
|
|
20
|
+
export function addPasskeyOptions<TAuthClient extends PasskeyAuthClient>(
|
|
21
|
+
authClient: TAuthClient
|
|
22
|
+
) {
|
|
23
|
+
return createAuthMutationOptions(
|
|
24
|
+
authClient.passkey.addPasskey,
|
|
25
|
+
passkeyMutationKeys.addPasskey
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function useAddPasskey<TAuthClient extends PasskeyAuthClient>(
|
|
30
|
+
authClient: TAuthClient,
|
|
31
|
+
options?: AddPasskeyOptions
|
|
32
|
+
) {
|
|
33
|
+
return useSessionScopedMutation(
|
|
34
|
+
authClient,
|
|
35
|
+
authClient.passkey.addPasskey,
|
|
36
|
+
passkeyMutationKeys.addPasskey,
|
|
37
|
+
(userId) => ({ awaits: [passkeyQueryKeys.lists(userId)] }),
|
|
38
|
+
options
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
passkeyMutationKeys,
|
|
3
|
+
passkeyQueryKeys
|
|
4
|
+
} from "@better-auth-ui/core/plugins"
|
|
5
|
+
import type { PasskeyAuthClient } from "../../lib/auth-client"
|
|
6
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
7
|
+
import { useSessionScopedMutation } from "../use-session-scoped-mutation"
|
|
8
|
+
|
|
9
|
+
export type DeletePasskeyParams<TAuthClient extends PasskeyAuthClient> =
|
|
10
|
+
Parameters<TAuthClient["passkey"]["deletePasskey"]>[0]
|
|
11
|
+
|
|
12
|
+
export type DeletePasskeyOptions = Parameters<
|
|
13
|
+
typeof useSessionScopedMutation<
|
|
14
|
+
PasskeyAuthClient,
|
|
15
|
+
PasskeyAuthClient["passkey"]["deletePasskey"],
|
|
16
|
+
typeof passkeyMutationKeys.deletePasskey
|
|
17
|
+
>
|
|
18
|
+
>[4]
|
|
19
|
+
|
|
20
|
+
export function deletePasskeyOptions<TAuthClient extends PasskeyAuthClient>(
|
|
21
|
+
authClient: TAuthClient
|
|
22
|
+
) {
|
|
23
|
+
return createAuthMutationOptions(
|
|
24
|
+
authClient.passkey.deletePasskey,
|
|
25
|
+
passkeyMutationKeys.deletePasskey
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function useDeletePasskey<TAuthClient extends PasskeyAuthClient>(
|
|
30
|
+
authClient: TAuthClient,
|
|
31
|
+
options?: DeletePasskeyOptions
|
|
32
|
+
) {
|
|
33
|
+
return useSessionScopedMutation(
|
|
34
|
+
authClient,
|
|
35
|
+
authClient.passkey.deletePasskey,
|
|
36
|
+
passkeyMutationKeys.deletePasskey,
|
|
37
|
+
(userId) => ({ awaits: [passkeyQueryKeys.lists(userId)] }),
|
|
38
|
+
options
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import { passkeyMutationKeys } from "@better-auth-ui/core/plugins"
|
|
3
|
+
import type { PasskeyAuthClient } from "../../lib/auth-client"
|
|
4
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
5
|
+
|
|
6
|
+
export type SignInPasskeyParams<TAuthClient extends PasskeyAuthClient> =
|
|
7
|
+
Parameters<TAuthClient["signIn"]["passkey"]>[0]
|
|
8
|
+
|
|
9
|
+
export function signInPasskeyOptions<TAuthClient extends PasskeyAuthClient>(
|
|
10
|
+
authClient: TAuthClient
|
|
11
|
+
) {
|
|
12
|
+
return createAuthMutationOptions(
|
|
13
|
+
authClient.signIn.passkey,
|
|
14
|
+
passkeyMutationKeys.signIn,
|
|
15
|
+
{ awaits: [authQueryKeys.session] }
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
|
|
5
|
+
export type ChangeEmailParams<TAuthClient extends AuthClient> = Parameters<
|
|
6
|
+
TAuthClient["changeEmail"]
|
|
7
|
+
>[0]
|
|
8
|
+
|
|
9
|
+
export function changeEmailOptions<TAuthClient extends AuthClient>(
|
|
10
|
+
authClient: TAuthClient
|
|
11
|
+
) {
|
|
12
|
+
return createAuthMutationOptions(
|
|
13
|
+
authClient.changeEmail,
|
|
14
|
+
authMutationKeys.changeEmail,
|
|
15
|
+
{ awaits: [authQueryKeys.session] }
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
|
|
5
|
+
export type ChangePasswordParams<TAuthClient extends AuthClient> = Parameters<
|
|
6
|
+
TAuthClient["changePassword"]
|
|
7
|
+
>[0]
|
|
8
|
+
|
|
9
|
+
export function changePasswordOptions<TAuthClient extends AuthClient>(
|
|
10
|
+
authClient: TAuthClient
|
|
11
|
+
) {
|
|
12
|
+
return createAuthMutationOptions(
|
|
13
|
+
authClient.changePassword,
|
|
14
|
+
authMutationKeys.changePassword
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { deleteUserMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
|
|
5
|
+
export type DeleteUserParams<TAuthClient extends AuthClient> = Parameters<
|
|
6
|
+
TAuthClient["deleteUser"]
|
|
7
|
+
>[0]
|
|
8
|
+
|
|
9
|
+
export function deleteUserOptions<TAuthClient extends AuthClient>(
|
|
10
|
+
authClient: TAuthClient
|
|
11
|
+
) {
|
|
12
|
+
return createAuthMutationOptions(
|
|
13
|
+
authClient.deleteUser,
|
|
14
|
+
deleteUserMutationKeys.deleteUser
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
|
|
5
|
+
export type LinkSocialParams<TAuthClient extends AuthClient> = Parameters<
|
|
6
|
+
TAuthClient["linkSocial"]
|
|
7
|
+
>[0]
|
|
8
|
+
|
|
9
|
+
export function linkSocialOptions<TAuthClient extends AuthClient>(
|
|
10
|
+
authClient: TAuthClient
|
|
11
|
+
) {
|
|
12
|
+
return createAuthMutationOptions(
|
|
13
|
+
authClient.linkSocial,
|
|
14
|
+
authMutationKeys.linkSocial
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
import { useSessionScopedMutation } from "../use-session-scoped-mutation"
|
|
5
|
+
|
|
6
|
+
export type RevokeSessionParams<TAuthClient extends AuthClient> = Parameters<
|
|
7
|
+
TAuthClient["revokeSession"]
|
|
8
|
+
>[0]
|
|
9
|
+
|
|
10
|
+
export type RevokeSessionOptions = Parameters<
|
|
11
|
+
typeof useSessionScopedMutation<
|
|
12
|
+
AuthClient,
|
|
13
|
+
AuthClient["revokeSession"],
|
|
14
|
+
typeof authMutationKeys.revokeSession
|
|
15
|
+
>
|
|
16
|
+
>[4]
|
|
17
|
+
|
|
18
|
+
export function revokeSessionOptions<TAuthClient extends AuthClient>(
|
|
19
|
+
authClient: TAuthClient
|
|
20
|
+
) {
|
|
21
|
+
return createAuthMutationOptions(
|
|
22
|
+
authClient.revokeSession,
|
|
23
|
+
authMutationKeys.revokeSession
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useRevokeSession<TAuthClient extends AuthClient>(
|
|
28
|
+
authClient: TAuthClient,
|
|
29
|
+
options?: RevokeSessionOptions
|
|
30
|
+
) {
|
|
31
|
+
return useSessionScopedMutation(
|
|
32
|
+
authClient,
|
|
33
|
+
authClient.revokeSession,
|
|
34
|
+
authMutationKeys.revokeSession,
|
|
35
|
+
(userId) => ({ awaits: [authQueryKeys.listSessions(userId)] }),
|
|
36
|
+
options
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
import { useSessionScopedMutation } from "../use-session-scoped-mutation"
|
|
5
|
+
|
|
6
|
+
export type UnlinkAccountParams<TAuthClient extends AuthClient> = Parameters<
|
|
7
|
+
TAuthClient["unlinkAccount"]
|
|
8
|
+
>[0]
|
|
9
|
+
|
|
10
|
+
export type UnlinkAccountOptions = Parameters<
|
|
11
|
+
typeof useSessionScopedMutation<
|
|
12
|
+
AuthClient,
|
|
13
|
+
AuthClient["unlinkAccount"],
|
|
14
|
+
typeof authMutationKeys.unlinkAccount
|
|
15
|
+
>
|
|
16
|
+
>[4]
|
|
17
|
+
|
|
18
|
+
export function unlinkAccountOptions<TAuthClient extends AuthClient>(
|
|
19
|
+
authClient: TAuthClient
|
|
20
|
+
) {
|
|
21
|
+
return createAuthMutationOptions(
|
|
22
|
+
authClient.unlinkAccount,
|
|
23
|
+
authMutationKeys.unlinkAccount
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useUnlinkAccount<TAuthClient extends AuthClient>(
|
|
28
|
+
authClient: TAuthClient,
|
|
29
|
+
options?: UnlinkAccountOptions
|
|
30
|
+
) {
|
|
31
|
+
return useSessionScopedMutation(
|
|
32
|
+
authClient,
|
|
33
|
+
authClient.unlinkAccount,
|
|
34
|
+
authMutationKeys.unlinkAccount,
|
|
35
|
+
(userId) => ({ awaits: [authQueryKeys.listAccounts(userId)] }),
|
|
36
|
+
options
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
|
|
5
|
+
export type UpdateUserParams<TAuthClient extends AuthClient> = Parameters<
|
|
6
|
+
TAuthClient["updateUser"]
|
|
7
|
+
>[0]
|
|
8
|
+
|
|
9
|
+
export function updateUserOptions<TAuthClient extends AuthClient>(
|
|
10
|
+
authClient: TAuthClient
|
|
11
|
+
) {
|
|
12
|
+
return createAuthMutationOptions(
|
|
13
|
+
authClient.updateUser,
|
|
14
|
+
authMutationKeys.updateUser,
|
|
15
|
+
{ awaits: [authQueryKeys.session] }
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CreateMutationOptions,
|
|
3
|
+
createMutation,
|
|
4
|
+
type MutationKey
|
|
5
|
+
} from "@tanstack/solid-query"
|
|
6
|
+
import type { BetterFetchError } from "better-auth/client"
|
|
7
|
+
import type { AuthClient } from "../lib/auth-client"
|
|
8
|
+
import { useSession } from "../queries/auth/session-query"
|
|
9
|
+
import {
|
|
10
|
+
type AuthMutationMeta,
|
|
11
|
+
createAuthMutationOptions,
|
|
12
|
+
type MutationMethod
|
|
13
|
+
} from "./create-auth-mutation"
|
|
14
|
+
|
|
15
|
+
export type SessionScopedMutationOptions<TMethod extends MutationMethod> = Omit<
|
|
16
|
+
CreateMutationOptions<
|
|
17
|
+
Awaited<ReturnType<TMethod>>,
|
|
18
|
+
BetterFetchError,
|
|
19
|
+
Parameters<TMethod>[0]
|
|
20
|
+
>,
|
|
21
|
+
"mutationKey" | "mutationFn" | "meta"
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a mutation whose `meta` is derived from the current session's userId.
|
|
26
|
+
*
|
|
27
|
+
* This mirrors `useOrganizationMutation` for non-org domains: it reads the
|
|
28
|
+
* session reactively and passes the userId to a meta factory function so that
|
|
29
|
+
* `MutationInvalidator` can invalidate the correct scoped query keys.
|
|
30
|
+
*
|
|
31
|
+
* NOTE: `options` must NEVER contain a `meta` property — the type Omit
|
|
32
|
+
* enforces this at the type level, and the explicit `meta:` assignment below
|
|
33
|
+
* will silently override anything passed via options.
|
|
34
|
+
*/
|
|
35
|
+
export function useSessionScopedMutation<
|
|
36
|
+
TAuthClient extends AuthClient,
|
|
37
|
+
TMethod extends MutationMethod,
|
|
38
|
+
const TMutationKey extends MutationKey
|
|
39
|
+
>(
|
|
40
|
+
authClient: TAuthClient,
|
|
41
|
+
authFn: TMethod,
|
|
42
|
+
mutationKey: TMutationKey,
|
|
43
|
+
meta: (userId: string | undefined) => AuthMutationMeta,
|
|
44
|
+
options?: SessionScopedMutationOptions<TMethod>
|
|
45
|
+
) {
|
|
46
|
+
const session = useSession(authClient)
|
|
47
|
+
|
|
48
|
+
return createMutation(() => {
|
|
49
|
+
const userId = (session.data as { user?: { id?: string } } | undefined)
|
|
50
|
+
?.user?.id
|
|
51
|
+
|
|
52
|
+
if (!userId) {
|
|
53
|
+
console.debug(
|
|
54
|
+
`[useSessionScopedMutation] userId is undefined for mutation "${String(mutationKey)}". Cache invalidation will be a no-op until the session loads.`
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...createAuthMutationOptions(authFn, mutationKey),
|
|
60
|
+
...options,
|
|
61
|
+
meta: meta(userId)
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { usernameMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import type { UsernameAuthClient } from "../../lib/auth-client"
|
|
3
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
4
|
+
|
|
5
|
+
export type IsUsernameAvailableParams<TAuthClient extends UsernameAuthClient> =
|
|
6
|
+
Parameters<TAuthClient["isUsernameAvailable"]>[0]
|
|
7
|
+
|
|
8
|
+
export function isUsernameAvailableOptions<
|
|
9
|
+
TAuthClient extends UsernameAuthClient
|
|
10
|
+
>(authClient: TAuthClient) {
|
|
11
|
+
return createAuthMutationOptions(
|
|
12
|
+
authClient.isUsernameAvailable,
|
|
13
|
+
usernameMutationKeys.isUsernameAvailable
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import { usernameMutationKeys } from "@better-auth-ui/core/plugins"
|
|
3
|
+
import type { UsernameAuthClient } from "../../lib/auth-client"
|
|
4
|
+
import { createAuthMutationOptions } from "../create-auth-mutation"
|
|
5
|
+
|
|
6
|
+
export type SignInUsernameParams<TAuthClient extends UsernameAuthClient> =
|
|
7
|
+
Parameters<TAuthClient["signIn"]["username"]>[0]
|
|
8
|
+
|
|
9
|
+
export function signInUsernameOptions<TAuthClient extends UsernameAuthClient>(
|
|
10
|
+
authClient: TAuthClient
|
|
11
|
+
) {
|
|
12
|
+
return createAuthMutationOptions(
|
|
13
|
+
authClient.signIn.username,
|
|
14
|
+
usernameMutationKeys.signIn,
|
|
15
|
+
{ awaits: [authQueryKeys.session] }
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createAuthPlugin } from "@better-auth-ui/core"
|
|
2
|
+
import { type Component, onCleanup } from "solid-js"
|
|
3
|
+
import { useFetchOptions } from "../lib/fetch-options-provider"
|
|
4
|
+
|
|
5
|
+
/** Props passed to the consumer's `render` component. */
|
|
6
|
+
export type CaptchaRenderProps = {
|
|
7
|
+
/** Call once the user solves the captcha. */
|
|
8
|
+
setToken: (token: string) => void
|
|
9
|
+
/** Call on error/expire to clear the token. */
|
|
10
|
+
clearToken: () => void
|
|
11
|
+
/**
|
|
12
|
+
* Register your widget's `reset()`. Forms call it after a failed
|
|
13
|
+
* submission since captcha tokens are single-use. Pass `null` on cleanup.
|
|
14
|
+
*/
|
|
15
|
+
setReset: (reset: (() => void) | null) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type CaptchaPluginOptions = {
|
|
19
|
+
/** Renders the captcha widget. Wire `setToken`, `clearToken`, and `setReset`. */
|
|
20
|
+
render: Component<CaptchaRenderProps>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Provider-agnostic captcha plugin. Forwards the resolved token via the
|
|
25
|
+
* `x-captcha-response` header on Better Auth requests.
|
|
26
|
+
*/
|
|
27
|
+
export const captchaPlugin = createAuthPlugin(
|
|
28
|
+
"captcha",
|
|
29
|
+
({ render: Render }: CaptchaPluginOptions) => {
|
|
30
|
+
const CaptchaWidget = () => {
|
|
31
|
+
const { setFetchOptions, registerReset } = useFetchOptions()
|
|
32
|
+
|
|
33
|
+
const setToken = (token: string) => {
|
|
34
|
+
setFetchOptions({ headers: { "x-captcha-response": token } })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const clearToken = () => {
|
|
38
|
+
setFetchOptions(undefined)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const setReset = (reset: (() => void) | null) => {
|
|
42
|
+
registerReset(reset)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
onCleanup(() => {
|
|
46
|
+
setFetchOptions(undefined)
|
|
47
|
+
registerReset(null)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Render
|
|
52
|
+
setToken={setToken}
|
|
53
|
+
clearToken={clearToken}
|
|
54
|
+
setReset={setReset}
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
render: Render,
|
|
61
|
+
captchaComponent: CaptchaWidget
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
)
|
package/src/plugins.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { apiKeyQueryKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import type { QueryClient } from "@tanstack/solid-query"
|
|
3
|
+
import type { ApiKeyAuthClient, InferData } from "../../lib/auth-client"
|
|
4
|
+
import { useSession } from "../auth/session-query"
|
|
5
|
+
import {
|
|
6
|
+
createUserScopedOptions,
|
|
7
|
+
createUserScopedQuery,
|
|
8
|
+
ensureUserScopedQuery,
|
|
9
|
+
fetchUserScopedQuery,
|
|
10
|
+
getSessionUserId,
|
|
11
|
+
prefetchUserScopedQuery
|
|
12
|
+
} from "../create-user-scoped-query"
|
|
13
|
+
|
|
14
|
+
export type ListApiKeysData<TAuthClient extends ApiKeyAuthClient> = InferData<
|
|
15
|
+
TAuthClient["apiKey"]["list"]
|
|
16
|
+
>
|
|
17
|
+
export type ListApiKeysParams<TAuthClient extends ApiKeyAuthClient> =
|
|
18
|
+
Parameters<TAuthClient["apiKey"]["list"]>[0]
|
|
19
|
+
export type ListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> = Omit<
|
|
20
|
+
ReturnType<typeof listApiKeysOptions<TAuthClient>>,
|
|
21
|
+
"queryKey" | "queryFn"
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>(
|
|
25
|
+
authClient: TAuthClient,
|
|
26
|
+
userId: string | undefined,
|
|
27
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
28
|
+
) {
|
|
29
|
+
return createUserScopedOptions(
|
|
30
|
+
apiKeyQueryKeys.list(userId, params?.query),
|
|
31
|
+
authClient.apiKey.list,
|
|
32
|
+
params
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const ensureListApiKeys = <TAuthClient extends ApiKeyAuthClient>(
|
|
37
|
+
queryClient: QueryClient,
|
|
38
|
+
authClient: TAuthClient,
|
|
39
|
+
userId: string,
|
|
40
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
41
|
+
) =>
|
|
42
|
+
ensureUserScopedQuery(
|
|
43
|
+
queryClient,
|
|
44
|
+
apiKeyQueryKeys.list(userId, params?.query),
|
|
45
|
+
authClient.apiKey.list,
|
|
46
|
+
params
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
export const prefetchListApiKeys = <TAuthClient extends ApiKeyAuthClient>(
|
|
50
|
+
queryClient: QueryClient,
|
|
51
|
+
authClient: TAuthClient,
|
|
52
|
+
userId: string,
|
|
53
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
54
|
+
) =>
|
|
55
|
+
prefetchUserScopedQuery(
|
|
56
|
+
queryClient,
|
|
57
|
+
apiKeyQueryKeys.list(userId, params?.query),
|
|
58
|
+
authClient.apiKey.list,
|
|
59
|
+
params
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
export const fetchListApiKeys = <TAuthClient extends ApiKeyAuthClient>(
|
|
63
|
+
queryClient: QueryClient,
|
|
64
|
+
authClient: TAuthClient,
|
|
65
|
+
userId: string,
|
|
66
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
67
|
+
) =>
|
|
68
|
+
fetchUserScopedQuery(
|
|
69
|
+
queryClient,
|
|
70
|
+
apiKeyQueryKeys.list(userId, params?.query),
|
|
71
|
+
authClient.apiKey.list,
|
|
72
|
+
params
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
export type UseListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> =
|
|
76
|
+
ListApiKeysOptions<TAuthClient> & ListApiKeysParams<TAuthClient>
|
|
77
|
+
|
|
78
|
+
export function useListApiKeys<TAuthClient extends ApiKeyAuthClient>(
|
|
79
|
+
authClient: TAuthClient,
|
|
80
|
+
options: UseListApiKeysOptions<TAuthClient> = {}
|
|
81
|
+
) {
|
|
82
|
+
const session = useSession(authClient)
|
|
83
|
+
const userId = () => getSessionUserId(session)
|
|
84
|
+
const { query, fetchOptions, ...queryOptionsRest } = options
|
|
85
|
+
|
|
86
|
+
return createUserScopedQuery(
|
|
87
|
+
() => apiKeyQueryKeys.list(userId(), query),
|
|
88
|
+
authClient.apiKey.list,
|
|
89
|
+
() => ({ query, fetchOptions }) as ListApiKeysParams<TAuthClient>,
|
|
90
|
+
() => Boolean(userId()),
|
|
91
|
+
() => queryOptionsRest
|
|
92
|
+
)
|
|
93
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import {
|
|
3
|
+
createQuery,
|
|
4
|
+
type DataTag,
|
|
5
|
+
type QueryClient,
|
|
6
|
+
queryOptions
|
|
7
|
+
} from "@tanstack/solid-query"
|
|
8
|
+
import type { BetterFetchError } from "better-auth/client"
|
|
9
|
+
import type { AuthClient, InferData } from "../../lib/auth-client"
|
|
10
|
+
|
|
11
|
+
export type SessionData<TAuthClient extends AuthClient = AuthClient> =
|
|
12
|
+
InferData<TAuthClient["getSession"]>
|
|
13
|
+
|
|
14
|
+
export type Session<TAuthClient extends AuthClient = AuthClient> = NonNullable<
|
|
15
|
+
SessionData<TAuthClient>
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
export type SessionParams<TAuthClient extends AuthClient> = Parameters<
|
|
19
|
+
TAuthClient["getSession"]
|
|
20
|
+
>[0]
|
|
21
|
+
|
|
22
|
+
export type SessionOptions<TAuthClient extends AuthClient> = Omit<
|
|
23
|
+
ReturnType<typeof sessionOptions<TAuthClient>>,
|
|
24
|
+
"queryKey" | "queryFn"
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
export function sessionOptions<TAuthClient extends AuthClient>(
|
|
28
|
+
authClient: TAuthClient,
|
|
29
|
+
params?: SessionParams<TAuthClient>
|
|
30
|
+
) {
|
|
31
|
+
type TData = SessionData<TAuthClient>
|
|
32
|
+
const queryKey = authQueryKeys.session
|
|
33
|
+
|
|
34
|
+
const options = queryOptions<TData, BetterFetchError>({
|
|
35
|
+
queryKey,
|
|
36
|
+
queryFn: ({ signal }) =>
|
|
37
|
+
authClient.getSession({
|
|
38
|
+
...params,
|
|
39
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
40
|
+
}) as Promise<TData>
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return options as typeof options & {
|
|
44
|
+
queryKey: DataTag<typeof queryKey, TData, BetterFetchError>
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const ensureSession = <TAuthClient extends AuthClient>(
|
|
49
|
+
queryClient: QueryClient,
|
|
50
|
+
authClient: TAuthClient,
|
|
51
|
+
params?: SessionParams<TAuthClient>
|
|
52
|
+
) => queryClient.ensureQueryData(sessionOptions(authClient, params) as never)
|
|
53
|
+
|
|
54
|
+
export const prefetchSession = <TAuthClient extends AuthClient>(
|
|
55
|
+
queryClient: QueryClient,
|
|
56
|
+
authClient: TAuthClient,
|
|
57
|
+
params?: SessionParams<TAuthClient>
|
|
58
|
+
) => queryClient.prefetchQuery(sessionOptions(authClient, params) as never)
|
|
59
|
+
|
|
60
|
+
export const fetchSession = <TAuthClient extends AuthClient>(
|
|
61
|
+
queryClient: QueryClient,
|
|
62
|
+
authClient: TAuthClient,
|
|
63
|
+
params?: SessionParams<TAuthClient>
|
|
64
|
+
) => queryClient.fetchQuery(sessionOptions(authClient, params) as never)
|
|
65
|
+
|
|
66
|
+
export type UseSessionOptions<TAuthClient extends AuthClient> =
|
|
67
|
+
SessionOptions<TAuthClient> & SessionParams<TAuthClient>
|
|
68
|
+
|
|
69
|
+
export function useSession<TAuthClient extends AuthClient>(
|
|
70
|
+
authClient: TAuthClient,
|
|
71
|
+
options: UseSessionOptions<TAuthClient> = {}
|
|
72
|
+
) {
|
|
73
|
+
return createQuery(() => {
|
|
74
|
+
const { query, fetchOptions, ...queryOptions } = options
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
...sessionOptions(authClient, { query, fetchOptions }),
|
|
78
|
+
...queryOptions
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CreateQueryOptions,
|
|
3
|
+
type DataTag,
|
|
4
|
+
type QueryKey,
|
|
5
|
+
queryOptions
|
|
6
|
+
} from "@tanstack/solid-query"
|
|
7
|
+
import type { BetterFetchError, BetterFetchOption } from "better-auth/client"
|
|
8
|
+
|
|
9
|
+
export type AuthQueryFn<TData = unknown> = (params: {
|
|
10
|
+
query?: Record<string, unknown>
|
|
11
|
+
fetchOptions?: BetterFetchOption
|
|
12
|
+
}) => Promise<{ data: TData }>
|
|
13
|
+
|
|
14
|
+
export type AuthQueryFnData<TFn> =
|
|
15
|
+
TFn extends AuthQueryFn<infer TData> ? TData : never
|
|
16
|
+
|
|
17
|
+
export type AuthQueryKey<
|
|
18
|
+
TFn extends AuthQueryFn = AuthQueryFn,
|
|
19
|
+
TPrefix extends QueryKey = QueryKey
|
|
20
|
+
> = readonly [...TPrefix, NonNullable<Parameters<TFn>[0]>["query"] | null]
|
|
21
|
+
|
|
22
|
+
export type AuthQueryOptions<
|
|
23
|
+
TFn extends AuthQueryFn = AuthQueryFn,
|
|
24
|
+
TPrefix extends QueryKey = QueryKey
|
|
25
|
+
> = Omit<
|
|
26
|
+
CreateQueryOptions<
|
|
27
|
+
AuthQueryFnData<TFn>,
|
|
28
|
+
BetterFetchError,
|
|
29
|
+
AuthQueryFnData<TFn>,
|
|
30
|
+
AuthQueryKey<TFn, TPrefix>
|
|
31
|
+
>,
|
|
32
|
+
"queryKey"
|
|
33
|
+
> & {
|
|
34
|
+
queryKey: DataTag<
|
|
35
|
+
AuthQueryKey<TFn, TPrefix>,
|
|
36
|
+
AuthQueryFnData<TFn>,
|
|
37
|
+
BetterFetchError
|
|
38
|
+
>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function authQueryOptions<
|
|
42
|
+
TFn extends AuthQueryFn,
|
|
43
|
+
const TPrefix extends QueryKey
|
|
44
|
+
>(
|
|
45
|
+
authFn: TFn,
|
|
46
|
+
queryKey: TPrefix,
|
|
47
|
+
params?: Parameters<TFn>[0]
|
|
48
|
+
): AuthQueryOptions<TFn, TPrefix> {
|
|
49
|
+
return queryOptions<AuthQueryFnData<TFn>, BetterFetchError>({
|
|
50
|
+
queryKey: [...queryKey, params?.query ?? null] as const,
|
|
51
|
+
queryFn: ({ signal }) =>
|
|
52
|
+
authFn({
|
|
53
|
+
...params,
|
|
54
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
55
|
+
}) as Promise<AuthQueryFnData<TFn>>
|
|
56
|
+
}) as AuthQueryOptions<TFn, TPrefix>
|
|
57
|
+
}
|