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.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
- package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
- package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
- package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
- package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
- package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
- package/dist/chunk-BDFQSFBU.js +750 -0
- package/dist/chunk-CRAHKL2C.cjs +801 -0
- package/dist/chunk-MJPOA6PK.js +801 -0
- package/dist/chunk-SV64DXGW.cjs +750 -0
- package/dist/index.cjs +12618 -0
- package/dist/index.d.cts +771 -0
- package/dist/index.d.ts +771 -0
- package/dist/index.js +12618 -0
- package/dist/instantdb.cjs +189 -0
- package/dist/instantdb.d.cts +36 -0
- package/dist/instantdb.d.ts +36 -0
- package/dist/instantdb.js +189 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/server.cjs +194 -0
- package/dist/server.d.cts +35 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +194 -0
- package/dist/style.css +1 -0
- package/dist/tanstack.cjs +153 -0
- package/dist/tanstack.d.cts +18 -0
- package/dist/tanstack.d.ts +18 -0
- package/dist/tanstack.js +153 -0
- package/dist/triplit.cjs +201 -0
- package/dist/triplit.d.cts +31 -0
- package/dist/triplit.d.ts +31 -0
- package/dist/triplit.js +201 -0
- package/dist/utils-C5R37WDe.d.cts +3 -0
- package/dist/utils-C5R37WDe.d.ts +3 -0
- package/dist/view-paths-CHSJf5dv.d.cts +645 -0
- package/dist/view-paths-CHSJf5dv.d.ts +645 -0
- package/package.json +156 -0
- package/src/components/account/account-view.tsx +220 -0
- package/src/components/auth/auth-callback.tsx +36 -0
- package/src/components/auth/auth-form.tsx +277 -0
- package/src/components/auth/auth-view.tsx +389 -0
- package/src/components/auth/email-otp-button.tsx +53 -0
- package/src/components/auth/forms/email-otp-form.tsx +288 -0
- package/src/components/auth/forms/forgot-password-form.tsx +168 -0
- package/src/components/auth/forms/magic-link-form.tsx +191 -0
- package/src/components/auth/forms/recover-account-form.tsx +138 -0
- package/src/components/auth/forms/reset-password-form.tsx +215 -0
- package/src/components/auth/forms/sign-in-form.tsx +289 -0
- package/src/components/auth/forms/sign-up-form.tsx +788 -0
- package/src/components/auth/forms/two-factor-form.tsx +372 -0
- package/src/components/auth/magic-link-button.tsx +54 -0
- package/src/components/auth/one-tap.tsx +48 -0
- package/src/components/auth/otp-input-group.tsx +65 -0
- package/src/components/auth/passkey-button.tsx +85 -0
- package/src/components/auth/provider-button.tsx +141 -0
- package/src/components/auth/sign-out.tsx +25 -0
- package/src/components/auth-loading.tsx +21 -0
- package/src/components/captcha/captcha.tsx +79 -0
- package/src/components/captcha/recaptcha-badge.tsx +61 -0
- package/src/components/captcha/recaptcha-v2.tsx +58 -0
- package/src/components/captcha/recaptcha-v3.tsx +73 -0
- package/src/components/email/email-template.tsx +216 -0
- package/src/components/form-error.tsx +27 -0
- package/src/components/organization/accept-invitation-card.tsx +362 -0
- package/src/components/organization/create-organization-dialog.tsx +395 -0
- package/src/components/organization/delete-organization-card.tsx +101 -0
- package/src/components/organization/delete-organization-dialog.tsx +209 -0
- package/src/components/organization/invitation-cell.tsx +156 -0
- package/src/components/organization/invite-member-dialog.tsx +258 -0
- package/src/components/organization/leave-organization-dialog.tsx +150 -0
- package/src/components/organization/member-cell.tsx +187 -0
- package/src/components/organization/organization-cell-view.tsx +122 -0
- package/src/components/organization/organization-cell.tsx +154 -0
- package/src/components/organization/organization-invitations-card.tsx +94 -0
- package/src/components/organization/organization-logo-card.tsx +308 -0
- package/src/components/organization/organization-logo.tsx +120 -0
- package/src/components/organization/organization-members-card.tsx +155 -0
- package/src/components/organization/organization-name-card.tsx +204 -0
- package/src/components/organization/organization-settings-cards.tsx +67 -0
- package/src/components/organization/organization-slug-card.tsx +223 -0
- package/src/components/organization/organization-switcher.tsx +512 -0
- package/src/components/organization/organization-view.tsx +228 -0
- package/src/components/organization/organizations-card.tsx +72 -0
- package/src/components/organization/personal-account-view.tsx +115 -0
- package/src/components/organization/remove-member-dialog.tsx +144 -0
- package/src/components/organization/update-member-role-dialog.tsx +213 -0
- package/src/components/organization/user-invitations-card.tsx +238 -0
- package/src/components/password-input.tsx +56 -0
- package/src/components/provider-icons.tsx +385 -0
- package/src/components/redirect-to-sign-in.tsx +16 -0
- package/src/components/redirect-to-sign-up.tsx +16 -0
- package/src/components/settings/account/account-cell.tsx +158 -0
- package/src/components/settings/account/accounts-card.tsx +75 -0
- package/src/components/settings/account/delete-account-card.tsx +65 -0
- package/src/components/settings/account/delete-account-dialog.tsx +231 -0
- package/src/components/settings/account/update-avatar-card.tsx +198 -0
- package/src/components/settings/account/update-field-card.tsx +282 -0
- package/src/components/settings/account/update-name-card.tsx +39 -0
- package/src/components/settings/account/update-username-card.tsx +42 -0
- package/src/components/settings/account-settings-cards.tsx +123 -0
- package/src/components/settings/api-key/api-key-cell.tsx +108 -0
- package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
- package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
- package/src/components/settings/api-key/api-keys-card.tsx +98 -0
- package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
- package/src/components/settings/passkey/passkey-cell.tsx +113 -0
- package/src/components/settings/passkey/passkeys-card.tsx +111 -0
- package/src/components/settings/providers/provider-cell.tsx +152 -0
- package/src/components/settings/providers/providers-card.tsx +108 -0
- package/src/components/settings/security/change-email-card.tsx +200 -0
- package/src/components/settings/security/change-password-card.tsx +326 -0
- package/src/components/settings/security/session-cell.tsx +120 -0
- package/src/components/settings/security/sessions-card.tsx +58 -0
- package/src/components/settings/security-settings-cards.tsx +111 -0
- package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
- package/src/components/settings/shared/settings-action-button.tsx +51 -0
- package/src/components/settings/shared/settings-card-footer.tsx +94 -0
- package/src/components/settings/shared/settings-card-header.tsx +67 -0
- package/src/components/settings/shared/settings-card.tsx +106 -0
- package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
- package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
- package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
- package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
- package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
- package/src/components/signed-in.tsx +20 -0
- package/src/components/signed-out.tsx +20 -0
- package/src/components/ui/alert.tsx +66 -0
- package/src/components/ui/avatar.tsx +53 -0
- package/src/components/ui/button.tsx +59 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/checkbox.tsx +32 -0
- package/src/components/ui/dialog.tsx +143 -0
- package/src/components/ui/drawer.tsx +135 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/form.tsx +167 -0
- package/src/components/ui/input-otp.tsx +77 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/select.tsx +185 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/tabs.tsx +66 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/user-avatar.tsx +147 -0
- package/src/components/user-button.tsx +409 -0
- package/src/components/user-view.tsx +138 -0
- package/src/hooks/use-auth-data.ts +184 -0
- package/src/hooks/use-authenticate.ts +62 -0
- package/src/hooks/use-captcha.tsx +138 -0
- package/src/hooks/use-current-organization.ts +59 -0
- package/src/hooks/use-hydrated.ts +13 -0
- package/src/hooks/use-lang.ts +32 -0
- package/src/hooks/use-success-transition.ts +51 -0
- package/src/hooks/use-theme.ts +39 -0
- package/src/index.ts +65 -0
- package/src/instantdb.ts +1 -0
- package/src/lib/auth-data-cache.ts +90 -0
- package/src/lib/auth-ui-provider.tsx +658 -0
- package/src/lib/gravatar-utils.ts +58 -0
- package/src/lib/image-utils.ts +55 -0
- package/src/lib/instantdb/model-names.ts +24 -0
- package/src/lib/instantdb/use-instant-options.ts +98 -0
- package/src/lib/instantdb/use-list-accounts.ts +38 -0
- package/src/lib/instantdb/use-list-sessions.ts +53 -0
- package/src/lib/instantdb/use-session.ts +55 -0
- package/src/lib/organization-refetcher.tsx +56 -0
- package/src/lib/social-providers.ts +144 -0
- package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
- package/src/lib/tanstack/use-tanstack-options.ts +112 -0
- package/src/lib/triplit/model-names.ts +24 -0
- package/src/lib/triplit/use-conditional-query.ts +82 -0
- package/src/lib/triplit/use-list-accounts.ts +31 -0
- package/src/lib/triplit/use-list-sessions.ts +33 -0
- package/src/lib/triplit/use-session.ts +42 -0
- package/src/lib/triplit/use-triplit-hooks.ts +68 -0
- package/src/lib/triplit/use-triplit-token.ts +44 -0
- package/src/lib/utils.ts +105 -0
- package/src/lib/view-paths.ts +55 -0
- package/src/localization/admin-error-codes.ts +20 -0
- package/src/localization/anonymous-error-codes.ts +6 -0
- package/src/localization/api-key-error-codes.ts +32 -0
- package/src/localization/auth-localization.ts +740 -0
- package/src/localization/base-error-codes.ts +27 -0
- package/src/localization/captcha-error-codes.ts +17 -0
- package/src/localization/email-otp-error-codes.ts +7 -0
- package/src/localization/generic-oauth-error-codes.ts +3 -0
- package/src/localization/haveibeenpwned-error-codes.ts +4 -0
- package/src/localization/multi-session-error-codes.ts +3 -0
- package/src/localization/organization-error-codes.ts +57 -0
- package/src/localization/passkey-error-codes.ts +10 -0
- package/src/localization/phone-number-error-codes.ts +10 -0
- package/src/localization/stripe-localization.ts +12 -0
- package/src/localization/two-factor-error-codes.ts +12 -0
- package/src/localization/username-error-codes.ts +9 -0
- package/src/server.ts +4 -0
- package/src/style.css +1 -0
- package/src/tanstack.ts +1 -0
- package/src/triplit.ts +1 -0
- package/src/types/account-options.ts +35 -0
- package/src/types/additional-fields.ts +21 -0
- package/src/types/any-auth-client.ts +6 -0
- package/src/types/api-key.ts +9 -0
- package/src/types/auth-client.ts +37 -0
- package/src/types/auth-hooks.ts +61 -0
- package/src/types/auth-mutators.ts +17 -0
- package/src/types/avatar-options.ts +29 -0
- package/src/types/captcha-options.ts +32 -0
- package/src/types/captcha-provider.ts +6 -0
- package/src/types/credentials-options.ts +32 -0
- package/src/types/delete-user-options.ts +7 -0
- package/src/types/fetch-error.ts +6 -0
- package/src/types/generic-oauth-options.ts +16 -0
- package/src/types/gravatar-options.ts +21 -0
- package/src/types/image.ts +7 -0
- package/src/types/invitation.ts +10 -0
- package/src/types/link.ts +7 -0
- package/src/types/organization-options.ts +106 -0
- package/src/types/password-validation.ts +16 -0
- package/src/types/profile.ts +15 -0
- package/src/types/refetch.ts +1 -0
- package/src/types/render-toast.ts +9 -0
- package/src/types/sign-up-options.ts +7 -0
- package/src/types/social-options.ts +16 -0
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
import {
|
|
2
|
+
accountViewPaths,
|
|
3
|
+
authLocalization,
|
|
4
|
+
authViewPaths,
|
|
5
|
+
getLocalizedError,
|
|
6
|
+
organizationViewPaths
|
|
7
|
+
} from "./chunk-MJPOA6PK.js";
|
|
8
|
+
|
|
9
|
+
// src/hooks/use-auth-data.ts
|
|
10
|
+
import {
|
|
11
|
+
useCallback,
|
|
12
|
+
useContext as useContext4,
|
|
13
|
+
useEffect as useEffect5,
|
|
14
|
+
useRef,
|
|
15
|
+
useState as useState3,
|
|
16
|
+
useSyncExternalStore as useSyncExternalStore2
|
|
17
|
+
} from "react";
|
|
18
|
+
|
|
19
|
+
// src/lib/auth-data-cache.ts
|
|
20
|
+
var AuthDataCache = class {
|
|
21
|
+
cache = /* @__PURE__ */ new Map();
|
|
22
|
+
listeners = /* @__PURE__ */ new Map();
|
|
23
|
+
inFlightRequests = /* @__PURE__ */ new Map();
|
|
24
|
+
get(key) {
|
|
25
|
+
return this.cache.get(key);
|
|
26
|
+
}
|
|
27
|
+
set(key, data) {
|
|
28
|
+
const entry = {
|
|
29
|
+
data,
|
|
30
|
+
timestamp: Date.now(),
|
|
31
|
+
isRefetching: false
|
|
32
|
+
};
|
|
33
|
+
this.cache.set(key, entry);
|
|
34
|
+
this.notify(key);
|
|
35
|
+
}
|
|
36
|
+
setRefetching(key, isRefetching) {
|
|
37
|
+
const entry = this.cache.get(key);
|
|
38
|
+
if (entry) {
|
|
39
|
+
entry.isRefetching = isRefetching;
|
|
40
|
+
this.notify(key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
clear(key) {
|
|
44
|
+
if (key) {
|
|
45
|
+
this.cache.delete(key);
|
|
46
|
+
this.inFlightRequests.delete(key);
|
|
47
|
+
this.notify(key);
|
|
48
|
+
} else {
|
|
49
|
+
this.cache.clear();
|
|
50
|
+
this.inFlightRequests.clear();
|
|
51
|
+
const keys = Array.from(this.listeners.keys());
|
|
52
|
+
for (const key2 of keys) {
|
|
53
|
+
this.notify(key2);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
getInFlightRequest(key) {
|
|
58
|
+
return this.inFlightRequests.get(key);
|
|
59
|
+
}
|
|
60
|
+
setInFlightRequest(key, promise) {
|
|
61
|
+
this.inFlightRequests.set(key, promise);
|
|
62
|
+
}
|
|
63
|
+
removeInFlightRequest(key) {
|
|
64
|
+
this.inFlightRequests.delete(key);
|
|
65
|
+
}
|
|
66
|
+
subscribe(key, callback) {
|
|
67
|
+
if (!this.listeners.has(key)) {
|
|
68
|
+
this.listeners.set(key, /* @__PURE__ */ new Set());
|
|
69
|
+
}
|
|
70
|
+
this.listeners.get(key).add(callback);
|
|
71
|
+
return () => {
|
|
72
|
+
const callbacks = this.listeners.get(key);
|
|
73
|
+
if (callbacks) {
|
|
74
|
+
callbacks.delete(callback);
|
|
75
|
+
if (callbacks.size === 0) {
|
|
76
|
+
this.listeners.delete(key);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
notify(key) {
|
|
82
|
+
const callbacks = this.listeners.get(key);
|
|
83
|
+
if (callbacks) {
|
|
84
|
+
const callbackArray = Array.from(callbacks);
|
|
85
|
+
for (const callback of callbackArray) {
|
|
86
|
+
callback();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var authDataCache = new AuthDataCache();
|
|
92
|
+
|
|
93
|
+
// src/lib/auth-ui-provider.tsx
|
|
94
|
+
import { createContext, useMemo as useMemo2 } from "react";
|
|
95
|
+
import { toast } from "sonner";
|
|
96
|
+
|
|
97
|
+
// src/components/captcha/recaptcha-v3.tsx
|
|
98
|
+
import {
|
|
99
|
+
GoogleReCaptchaProvider,
|
|
100
|
+
useGoogleReCaptcha
|
|
101
|
+
} from "@wojtekmaj/react-recaptcha-v3";
|
|
102
|
+
import { useContext, useEffect as useEffect3 } from "react";
|
|
103
|
+
|
|
104
|
+
// src/hooks/use-hydrated.ts
|
|
105
|
+
import { useSyncExternalStore } from "react";
|
|
106
|
+
function subscribe() {
|
|
107
|
+
return () => {
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function useIsHydrated() {
|
|
111
|
+
return useSyncExternalStore(
|
|
112
|
+
subscribe,
|
|
113
|
+
() => true,
|
|
114
|
+
() => false
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/hooks/use-lang.ts
|
|
119
|
+
import { useEffect, useState } from "react";
|
|
120
|
+
function useLang() {
|
|
121
|
+
const [lang, setLang] = useState();
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const checkLang = () => {
|
|
124
|
+
const currentLang = document.documentElement.getAttribute("lang");
|
|
125
|
+
setLang(currentLang ?? void 0);
|
|
126
|
+
};
|
|
127
|
+
checkLang();
|
|
128
|
+
const observer = new MutationObserver((mutations) => {
|
|
129
|
+
for (const mutation of mutations) {
|
|
130
|
+
if (mutation.attributeName === "lang") {
|
|
131
|
+
checkLang();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
observer.observe(document.documentElement, { attributes: true });
|
|
136
|
+
return () => {
|
|
137
|
+
observer.disconnect();
|
|
138
|
+
};
|
|
139
|
+
}, []);
|
|
140
|
+
return { lang };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/hooks/use-theme.ts
|
|
144
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
145
|
+
function useTheme() {
|
|
146
|
+
const [theme, setTheme] = useState2("light");
|
|
147
|
+
useEffect2(() => {
|
|
148
|
+
const checkTheme = () => {
|
|
149
|
+
var _a;
|
|
150
|
+
const isDark = document.documentElement.classList.contains("dark") || ((_a = document.documentElement.getAttribute("style")) == null ? void 0 : _a.includes("color-scheme: dark"));
|
|
151
|
+
setTheme(isDark ? "dark" : "light");
|
|
152
|
+
};
|
|
153
|
+
checkTheme();
|
|
154
|
+
const observer = new MutationObserver((mutations) => {
|
|
155
|
+
for (const mutation of mutations) {
|
|
156
|
+
if (mutation.attributeName === "style" || mutation.attributeName === "class") {
|
|
157
|
+
checkTheme();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
observer.observe(document.documentElement, { attributes: true });
|
|
162
|
+
return () => {
|
|
163
|
+
observer.disconnect();
|
|
164
|
+
};
|
|
165
|
+
}, []);
|
|
166
|
+
return { theme };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/components/captcha/recaptcha-v3.tsx
|
|
170
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
171
|
+
function RecaptchaV3({ children }) {
|
|
172
|
+
const isHydrated = useIsHydrated();
|
|
173
|
+
const { captcha } = useContext(AuthUIContext);
|
|
174
|
+
if ((captcha == null ? void 0 : captcha.provider) !== "google-recaptcha-v3") return children;
|
|
175
|
+
return /* @__PURE__ */ jsxs(
|
|
176
|
+
GoogleReCaptchaProvider,
|
|
177
|
+
{
|
|
178
|
+
reCaptchaKey: captcha.siteKey,
|
|
179
|
+
useEnterprise: captcha.enterprise,
|
|
180
|
+
useRecaptchaNet: captcha.recaptchaNet,
|
|
181
|
+
children: [
|
|
182
|
+
isHydrated && /* @__PURE__ */ jsx("style", { children: `
|
|
183
|
+
.grecaptcha-badge {
|
|
184
|
+
visibility: hidden;
|
|
185
|
+
border-radius: var(--radius) !important;
|
|
186
|
+
--tw-shadow: 0 1px 2px 0 var(--tw-shadow-color, #0000000d);
|
|
187
|
+
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;
|
|
188
|
+
border-style: var(--tw-border-style) !important;
|
|
189
|
+
border-width: 1px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.dark .grecaptcha-badge {
|
|
193
|
+
border-color: var(--input) !important;
|
|
194
|
+
}
|
|
195
|
+
` }),
|
|
196
|
+
/* @__PURE__ */ jsx(RecaptchaV3Style, {}),
|
|
197
|
+
children
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
function RecaptchaV3Style() {
|
|
203
|
+
const { executeRecaptcha } = useGoogleReCaptcha();
|
|
204
|
+
const { theme } = useTheme();
|
|
205
|
+
const { lang } = useLang();
|
|
206
|
+
useEffect3(() => {
|
|
207
|
+
if (!executeRecaptcha) return;
|
|
208
|
+
const updateRecaptcha = async () => {
|
|
209
|
+
const iframe = document.querySelector(
|
|
210
|
+
"iframe[title='reCAPTCHA']"
|
|
211
|
+
);
|
|
212
|
+
if (iframe) {
|
|
213
|
+
const iframeSrcUrl = new URL(iframe.src);
|
|
214
|
+
iframeSrcUrl.searchParams.set("theme", theme);
|
|
215
|
+
if (lang) iframeSrcUrl.searchParams.set("hl", lang);
|
|
216
|
+
iframe.src = iframeSrcUrl.toString();
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
updateRecaptcha();
|
|
220
|
+
}, [executeRecaptcha, theme, lang]);
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/lib/organization-refetcher.tsx
|
|
225
|
+
import { useContext as useContext3, useEffect as useEffect4 } from "react";
|
|
226
|
+
|
|
227
|
+
// src/hooks/use-current-organization.ts
|
|
228
|
+
import { useContext as useContext2, useMemo } from "react";
|
|
229
|
+
function useCurrentOrganization({
|
|
230
|
+
slug: slugProp
|
|
231
|
+
} = {}) {
|
|
232
|
+
const {
|
|
233
|
+
organization: organizationOptions,
|
|
234
|
+
hooks: { useActiveOrganization, useListOrganizations }
|
|
235
|
+
} = useContext2(AuthUIContext);
|
|
236
|
+
const { pathMode, slug: contextSlug } = organizationOptions || {};
|
|
237
|
+
let data;
|
|
238
|
+
let isPending;
|
|
239
|
+
let isRefetching;
|
|
240
|
+
let refetch;
|
|
241
|
+
const {
|
|
242
|
+
data: organizations,
|
|
243
|
+
isPending: organizationsPending,
|
|
244
|
+
isRefetching: organizationsRefetching
|
|
245
|
+
} = useListOrganizations();
|
|
246
|
+
if (pathMode === "slug") {
|
|
247
|
+
const slug = slugProp || contextSlug;
|
|
248
|
+
data = organizations == null ? void 0 : organizations.find((organization) => organization.slug === slug);
|
|
249
|
+
isPending = organizationsPending;
|
|
250
|
+
isRefetching = organizationsRefetching;
|
|
251
|
+
} else {
|
|
252
|
+
const {
|
|
253
|
+
data: activeOrganization,
|
|
254
|
+
isPending: organizationPending,
|
|
255
|
+
isRefetching: organizationRefetching,
|
|
256
|
+
refetch: refetchOrganization
|
|
257
|
+
} = useActiveOrganization();
|
|
258
|
+
refetch = refetchOrganization;
|
|
259
|
+
data = activeOrganization;
|
|
260
|
+
isPending = organizationPending;
|
|
261
|
+
isRefetching = organizationRefetching;
|
|
262
|
+
}
|
|
263
|
+
return useMemo(
|
|
264
|
+
() => ({
|
|
265
|
+
data,
|
|
266
|
+
isPending,
|
|
267
|
+
isRefetching,
|
|
268
|
+
refetch
|
|
269
|
+
}),
|
|
270
|
+
[data, isPending, isRefetching, refetch]
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/lib/organization-refetcher.tsx
|
|
275
|
+
var OrganizationRefetcher = () => {
|
|
276
|
+
const {
|
|
277
|
+
hooks: { useListOrganizations, useSession },
|
|
278
|
+
organization: organizationOptions,
|
|
279
|
+
navigate,
|
|
280
|
+
redirectTo
|
|
281
|
+
} = useContext3(AuthUIContext);
|
|
282
|
+
const { slug, pathMode, personalPath } = organizationOptions || {};
|
|
283
|
+
const { data: sessionData } = useSession();
|
|
284
|
+
const {
|
|
285
|
+
data: organization,
|
|
286
|
+
isPending: organizationPending,
|
|
287
|
+
isRefetching: organizationRefetching,
|
|
288
|
+
refetch: refetchOrganization
|
|
289
|
+
} = useCurrentOrganization();
|
|
290
|
+
const { refetch: refetchListOrganizations } = useListOrganizations();
|
|
291
|
+
const { data: organizations } = useListOrganizations();
|
|
292
|
+
useEffect4(() => {
|
|
293
|
+
if (!(sessionData == null ? void 0 : sessionData.user.id)) return;
|
|
294
|
+
if (organization || organizations) {
|
|
295
|
+
refetchOrganization == null ? void 0 : refetchOrganization();
|
|
296
|
+
refetchListOrganizations == null ? void 0 : refetchListOrganizations();
|
|
297
|
+
}
|
|
298
|
+
}, [sessionData == null ? void 0 : sessionData.user.id]);
|
|
299
|
+
useEffect4(() => {
|
|
300
|
+
if (organizationRefetching || organizationPending) return;
|
|
301
|
+
if (slug && pathMode === "slug" && !organization) {
|
|
302
|
+
navigate(personalPath || redirectTo);
|
|
303
|
+
}
|
|
304
|
+
}, [
|
|
305
|
+
organization,
|
|
306
|
+
organizationRefetching,
|
|
307
|
+
organizationPending,
|
|
308
|
+
slug,
|
|
309
|
+
pathMode,
|
|
310
|
+
personalPath,
|
|
311
|
+
navigate,
|
|
312
|
+
redirectTo
|
|
313
|
+
]);
|
|
314
|
+
return null;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/lib/auth-ui-provider.tsx
|
|
318
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
319
|
+
var DefaultLink = ({ href, className, children }) => /* @__PURE__ */ jsx2("a", { className, href, children });
|
|
320
|
+
var defaultNavigate = (href) => {
|
|
321
|
+
window.location.href = href;
|
|
322
|
+
};
|
|
323
|
+
var defaultReplace = (href) => {
|
|
324
|
+
window.location.replace(href);
|
|
325
|
+
};
|
|
326
|
+
var defaultToast = ({ variant = "default", message }) => {
|
|
327
|
+
if (variant === "default") {
|
|
328
|
+
toast(message);
|
|
329
|
+
} else {
|
|
330
|
+
toast[variant](message);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
var AuthUIContext = createContext(
|
|
334
|
+
{}
|
|
335
|
+
);
|
|
336
|
+
var AuthUIProvider = ({
|
|
337
|
+
children,
|
|
338
|
+
authClient: authClientProp,
|
|
339
|
+
account: accountProp,
|
|
340
|
+
avatar: avatarProp,
|
|
341
|
+
deleteUser: deleteUserProp,
|
|
342
|
+
social: socialProp,
|
|
343
|
+
genericOAuth: genericOAuthProp,
|
|
344
|
+
basePath = "/auth",
|
|
345
|
+
baseURL = "",
|
|
346
|
+
captcha,
|
|
347
|
+
redirectTo = "/",
|
|
348
|
+
credentials: credentialsProp,
|
|
349
|
+
changeEmail = true,
|
|
350
|
+
freshAge = 60 * 60 * 24,
|
|
351
|
+
hooks: hooksProp,
|
|
352
|
+
mutators: mutatorsProp,
|
|
353
|
+
localization: localizationProp,
|
|
354
|
+
nameRequired = true,
|
|
355
|
+
organization: organizationProp,
|
|
356
|
+
signUp: signUpProp = true,
|
|
357
|
+
toast: toast2 = defaultToast,
|
|
358
|
+
viewPaths: viewPathsProp,
|
|
359
|
+
navigate,
|
|
360
|
+
replace,
|
|
361
|
+
Link = DefaultLink,
|
|
362
|
+
...props
|
|
363
|
+
}) => {
|
|
364
|
+
const authClient = authClientProp;
|
|
365
|
+
const avatar = useMemo2(() => {
|
|
366
|
+
if (!avatarProp) return;
|
|
367
|
+
if (avatarProp === true) {
|
|
368
|
+
return {
|
|
369
|
+
extension: "png",
|
|
370
|
+
size: 128
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
upload: avatarProp.upload,
|
|
375
|
+
delete: avatarProp.delete,
|
|
376
|
+
extension: avatarProp.extension || "png",
|
|
377
|
+
size: avatarProp.size || (avatarProp.upload ? 256 : 128)
|
|
378
|
+
};
|
|
379
|
+
}, [avatarProp]);
|
|
380
|
+
const account = useMemo2(() => {
|
|
381
|
+
var _a;
|
|
382
|
+
if (accountProp === false) return;
|
|
383
|
+
if (accountProp === true || accountProp === void 0) {
|
|
384
|
+
return {
|
|
385
|
+
basePath: "/account",
|
|
386
|
+
fields: ["image", "name"],
|
|
387
|
+
viewPaths: accountViewPaths
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
const basePath2 = ((_a = accountProp.basePath) == null ? void 0 : _a.endsWith("/")) ? accountProp.basePath.slice(0, -1) : accountProp.basePath;
|
|
391
|
+
return {
|
|
392
|
+
basePath: basePath2 ?? "/account",
|
|
393
|
+
fields: accountProp.fields || ["image", "name"],
|
|
394
|
+
viewPaths: { ...accountViewPaths, ...accountProp.viewPaths }
|
|
395
|
+
};
|
|
396
|
+
}, [accountProp]);
|
|
397
|
+
const deleteUser = useMemo2(() => {
|
|
398
|
+
if (!deleteUserProp) return;
|
|
399
|
+
if (deleteUserProp === true) {
|
|
400
|
+
return {};
|
|
401
|
+
}
|
|
402
|
+
return deleteUserProp;
|
|
403
|
+
}, [deleteUserProp]);
|
|
404
|
+
const social = useMemo2(() => {
|
|
405
|
+
if (!socialProp) return;
|
|
406
|
+
return socialProp;
|
|
407
|
+
}, [socialProp]);
|
|
408
|
+
const genericOAuth = useMemo2(() => {
|
|
409
|
+
if (!genericOAuthProp) return;
|
|
410
|
+
return genericOAuthProp;
|
|
411
|
+
}, [genericOAuthProp]);
|
|
412
|
+
const credentials = useMemo2(() => {
|
|
413
|
+
if (credentialsProp === false) return;
|
|
414
|
+
if (credentialsProp === true) {
|
|
415
|
+
return {
|
|
416
|
+
forgotPassword: true
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
...credentialsProp,
|
|
421
|
+
forgotPassword: (credentialsProp == null ? void 0 : credentialsProp.forgotPassword) ?? true
|
|
422
|
+
};
|
|
423
|
+
}, [credentialsProp]);
|
|
424
|
+
const signUp = useMemo2(() => {
|
|
425
|
+
if (signUpProp === false) return;
|
|
426
|
+
if (signUpProp === true || signUpProp === void 0) {
|
|
427
|
+
return {
|
|
428
|
+
fields: ["name"]
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
fields: signUpProp.fields || ["name"]
|
|
433
|
+
};
|
|
434
|
+
}, [signUpProp]);
|
|
435
|
+
const organization = useMemo2(() => {
|
|
436
|
+
var _a;
|
|
437
|
+
if (!organizationProp) return;
|
|
438
|
+
if (organizationProp === true) {
|
|
439
|
+
return {
|
|
440
|
+
basePath: "/organization",
|
|
441
|
+
viewPaths: organizationViewPaths,
|
|
442
|
+
customRoles: []
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
let logo;
|
|
446
|
+
if (organizationProp.logo === true) {
|
|
447
|
+
logo = {
|
|
448
|
+
extension: "png",
|
|
449
|
+
size: 128
|
|
450
|
+
};
|
|
451
|
+
} else if (organizationProp.logo) {
|
|
452
|
+
logo = {
|
|
453
|
+
upload: organizationProp.logo.upload,
|
|
454
|
+
delete: organizationProp.logo.delete,
|
|
455
|
+
extension: organizationProp.logo.extension || "png",
|
|
456
|
+
size: organizationProp.logo.size || organizationProp.logo.upload ? 256 : 128
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const basePath2 = ((_a = organizationProp.basePath) == null ? void 0 : _a.endsWith("/")) ? organizationProp.basePath.slice(0, -1) : organizationProp.basePath;
|
|
460
|
+
return {
|
|
461
|
+
...organizationProp,
|
|
462
|
+
logo,
|
|
463
|
+
basePath: basePath2 ?? "/organization",
|
|
464
|
+
customRoles: organizationProp.customRoles || [],
|
|
465
|
+
viewPaths: {
|
|
466
|
+
...organizationViewPaths,
|
|
467
|
+
...organizationProp.viewPaths
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}, [organizationProp]);
|
|
471
|
+
const defaultMutators = useMemo2(() => {
|
|
472
|
+
return {
|
|
473
|
+
deleteApiKey: (params) => authClient.apiKey.delete({
|
|
474
|
+
...params,
|
|
475
|
+
fetchOptions: { throw: true }
|
|
476
|
+
}),
|
|
477
|
+
deletePasskey: (params) => authClient.passkey.deletePasskey({
|
|
478
|
+
...params,
|
|
479
|
+
fetchOptions: { throw: true }
|
|
480
|
+
}),
|
|
481
|
+
revokeDeviceSession: (params) => authClient.multiSession.revoke({
|
|
482
|
+
...params,
|
|
483
|
+
fetchOptions: { throw: true }
|
|
484
|
+
}),
|
|
485
|
+
revokeSession: (params) => authClient.revokeSession({
|
|
486
|
+
...params,
|
|
487
|
+
fetchOptions: { throw: true }
|
|
488
|
+
}),
|
|
489
|
+
setActiveSession: (params) => authClient.multiSession.setActive({
|
|
490
|
+
...params,
|
|
491
|
+
fetchOptions: { throw: true }
|
|
492
|
+
}),
|
|
493
|
+
updateOrganization: (params) => authClient.organization.update({
|
|
494
|
+
...params,
|
|
495
|
+
fetchOptions: { throw: true }
|
|
496
|
+
}),
|
|
497
|
+
updateUser: (params) => authClient.updateUser({
|
|
498
|
+
...params,
|
|
499
|
+
fetchOptions: { throw: true }
|
|
500
|
+
}),
|
|
501
|
+
unlinkAccount: (params) => authClient.unlinkAccount({
|
|
502
|
+
...params,
|
|
503
|
+
fetchOptions: { throw: true }
|
|
504
|
+
})
|
|
505
|
+
};
|
|
506
|
+
}, [authClient]);
|
|
507
|
+
const defaultHooks = useMemo2(() => {
|
|
508
|
+
return {
|
|
509
|
+
useSession: authClient.useSession,
|
|
510
|
+
useListAccounts: () => useAuthData({
|
|
511
|
+
queryFn: authClient.listAccounts,
|
|
512
|
+
cacheKey: "listAccounts"
|
|
513
|
+
}),
|
|
514
|
+
useAccountInfo: (params) => useAuthData({
|
|
515
|
+
queryFn: () => authClient.accountInfo(params),
|
|
516
|
+
cacheKey: `accountInfo:${JSON.stringify(params)}`
|
|
517
|
+
}),
|
|
518
|
+
useListDeviceSessions: () => useAuthData({
|
|
519
|
+
queryFn: authClient.multiSession.listDeviceSessions,
|
|
520
|
+
cacheKey: "listDeviceSessions"
|
|
521
|
+
}),
|
|
522
|
+
useListSessions: () => useAuthData({
|
|
523
|
+
queryFn: authClient.listSessions,
|
|
524
|
+
cacheKey: "listSessions"
|
|
525
|
+
}),
|
|
526
|
+
useListPasskeys: authClient.useListPasskeys,
|
|
527
|
+
useListApiKeys: () => useAuthData({
|
|
528
|
+
queryFn: authClient.apiKey.list,
|
|
529
|
+
cacheKey: "listApiKeys"
|
|
530
|
+
}),
|
|
531
|
+
useActiveOrganization: authClient.useActiveOrganization,
|
|
532
|
+
useListOrganizations: authClient.useListOrganizations,
|
|
533
|
+
useHasPermission: (params) => useAuthData({
|
|
534
|
+
queryFn: () => authClient.$fetch("/organization/has-permission", {
|
|
535
|
+
method: "POST",
|
|
536
|
+
body: params
|
|
537
|
+
}),
|
|
538
|
+
cacheKey: `hasPermission:${JSON.stringify(params)}`
|
|
539
|
+
}),
|
|
540
|
+
useInvitation: (params) => useAuthData({
|
|
541
|
+
queryFn: () => authClient.organization.getInvitation(params),
|
|
542
|
+
cacheKey: `invitation:${JSON.stringify(params)}`
|
|
543
|
+
}),
|
|
544
|
+
useListInvitations: (params) => useAuthData({
|
|
545
|
+
queryFn: () => {
|
|
546
|
+
var _a;
|
|
547
|
+
return authClient.$fetch(
|
|
548
|
+
`/organization/list-invitations?organizationId=${((_a = params == null ? void 0 : params.query) == null ? void 0 : _a.organizationId) || ""}`
|
|
549
|
+
);
|
|
550
|
+
},
|
|
551
|
+
cacheKey: `listInvitations:${JSON.stringify(params)}`
|
|
552
|
+
}),
|
|
553
|
+
useListUserInvitations: () => useAuthData({
|
|
554
|
+
queryFn: () => authClient.$fetch(
|
|
555
|
+
"/organization/list-user-invitations"
|
|
556
|
+
),
|
|
557
|
+
cacheKey: `listUserInvitations`
|
|
558
|
+
}),
|
|
559
|
+
useListMembers: (params) => useAuthData({
|
|
560
|
+
queryFn: () => {
|
|
561
|
+
var _a;
|
|
562
|
+
return authClient.$fetch(
|
|
563
|
+
`/organization/list-members?organizationId=${((_a = params == null ? void 0 : params.query) == null ? void 0 : _a.organizationId) || ""}`
|
|
564
|
+
);
|
|
565
|
+
},
|
|
566
|
+
cacheKey: `listMembers:${JSON.stringify(params)}`
|
|
567
|
+
})
|
|
568
|
+
};
|
|
569
|
+
}, [authClient]);
|
|
570
|
+
const viewPaths = useMemo2(() => {
|
|
571
|
+
return { ...authViewPaths, ...viewPathsProp };
|
|
572
|
+
}, [viewPathsProp]);
|
|
573
|
+
const localization = useMemo2(() => {
|
|
574
|
+
return { ...authLocalization, ...localizationProp };
|
|
575
|
+
}, [localizationProp]);
|
|
576
|
+
const hooks = useMemo2(() => {
|
|
577
|
+
return { ...defaultHooks, ...hooksProp };
|
|
578
|
+
}, [defaultHooks, hooksProp]);
|
|
579
|
+
const mutators = useMemo2(() => {
|
|
580
|
+
return { ...defaultMutators, ...mutatorsProp };
|
|
581
|
+
}, [defaultMutators, mutatorsProp]);
|
|
582
|
+
baseURL = baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL;
|
|
583
|
+
basePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
584
|
+
const { data: sessionData } = hooks.useSession();
|
|
585
|
+
return /* @__PURE__ */ jsxs2(
|
|
586
|
+
AuthUIContext.Provider,
|
|
587
|
+
{
|
|
588
|
+
value: {
|
|
589
|
+
authClient,
|
|
590
|
+
avatar,
|
|
591
|
+
basePath: basePath === "/" ? "" : basePath,
|
|
592
|
+
baseURL,
|
|
593
|
+
captcha,
|
|
594
|
+
redirectTo,
|
|
595
|
+
changeEmail,
|
|
596
|
+
credentials,
|
|
597
|
+
deleteUser,
|
|
598
|
+
freshAge,
|
|
599
|
+
genericOAuth,
|
|
600
|
+
hooks,
|
|
601
|
+
mutators,
|
|
602
|
+
localization,
|
|
603
|
+
nameRequired,
|
|
604
|
+
organization,
|
|
605
|
+
account,
|
|
606
|
+
signUp,
|
|
607
|
+
social,
|
|
608
|
+
toast: toast2,
|
|
609
|
+
navigate: navigate || defaultNavigate,
|
|
610
|
+
replace: replace || navigate || defaultReplace,
|
|
611
|
+
viewPaths,
|
|
612
|
+
Link,
|
|
613
|
+
...props
|
|
614
|
+
},
|
|
615
|
+
children: [
|
|
616
|
+
sessionData && organization && /* @__PURE__ */ jsx2(OrganizationRefetcher, {}),
|
|
617
|
+
(captcha == null ? void 0 : captcha.provider) === "google-recaptcha-v3" ? /* @__PURE__ */ jsx2(RecaptchaV3, { children }) : children
|
|
618
|
+
]
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
// src/hooks/use-auth-data.ts
|
|
624
|
+
function useAuthData({
|
|
625
|
+
queryFn,
|
|
626
|
+
cacheKey,
|
|
627
|
+
staleTime = 1e4
|
|
628
|
+
// Default 10 seconds
|
|
629
|
+
}) {
|
|
630
|
+
var _a;
|
|
631
|
+
const {
|
|
632
|
+
hooks: { useSession },
|
|
633
|
+
toast: toast2,
|
|
634
|
+
localization
|
|
635
|
+
} = useContext4(AuthUIContext);
|
|
636
|
+
const { data: sessionData, isPending: sessionPending } = useSession();
|
|
637
|
+
const queryFnRef = useRef(queryFn);
|
|
638
|
+
queryFnRef.current = queryFn;
|
|
639
|
+
const stableCacheKey = cacheKey || queryFn.toString();
|
|
640
|
+
const cacheEntry = useSyncExternalStore2(
|
|
641
|
+
useCallback(
|
|
642
|
+
(callback) => authDataCache.subscribe(stableCacheKey, callback),
|
|
643
|
+
[stableCacheKey]
|
|
644
|
+
),
|
|
645
|
+
useCallback(
|
|
646
|
+
() => authDataCache.get(stableCacheKey),
|
|
647
|
+
[stableCacheKey]
|
|
648
|
+
),
|
|
649
|
+
useCallback(
|
|
650
|
+
() => authDataCache.get(stableCacheKey),
|
|
651
|
+
[stableCacheKey]
|
|
652
|
+
)
|
|
653
|
+
);
|
|
654
|
+
const initialized = useRef(false);
|
|
655
|
+
const previousUserId = useRef(void 0);
|
|
656
|
+
const [error, setError] = useState3(null);
|
|
657
|
+
const refetch = useCallback(async () => {
|
|
658
|
+
const existingRequest = authDataCache.getInFlightRequest(stableCacheKey);
|
|
659
|
+
if (existingRequest) {
|
|
660
|
+
try {
|
|
661
|
+
const result = await existingRequest;
|
|
662
|
+
if (result.error) {
|
|
663
|
+
setError(result.error);
|
|
664
|
+
} else {
|
|
665
|
+
setError(null);
|
|
666
|
+
}
|
|
667
|
+
} catch (err) {
|
|
668
|
+
setError(err);
|
|
669
|
+
}
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if ((cacheEntry == null ? void 0 : cacheEntry.data) !== void 0) {
|
|
673
|
+
authDataCache.setRefetching(stableCacheKey, true);
|
|
674
|
+
}
|
|
675
|
+
const fetchPromise = queryFnRef.current();
|
|
676
|
+
authDataCache.setInFlightRequest(stableCacheKey, fetchPromise);
|
|
677
|
+
try {
|
|
678
|
+
const { data, error: error2 } = await fetchPromise;
|
|
679
|
+
if (error2) {
|
|
680
|
+
setError(error2);
|
|
681
|
+
toast2({
|
|
682
|
+
variant: "error",
|
|
683
|
+
message: getLocalizedError({ error: error2, localization })
|
|
684
|
+
});
|
|
685
|
+
} else {
|
|
686
|
+
setError(null);
|
|
687
|
+
}
|
|
688
|
+
authDataCache.set(stableCacheKey, data);
|
|
689
|
+
} catch (err) {
|
|
690
|
+
const error2 = err;
|
|
691
|
+
setError(error2);
|
|
692
|
+
toast2({
|
|
693
|
+
variant: "error",
|
|
694
|
+
message: getLocalizedError({ error: error2, localization })
|
|
695
|
+
});
|
|
696
|
+
} finally {
|
|
697
|
+
authDataCache.setRefetching(stableCacheKey, false);
|
|
698
|
+
authDataCache.removeInFlightRequest(stableCacheKey);
|
|
699
|
+
}
|
|
700
|
+
}, [stableCacheKey, toast2, localization, cacheEntry]);
|
|
701
|
+
useEffect5(() => {
|
|
702
|
+
var _a2;
|
|
703
|
+
const currentUserId = (_a2 = sessionData == null ? void 0 : sessionData.user) == null ? void 0 : _a2.id;
|
|
704
|
+
if (!sessionData) {
|
|
705
|
+
authDataCache.setRefetching(stableCacheKey, false);
|
|
706
|
+
authDataCache.clear(stableCacheKey);
|
|
707
|
+
initialized.current = false;
|
|
708
|
+
previousUserId.current = void 0;
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const userIdChanged = previousUserId.current !== void 0 && previousUserId.current !== currentUserId;
|
|
712
|
+
if (userIdChanged) {
|
|
713
|
+
authDataCache.clear(stableCacheKey);
|
|
714
|
+
}
|
|
715
|
+
const hasCachedData = (cacheEntry == null ? void 0 : cacheEntry.data) !== void 0;
|
|
716
|
+
const isStale = !cacheEntry || Date.now() - cacheEntry.timestamp > staleTime;
|
|
717
|
+
if (!initialized.current || !hasCachedData || userIdChanged || hasCachedData && isStale) {
|
|
718
|
+
if (!hasCachedData || isStale) {
|
|
719
|
+
initialized.current = true;
|
|
720
|
+
refetch();
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
previousUserId.current = currentUserId;
|
|
724
|
+
}, [
|
|
725
|
+
sessionData,
|
|
726
|
+
(_a = sessionData == null ? void 0 : sessionData.user) == null ? void 0 : _a.id,
|
|
727
|
+
stableCacheKey,
|
|
728
|
+
refetch,
|
|
729
|
+
cacheEntry,
|
|
730
|
+
staleTime
|
|
731
|
+
]);
|
|
732
|
+
const isPending = sessionPending || (cacheEntry == null ? void 0 : cacheEntry.data) === void 0 && !error;
|
|
733
|
+
return {
|
|
734
|
+
data: (cacheEntry == null ? void 0 : cacheEntry.data) ?? null,
|
|
735
|
+
isPending,
|
|
736
|
+
isRefetching: (cacheEntry == null ? void 0 : cacheEntry.isRefetching) ?? false,
|
|
737
|
+
error,
|
|
738
|
+
refetch
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
export {
|
|
743
|
+
useIsHydrated,
|
|
744
|
+
useLang,
|
|
745
|
+
useTheme,
|
|
746
|
+
useAuthData,
|
|
747
|
+
useCurrentOrganization,
|
|
748
|
+
AuthUIContext,
|
|
749
|
+
AuthUIProvider
|
|
750
|
+
};
|