better-auth-ui 3.2.5

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.
Files changed (226) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
  4. package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
  5. package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
  6. package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
  7. package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
  8. package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
  9. package/dist/chunk-BDFQSFBU.js +750 -0
  10. package/dist/chunk-CRAHKL2C.cjs +801 -0
  11. package/dist/chunk-MJPOA6PK.js +801 -0
  12. package/dist/chunk-SV64DXGW.cjs +750 -0
  13. package/dist/index.cjs +12618 -0
  14. package/dist/index.d.cts +771 -0
  15. package/dist/index.d.ts +771 -0
  16. package/dist/index.js +12618 -0
  17. package/dist/instantdb.cjs +189 -0
  18. package/dist/instantdb.d.cts +36 -0
  19. package/dist/instantdb.d.ts +36 -0
  20. package/dist/instantdb.js +189 -0
  21. package/dist/metafile-cjs.json +1 -0
  22. package/dist/metafile-esm.json +1 -0
  23. package/dist/server.cjs +194 -0
  24. package/dist/server.d.cts +35 -0
  25. package/dist/server.d.ts +35 -0
  26. package/dist/server.js +194 -0
  27. package/dist/style.css +1 -0
  28. package/dist/tanstack.cjs +153 -0
  29. package/dist/tanstack.d.cts +18 -0
  30. package/dist/tanstack.d.ts +18 -0
  31. package/dist/tanstack.js +153 -0
  32. package/dist/triplit.cjs +201 -0
  33. package/dist/triplit.d.cts +31 -0
  34. package/dist/triplit.d.ts +31 -0
  35. package/dist/triplit.js +201 -0
  36. package/dist/utils-C5R37WDe.d.cts +3 -0
  37. package/dist/utils-C5R37WDe.d.ts +3 -0
  38. package/dist/view-paths-CHSJf5dv.d.cts +645 -0
  39. package/dist/view-paths-CHSJf5dv.d.ts +645 -0
  40. package/package.json +156 -0
  41. package/src/components/account/account-view.tsx +220 -0
  42. package/src/components/auth/auth-callback.tsx +36 -0
  43. package/src/components/auth/auth-form.tsx +277 -0
  44. package/src/components/auth/auth-view.tsx +389 -0
  45. package/src/components/auth/email-otp-button.tsx +53 -0
  46. package/src/components/auth/forms/email-otp-form.tsx +288 -0
  47. package/src/components/auth/forms/forgot-password-form.tsx +168 -0
  48. package/src/components/auth/forms/magic-link-form.tsx +191 -0
  49. package/src/components/auth/forms/recover-account-form.tsx +138 -0
  50. package/src/components/auth/forms/reset-password-form.tsx +215 -0
  51. package/src/components/auth/forms/sign-in-form.tsx +289 -0
  52. package/src/components/auth/forms/sign-up-form.tsx +788 -0
  53. package/src/components/auth/forms/two-factor-form.tsx +372 -0
  54. package/src/components/auth/magic-link-button.tsx +54 -0
  55. package/src/components/auth/one-tap.tsx +48 -0
  56. package/src/components/auth/otp-input-group.tsx +65 -0
  57. package/src/components/auth/passkey-button.tsx +85 -0
  58. package/src/components/auth/provider-button.tsx +141 -0
  59. package/src/components/auth/sign-out.tsx +25 -0
  60. package/src/components/auth-loading.tsx +21 -0
  61. package/src/components/captcha/captcha.tsx +79 -0
  62. package/src/components/captcha/recaptcha-badge.tsx +61 -0
  63. package/src/components/captcha/recaptcha-v2.tsx +58 -0
  64. package/src/components/captcha/recaptcha-v3.tsx +73 -0
  65. package/src/components/email/email-template.tsx +216 -0
  66. package/src/components/form-error.tsx +27 -0
  67. package/src/components/organization/accept-invitation-card.tsx +362 -0
  68. package/src/components/organization/create-organization-dialog.tsx +395 -0
  69. package/src/components/organization/delete-organization-card.tsx +101 -0
  70. package/src/components/organization/delete-organization-dialog.tsx +209 -0
  71. package/src/components/organization/invitation-cell.tsx +156 -0
  72. package/src/components/organization/invite-member-dialog.tsx +258 -0
  73. package/src/components/organization/leave-organization-dialog.tsx +150 -0
  74. package/src/components/organization/member-cell.tsx +187 -0
  75. package/src/components/organization/organization-cell-view.tsx +122 -0
  76. package/src/components/organization/organization-cell.tsx +154 -0
  77. package/src/components/organization/organization-invitations-card.tsx +94 -0
  78. package/src/components/organization/organization-logo-card.tsx +308 -0
  79. package/src/components/organization/organization-logo.tsx +120 -0
  80. package/src/components/organization/organization-members-card.tsx +155 -0
  81. package/src/components/organization/organization-name-card.tsx +204 -0
  82. package/src/components/organization/organization-settings-cards.tsx +67 -0
  83. package/src/components/organization/organization-slug-card.tsx +223 -0
  84. package/src/components/organization/organization-switcher.tsx +512 -0
  85. package/src/components/organization/organization-view.tsx +228 -0
  86. package/src/components/organization/organizations-card.tsx +72 -0
  87. package/src/components/organization/personal-account-view.tsx +115 -0
  88. package/src/components/organization/remove-member-dialog.tsx +144 -0
  89. package/src/components/organization/update-member-role-dialog.tsx +213 -0
  90. package/src/components/organization/user-invitations-card.tsx +238 -0
  91. package/src/components/password-input.tsx +56 -0
  92. package/src/components/provider-icons.tsx +385 -0
  93. package/src/components/redirect-to-sign-in.tsx +16 -0
  94. package/src/components/redirect-to-sign-up.tsx +16 -0
  95. package/src/components/settings/account/account-cell.tsx +158 -0
  96. package/src/components/settings/account/accounts-card.tsx +75 -0
  97. package/src/components/settings/account/delete-account-card.tsx +65 -0
  98. package/src/components/settings/account/delete-account-dialog.tsx +231 -0
  99. package/src/components/settings/account/update-avatar-card.tsx +198 -0
  100. package/src/components/settings/account/update-field-card.tsx +282 -0
  101. package/src/components/settings/account/update-name-card.tsx +39 -0
  102. package/src/components/settings/account/update-username-card.tsx +42 -0
  103. package/src/components/settings/account-settings-cards.tsx +123 -0
  104. package/src/components/settings/api-key/api-key-cell.tsx +108 -0
  105. package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
  106. package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
  107. package/src/components/settings/api-key/api-keys-card.tsx +98 -0
  108. package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
  109. package/src/components/settings/passkey/passkey-cell.tsx +113 -0
  110. package/src/components/settings/passkey/passkeys-card.tsx +111 -0
  111. package/src/components/settings/providers/provider-cell.tsx +152 -0
  112. package/src/components/settings/providers/providers-card.tsx +108 -0
  113. package/src/components/settings/security/change-email-card.tsx +200 -0
  114. package/src/components/settings/security/change-password-card.tsx +326 -0
  115. package/src/components/settings/security/session-cell.tsx +120 -0
  116. package/src/components/settings/security/sessions-card.tsx +58 -0
  117. package/src/components/settings/security-settings-cards.tsx +111 -0
  118. package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
  119. package/src/components/settings/shared/settings-action-button.tsx +51 -0
  120. package/src/components/settings/shared/settings-card-footer.tsx +94 -0
  121. package/src/components/settings/shared/settings-card-header.tsx +67 -0
  122. package/src/components/settings/shared/settings-card.tsx +106 -0
  123. package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
  124. package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
  125. package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
  126. package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
  127. package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
  128. package/src/components/signed-in.tsx +20 -0
  129. package/src/components/signed-out.tsx +20 -0
  130. package/src/components/ui/alert.tsx +66 -0
  131. package/src/components/ui/avatar.tsx +53 -0
  132. package/src/components/ui/button.tsx +59 -0
  133. package/src/components/ui/card.tsx +92 -0
  134. package/src/components/ui/checkbox.tsx +32 -0
  135. package/src/components/ui/dialog.tsx +143 -0
  136. package/src/components/ui/drawer.tsx +135 -0
  137. package/src/components/ui/dropdown-menu.tsx +257 -0
  138. package/src/components/ui/form.tsx +167 -0
  139. package/src/components/ui/input-otp.tsx +77 -0
  140. package/src/components/ui/input.tsx +21 -0
  141. package/src/components/ui/label.tsx +24 -0
  142. package/src/components/ui/select.tsx +185 -0
  143. package/src/components/ui/separator.tsx +28 -0
  144. package/src/components/ui/skeleton.tsx +13 -0
  145. package/src/components/ui/tabs.tsx +66 -0
  146. package/src/components/ui/textarea.tsx +18 -0
  147. package/src/components/user-avatar.tsx +147 -0
  148. package/src/components/user-button.tsx +409 -0
  149. package/src/components/user-view.tsx +138 -0
  150. package/src/hooks/use-auth-data.ts +184 -0
  151. package/src/hooks/use-authenticate.ts +62 -0
  152. package/src/hooks/use-captcha.tsx +138 -0
  153. package/src/hooks/use-current-organization.ts +59 -0
  154. package/src/hooks/use-hydrated.ts +13 -0
  155. package/src/hooks/use-lang.ts +32 -0
  156. package/src/hooks/use-success-transition.ts +51 -0
  157. package/src/hooks/use-theme.ts +39 -0
  158. package/src/index.ts +65 -0
  159. package/src/instantdb.ts +1 -0
  160. package/src/lib/auth-data-cache.ts +90 -0
  161. package/src/lib/auth-ui-provider.tsx +658 -0
  162. package/src/lib/gravatar-utils.ts +58 -0
  163. package/src/lib/image-utils.ts +55 -0
  164. package/src/lib/instantdb/model-names.ts +24 -0
  165. package/src/lib/instantdb/use-instant-options.ts +98 -0
  166. package/src/lib/instantdb/use-list-accounts.ts +38 -0
  167. package/src/lib/instantdb/use-list-sessions.ts +53 -0
  168. package/src/lib/instantdb/use-session.ts +55 -0
  169. package/src/lib/organization-refetcher.tsx +56 -0
  170. package/src/lib/social-providers.ts +144 -0
  171. package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
  172. package/src/lib/tanstack/use-tanstack-options.ts +112 -0
  173. package/src/lib/triplit/model-names.ts +24 -0
  174. package/src/lib/triplit/use-conditional-query.ts +82 -0
  175. package/src/lib/triplit/use-list-accounts.ts +31 -0
  176. package/src/lib/triplit/use-list-sessions.ts +33 -0
  177. package/src/lib/triplit/use-session.ts +42 -0
  178. package/src/lib/triplit/use-triplit-hooks.ts +68 -0
  179. package/src/lib/triplit/use-triplit-token.ts +44 -0
  180. package/src/lib/utils.ts +105 -0
  181. package/src/lib/view-paths.ts +55 -0
  182. package/src/localization/admin-error-codes.ts +20 -0
  183. package/src/localization/anonymous-error-codes.ts +6 -0
  184. package/src/localization/api-key-error-codes.ts +32 -0
  185. package/src/localization/auth-localization.ts +740 -0
  186. package/src/localization/base-error-codes.ts +27 -0
  187. package/src/localization/captcha-error-codes.ts +17 -0
  188. package/src/localization/email-otp-error-codes.ts +7 -0
  189. package/src/localization/generic-oauth-error-codes.ts +3 -0
  190. package/src/localization/haveibeenpwned-error-codes.ts +4 -0
  191. package/src/localization/multi-session-error-codes.ts +3 -0
  192. package/src/localization/organization-error-codes.ts +57 -0
  193. package/src/localization/passkey-error-codes.ts +10 -0
  194. package/src/localization/phone-number-error-codes.ts +10 -0
  195. package/src/localization/stripe-localization.ts +12 -0
  196. package/src/localization/two-factor-error-codes.ts +12 -0
  197. package/src/localization/username-error-codes.ts +9 -0
  198. package/src/server.ts +4 -0
  199. package/src/style.css +1 -0
  200. package/src/tanstack.ts +1 -0
  201. package/src/triplit.ts +1 -0
  202. package/src/types/account-options.ts +35 -0
  203. package/src/types/additional-fields.ts +21 -0
  204. package/src/types/any-auth-client.ts +6 -0
  205. package/src/types/api-key.ts +9 -0
  206. package/src/types/auth-client.ts +37 -0
  207. package/src/types/auth-hooks.ts +61 -0
  208. package/src/types/auth-mutators.ts +17 -0
  209. package/src/types/avatar-options.ts +29 -0
  210. package/src/types/captcha-options.ts +32 -0
  211. package/src/types/captcha-provider.ts +6 -0
  212. package/src/types/credentials-options.ts +32 -0
  213. package/src/types/delete-user-options.ts +7 -0
  214. package/src/types/fetch-error.ts +6 -0
  215. package/src/types/generic-oauth-options.ts +16 -0
  216. package/src/types/gravatar-options.ts +21 -0
  217. package/src/types/image.ts +7 -0
  218. package/src/types/invitation.ts +10 -0
  219. package/src/types/link.ts +7 -0
  220. package/src/types/organization-options.ts +106 -0
  221. package/src/types/password-validation.ts +16 -0
  222. package/src/types/profile.ts +15 -0
  223. package/src/types/refetch.ts +1 -0
  224. package/src/types/render-toast.ts +9 -0
  225. package/src/types/sign-up-options.ts +7 -0
  226. package/src/types/social-options.ts +16 -0
@@ -0,0 +1,153 @@
1
+ import {
2
+ AuthUIProvider
3
+ } from "./chunk-BDFQSFBU.js";
4
+ import "./chunk-MJPOA6PK.js";
5
+
6
+ // src/lib/tanstack/auth-ui-provider-tanstack.tsx
7
+ import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
8
+
9
+ // src/lib/tanstack/use-tanstack-options.ts
10
+ import {
11
+ AuthQueryContext,
12
+ createAuthHooks
13
+ } from "@daveyplate/better-auth-tanstack";
14
+ import { useIsRestoring, useQueryClient } from "@tanstack/react-query";
15
+ import { useCallback, useContext, useMemo } from "react";
16
+ function useTanstackOptions({
17
+ authClient
18
+ }) {
19
+ const {
20
+ useUnlinkAccount,
21
+ useUpdateUser,
22
+ useDeletePasskey,
23
+ useRevokeSession,
24
+ useRevokeDeviceSession,
25
+ useSetActiveSession
26
+ } = createAuthHooks(authClient);
27
+ const queryClient = useQueryClient();
28
+ const { mutateAsync: updateUserAsync } = useUpdateUser();
29
+ const { mutateAsync: deletePasskeyAsync } = useDeletePasskey();
30
+ const { mutateAsync: unlinkAccountAsync } = useUnlinkAccount();
31
+ const { mutateAsync: revokeSessionAsync } = useRevokeSession();
32
+ const { mutateAsync: revokeDeviceSessionAsync } = useRevokeDeviceSession();
33
+ const { setActiveSessionAsync } = useSetActiveSession();
34
+ const { sessionKey } = useContext(AuthQueryContext);
35
+ const hooks = useMemo(
36
+ () => ({
37
+ ...createAuthHooks(authClient),
38
+ useIsRestoring
39
+ }),
40
+ [authClient]
41
+ );
42
+ const mutators = useMemo(
43
+ () => ({
44
+ updateUser: async (params) => {
45
+ const { error } = await updateUserAsync({
46
+ ...params,
47
+ fetchOptions: { throw: false }
48
+ });
49
+ if (error) throw error;
50
+ },
51
+ unlinkAccount: async (params) => {
52
+ const { error } = await unlinkAccountAsync({
53
+ ...params,
54
+ fetchOptions: { throw: false }
55
+ });
56
+ if (error) throw error;
57
+ },
58
+ deletePasskey: async (params) => {
59
+ const { error } = await deletePasskeyAsync({
60
+ ...params,
61
+ fetchOptions: { throw: false }
62
+ });
63
+ if (error) throw error;
64
+ },
65
+ revokeSession: async (params) => {
66
+ const { error } = await revokeSessionAsync({
67
+ ...params,
68
+ fetchOptions: { throw: false }
69
+ });
70
+ if (error) throw error;
71
+ },
72
+ setActiveSession: async (params) => {
73
+ const { error } = await setActiveSessionAsync({
74
+ ...params,
75
+ fetchOptions: { throw: false }
76
+ });
77
+ if (error) throw error;
78
+ },
79
+ revokeDeviceSession: async (params) => {
80
+ const { error } = await revokeDeviceSessionAsync({
81
+ ...params,
82
+ fetchOptions: { throw: false }
83
+ });
84
+ if (error) throw error;
85
+ }
86
+ }),
87
+ [
88
+ updateUserAsync,
89
+ deletePasskeyAsync,
90
+ unlinkAccountAsync,
91
+ revokeSessionAsync,
92
+ revokeDeviceSessionAsync,
93
+ setActiveSessionAsync
94
+ ]
95
+ );
96
+ const onSessionChange = useCallback(async () => {
97
+ await queryClient.refetchQueries({ queryKey: sessionKey });
98
+ queryClient.invalidateQueries({
99
+ predicate: (query) => query.queryKey !== sessionKey
100
+ });
101
+ }, [queryClient, sessionKey]);
102
+ return {
103
+ hooks,
104
+ mutators,
105
+ onSessionChange,
106
+ optimistic: true
107
+ };
108
+ }
109
+
110
+ // src/lib/tanstack/auth-ui-provider-tanstack.tsx
111
+ import { jsx } from "react/jsx-runtime";
112
+ function AuthUIProviderTanstack({
113
+ children,
114
+ authClient,
115
+ hooks: hooksProp,
116
+ mutators: mutatorsProp,
117
+ onSessionChange: onSessionChangeProp,
118
+ ...props
119
+ }) {
120
+ const {
121
+ hooks: contextHooks,
122
+ mutators: contextMutators,
123
+ onSessionChange,
124
+ optimistic
125
+ } = useTanstackOptions({ authClient });
126
+ const hooks = useMemo2(
127
+ () => ({ ...contextHooks, ...hooksProp }),
128
+ [contextHooks, hooksProp]
129
+ );
130
+ const mutators = useMemo2(
131
+ () => ({ ...contextMutators, ...mutatorsProp }),
132
+ [contextMutators, mutatorsProp]
133
+ );
134
+ const onSessionChangeCallback = useCallback2(async () => {
135
+ await onSessionChange();
136
+ await (onSessionChangeProp == null ? void 0 : onSessionChangeProp());
137
+ }, [onSessionChangeProp, onSessionChange]);
138
+ return /* @__PURE__ */ jsx(
139
+ AuthUIProvider,
140
+ {
141
+ authClient,
142
+ hooks,
143
+ mutators,
144
+ onSessionChange: onSessionChangeCallback,
145
+ optimistic,
146
+ ...props,
147
+ children
148
+ }
149
+ );
150
+ }
151
+ export {
152
+ AuthUIProviderTanstack
153
+ };
@@ -0,0 +1,201 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/lib/triplit/use-triplit-hooks.ts
2
+ var _react = require('react');
3
+
4
+ // src/lib/triplit/model-names.ts
5
+ var getModelName = ({
6
+ namespace,
7
+ modelNames,
8
+ usePlural = false
9
+ }) => {
10
+ return (modelNames == null ? void 0 : modelNames[namespace]) || `${namespace}${usePlural ? "s" : ""}`;
11
+ };
12
+
13
+ // src/lib/triplit/use-conditional-query.ts
14
+ var _react3 = require('@triplit/react');
15
+
16
+ function useConditionalQuery(client, query, options) {
17
+ const stringifiedQuery = !(options == null ? void 0 : options.disabled) && query && JSON.stringify(query);
18
+ const localOnly = !!(options == null ? void 0 : options.localOnly);
19
+ const [remoteFulfilled, setRemoteFulfilled] = _react.useState.call(void 0, false);
20
+ const defaultValue = {
21
+ results: void 0,
22
+ fetching: true,
23
+ fetchingLocal: false,
24
+ fetchingRemote: false,
25
+ error: void 0
26
+ };
27
+ const [subscribe, snapshot] = _react.useMemo.call(void 0,
28
+ () => stringifiedQuery ? _react3.createStateSubscription.call(void 0, client, query, {
29
+ ...options,
30
+ onRemoteFulfilled: () => setRemoteFulfilled(true)
31
+ }) : [() => () => {
32
+ }, () => defaultValue],
33
+ [stringifiedQuery, localOnly]
34
+ );
35
+ const getServerSnapshot = _react.useCallback.call(void 0, () => snapshot(), [snapshot]);
36
+ const { fetching, ...rest } = _react.useSyncExternalStore.call(void 0,
37
+ subscribe,
38
+ snapshot,
39
+ getServerSnapshot
40
+ );
41
+ return { fetching: fetching && !remoteFulfilled, ...rest };
42
+ }
43
+ function useConditionalQueryOne(client, query, options) {
44
+ const { fetching, fetchingLocal, fetchingRemote, results, error } = useConditionalQuery(
45
+ client,
46
+ query ? { ...query, limit: 1 } : query,
47
+ options
48
+ );
49
+ const result = _react.useMemo.call(void 0, () => {
50
+ return _nullishCoalesce((results == null ? void 0 : results[0]), () => ( null));
51
+ }, [results]);
52
+ return { fetching, fetchingLocal, fetchingRemote, result, error };
53
+ }
54
+
55
+ // src/lib/triplit/use-triplit-token.ts
56
+
57
+
58
+ function useTriplitToken(triplit) {
59
+ const connectionStatus = _react3.useConnectionStatus.call(void 0, triplit);
60
+ const payload = _react.useMemo.call(void 0,
61
+ () => triplit.token ? decodeJWT(triplit.token) : void 0,
62
+ [connectionStatus]
63
+ );
64
+ return { token: payload && triplit.token, payload };
65
+ }
66
+ function decodeJWT(token) {
67
+ try {
68
+ const base64Url = token.split(".")[1];
69
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
70
+ const jsonPayload = decodeURIComponent(
71
+ atob(base64).split("").map((char) => {
72
+ return `%${`00${char.charCodeAt(0).toString(16)}`.slice(-2)}`;
73
+ }).join("")
74
+ );
75
+ return JSON.parse(jsonPayload);
76
+ } catch (error) {
77
+ console.error("Failed to decode JWT:", error);
78
+ return null;
79
+ }
80
+ }
81
+
82
+ // src/lib/triplit/use-list-accounts.ts
83
+ function useListAccounts({
84
+ triplit,
85
+ modelNames,
86
+ usePlural,
87
+ isPending
88
+ }) {
89
+ const modelName = getModelName({
90
+ namespace: "account",
91
+ modelNames,
92
+ usePlural
93
+ });
94
+ const { payload } = useTriplitToken(triplit);
95
+ const { results, error, fetching } = useConditionalQuery(
96
+ triplit,
97
+ (payload == null ? void 0 : payload.sub) && triplit.query(modelName)
98
+ );
99
+ return {
100
+ data: results,
101
+ isPending: isPending || fetching,
102
+ error
103
+ };
104
+ }
105
+
106
+ // src/lib/triplit/use-list-sessions.ts
107
+ function useListSessions({
108
+ triplit,
109
+ modelNames,
110
+ usePlural,
111
+ isPending
112
+ }) {
113
+ const modelName = getModelName({
114
+ namespace: "session",
115
+ modelNames,
116
+ usePlural
117
+ });
118
+ const { payload } = useTriplitToken(triplit);
119
+ const {
120
+ results: sessions,
121
+ error,
122
+ fetching
123
+ } = useConditionalQuery(triplit, (payload == null ? void 0 : payload.sub) && triplit.query(modelName));
124
+ return {
125
+ data: sessions,
126
+ isPending: isPending || fetching,
127
+ error
128
+ };
129
+ }
130
+
131
+ // src/lib/triplit/use-session.ts
132
+ function useSession({
133
+ triplit,
134
+ sessionData,
135
+ isPending,
136
+ refetch,
137
+ usePlural,
138
+ modelNames
139
+ }) {
140
+ const modelName = getModelName({
141
+ namespace: "user",
142
+ modelNames,
143
+ usePlural
144
+ });
145
+ const { payload } = useTriplitToken(triplit);
146
+ const { result: user, error } = useConditionalQueryOne(
147
+ triplit,
148
+ (payload == null ? void 0 : payload.sub) && triplit.query(modelName)
149
+ );
150
+ return {
151
+ data: sessionData ? {
152
+ session: sessionData.session,
153
+ user: (sessionData == null ? void 0 : sessionData.user.id) === (user == null ? void 0 : user.id) ? user : sessionData.user
154
+ } : null,
155
+ error,
156
+ isPending,
157
+ refetch: refetch || (() => {
158
+ })
159
+ };
160
+ }
161
+
162
+ // src/lib/triplit/use-triplit-hooks.ts
163
+ function useTriplitHooks({
164
+ triplit,
165
+ usePlural = true,
166
+ modelNames,
167
+ sessionData,
168
+ isPending
169
+ }) {
170
+ const hooks = _react.useMemo.call(void 0, () => {
171
+ return {
172
+ useSession: () => useSession({
173
+ triplit,
174
+ modelNames,
175
+ usePlural,
176
+ sessionData,
177
+ isPending
178
+ }),
179
+ useListAccounts: () => useListAccounts({
180
+ triplit,
181
+ modelNames,
182
+ usePlural,
183
+ sessionData,
184
+ isPending
185
+ }),
186
+ useListSessions: () => useListSessions({
187
+ triplit,
188
+ modelNames,
189
+ usePlural,
190
+ sessionData,
191
+ isPending
192
+ })
193
+ };
194
+ }, [triplit, modelNames, usePlural, sessionData, isPending]);
195
+ return {
196
+ hooks
197
+ };
198
+ }
199
+
200
+
201
+ exports.useTriplitHooks = useTriplitHooks;
@@ -0,0 +1,31 @@
1
+ import { TriplitClient } from '@triplit/client';
2
+ import { User } from 'better-auth';
3
+ import { S as Session, R as Refetch, a as AuthHooks } from './auth-hooks-IOEvlYYv.cjs';
4
+ import '@better-fetch/fetch';
5
+ import 'better-auth/plugins/organization';
6
+ import 'better-auth/react';
7
+ import 'inspector';
8
+ import 'better-auth/client/plugins';
9
+ import 'better-auth/plugins/passkey';
10
+
11
+ declare const namespaces: readonly ["user", "session", "account", "passkey"];
12
+ type Namespace = (typeof namespaces)[number];
13
+ type ModelNames = {
14
+ [key in Namespace]: string;
15
+ };
16
+ interface UseTriplitOptionsProps {
17
+ triplit: TriplitClient<any>;
18
+ modelNames?: Partial<ModelNames>;
19
+ usePlural?: boolean;
20
+ sessionData?: {
21
+ user: User;
22
+ session: Session;
23
+ } | null;
24
+ refetch?: Refetch;
25
+ isPending: boolean;
26
+ }
27
+ declare function useTriplitHooks({ triplit, usePlural, modelNames, sessionData, isPending }: UseTriplitOptionsProps): {
28
+ hooks: AuthHooks;
29
+ };
30
+
31
+ export { type UseTriplitOptionsProps, useTriplitHooks };
@@ -0,0 +1,31 @@
1
+ import { TriplitClient } from '@triplit/client';
2
+ import { User } from 'better-auth';
3
+ import { S as Session, R as Refetch, a as AuthHooks } from './auth-hooks-IOEvlYYv.js';
4
+ import '@better-fetch/fetch';
5
+ import 'better-auth/plugins/organization';
6
+ import 'better-auth/react';
7
+ import 'inspector';
8
+ import 'better-auth/client/plugins';
9
+ import 'better-auth/plugins/passkey';
10
+
11
+ declare const namespaces: readonly ["user", "session", "account", "passkey"];
12
+ type Namespace = (typeof namespaces)[number];
13
+ type ModelNames = {
14
+ [key in Namespace]: string;
15
+ };
16
+ interface UseTriplitOptionsProps {
17
+ triplit: TriplitClient<any>;
18
+ modelNames?: Partial<ModelNames>;
19
+ usePlural?: boolean;
20
+ sessionData?: {
21
+ user: User;
22
+ session: Session;
23
+ } | null;
24
+ refetch?: Refetch;
25
+ isPending: boolean;
26
+ }
27
+ declare function useTriplitHooks({ triplit, usePlural, modelNames, sessionData, isPending }: UseTriplitOptionsProps): {
28
+ hooks: AuthHooks;
29
+ };
30
+
31
+ export { type UseTriplitOptionsProps, useTriplitHooks };
@@ -0,0 +1,201 @@
1
+ // src/lib/triplit/use-triplit-hooks.ts
2
+ import { useMemo as useMemo3 } from "react";
3
+
4
+ // src/lib/triplit/model-names.ts
5
+ var getModelName = ({
6
+ namespace,
7
+ modelNames,
8
+ usePlural = false
9
+ }) => {
10
+ return (modelNames == null ? void 0 : modelNames[namespace]) || `${namespace}${usePlural ? "s" : ""}`;
11
+ };
12
+
13
+ // src/lib/triplit/use-conditional-query.ts
14
+ import { createStateSubscription } from "@triplit/react";
15
+ import { useCallback, useMemo, useState, useSyncExternalStore } from "react";
16
+ function useConditionalQuery(client, query, options) {
17
+ const stringifiedQuery = !(options == null ? void 0 : options.disabled) && query && JSON.stringify(query);
18
+ const localOnly = !!(options == null ? void 0 : options.localOnly);
19
+ const [remoteFulfilled, setRemoteFulfilled] = useState(false);
20
+ const defaultValue = {
21
+ results: void 0,
22
+ fetching: true,
23
+ fetchingLocal: false,
24
+ fetchingRemote: false,
25
+ error: void 0
26
+ };
27
+ const [subscribe, snapshot] = useMemo(
28
+ () => stringifiedQuery ? createStateSubscription(client, query, {
29
+ ...options,
30
+ onRemoteFulfilled: () => setRemoteFulfilled(true)
31
+ }) : [() => () => {
32
+ }, () => defaultValue],
33
+ [stringifiedQuery, localOnly]
34
+ );
35
+ const getServerSnapshot = useCallback(() => snapshot(), [snapshot]);
36
+ const { fetching, ...rest } = useSyncExternalStore(
37
+ subscribe,
38
+ snapshot,
39
+ getServerSnapshot
40
+ );
41
+ return { fetching: fetching && !remoteFulfilled, ...rest };
42
+ }
43
+ function useConditionalQueryOne(client, query, options) {
44
+ const { fetching, fetchingLocal, fetchingRemote, results, error } = useConditionalQuery(
45
+ client,
46
+ query ? { ...query, limit: 1 } : query,
47
+ options
48
+ );
49
+ const result = useMemo(() => {
50
+ return (results == null ? void 0 : results[0]) ?? null;
51
+ }, [results]);
52
+ return { fetching, fetchingLocal, fetchingRemote, result, error };
53
+ }
54
+
55
+ // src/lib/triplit/use-triplit-token.ts
56
+ import { useConnectionStatus } from "@triplit/react";
57
+ import { useMemo as useMemo2 } from "react";
58
+ function useTriplitToken(triplit) {
59
+ const connectionStatus = useConnectionStatus(triplit);
60
+ const payload = useMemo2(
61
+ () => triplit.token ? decodeJWT(triplit.token) : void 0,
62
+ [connectionStatus]
63
+ );
64
+ return { token: payload && triplit.token, payload };
65
+ }
66
+ function decodeJWT(token) {
67
+ try {
68
+ const base64Url = token.split(".")[1];
69
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
70
+ const jsonPayload = decodeURIComponent(
71
+ atob(base64).split("").map((char) => {
72
+ return `%${`00${char.charCodeAt(0).toString(16)}`.slice(-2)}`;
73
+ }).join("")
74
+ );
75
+ return JSON.parse(jsonPayload);
76
+ } catch (error) {
77
+ console.error("Failed to decode JWT:", error);
78
+ return null;
79
+ }
80
+ }
81
+
82
+ // src/lib/triplit/use-list-accounts.ts
83
+ function useListAccounts({
84
+ triplit,
85
+ modelNames,
86
+ usePlural,
87
+ isPending
88
+ }) {
89
+ const modelName = getModelName({
90
+ namespace: "account",
91
+ modelNames,
92
+ usePlural
93
+ });
94
+ const { payload } = useTriplitToken(triplit);
95
+ const { results, error, fetching } = useConditionalQuery(
96
+ triplit,
97
+ (payload == null ? void 0 : payload.sub) && triplit.query(modelName)
98
+ );
99
+ return {
100
+ data: results,
101
+ isPending: isPending || fetching,
102
+ error
103
+ };
104
+ }
105
+
106
+ // src/lib/triplit/use-list-sessions.ts
107
+ function useListSessions({
108
+ triplit,
109
+ modelNames,
110
+ usePlural,
111
+ isPending
112
+ }) {
113
+ const modelName = getModelName({
114
+ namespace: "session",
115
+ modelNames,
116
+ usePlural
117
+ });
118
+ const { payload } = useTriplitToken(triplit);
119
+ const {
120
+ results: sessions,
121
+ error,
122
+ fetching
123
+ } = useConditionalQuery(triplit, (payload == null ? void 0 : payload.sub) && triplit.query(modelName));
124
+ return {
125
+ data: sessions,
126
+ isPending: isPending || fetching,
127
+ error
128
+ };
129
+ }
130
+
131
+ // src/lib/triplit/use-session.ts
132
+ function useSession({
133
+ triplit,
134
+ sessionData,
135
+ isPending,
136
+ refetch,
137
+ usePlural,
138
+ modelNames
139
+ }) {
140
+ const modelName = getModelName({
141
+ namespace: "user",
142
+ modelNames,
143
+ usePlural
144
+ });
145
+ const { payload } = useTriplitToken(triplit);
146
+ const { result: user, error } = useConditionalQueryOne(
147
+ triplit,
148
+ (payload == null ? void 0 : payload.sub) && triplit.query(modelName)
149
+ );
150
+ return {
151
+ data: sessionData ? {
152
+ session: sessionData.session,
153
+ user: (sessionData == null ? void 0 : sessionData.user.id) === (user == null ? void 0 : user.id) ? user : sessionData.user
154
+ } : null,
155
+ error,
156
+ isPending,
157
+ refetch: refetch || (() => {
158
+ })
159
+ };
160
+ }
161
+
162
+ // src/lib/triplit/use-triplit-hooks.ts
163
+ function useTriplitHooks({
164
+ triplit,
165
+ usePlural = true,
166
+ modelNames,
167
+ sessionData,
168
+ isPending
169
+ }) {
170
+ const hooks = useMemo3(() => {
171
+ return {
172
+ useSession: () => useSession({
173
+ triplit,
174
+ modelNames,
175
+ usePlural,
176
+ sessionData,
177
+ isPending
178
+ }),
179
+ useListAccounts: () => useListAccounts({
180
+ triplit,
181
+ modelNames,
182
+ usePlural,
183
+ sessionData,
184
+ isPending
185
+ }),
186
+ useListSessions: () => useListSessions({
187
+ triplit,
188
+ modelNames,
189
+ usePlural,
190
+ sessionData,
191
+ isPending
192
+ })
193
+ };
194
+ }, [triplit, modelNames, usePlural, sessionData, isPending]);
195
+ return {
196
+ hooks
197
+ };
198
+ }
199
+ export {
200
+ useTriplitHooks
201
+ };
@@ -0,0 +1,3 @@
1
+ declare function getViewByPath<T extends object>(viewPaths: T, path?: string): Extract<keyof T, string> | undefined;
2
+
3
+ export { getViewByPath as g };
@@ -0,0 +1,3 @@
1
+ declare function getViewByPath<T extends object>(viewPaths: T, path?: string): Extract<keyof T, string> | undefined;
2
+
3
+ export { getViewByPath as g };