@thetechfossil/auth2 1.2.15 → 1.2.17
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/README.md +0 -0
- package/dist/index.components.d.mts +8 -0
- package/dist/index.components.d.ts +8 -0
- package/dist/index.components.js +253 -142
- package/dist/index.components.js.map +1 -1
- package/dist/index.components.mjs +139 -28
- package/dist/index.components.mjs.map +1 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +296 -179
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -32
- package/dist/index.mjs.map +1 -1
- package/dist/index.next.d.mts +8 -0
- package/dist/index.next.d.ts +8 -0
- package/dist/index.next.js +315 -198
- package/dist/index.next.js.map +1 -1
- package/dist/index.next.mjs +149 -32
- package/dist/index.next.mjs.map +1 -1
- package/dist/index.next.server.d.mts +15 -3
- package/dist/index.next.server.d.ts +15 -3
- package/dist/index.next.server.js +21 -5
- package/dist/index.next.server.js.map +1 -1
- package/dist/index.next.server.mjs +18 -2
- package/dist/index.next.server.mjs.map +1 -1
- package/dist/index.node.js +5 -0
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +5 -0
- package/dist/index.node.mjs.map +1 -1
- package/next/index.js +0 -0
- package/next/index.mjs +0 -0
- package/next/package.json +0 -0
- package/next/server/package.json +0 -0
- package/next/server.js +0 -0
- package/next/server.mjs +0 -0
- package/package.json +102 -101
package/dist/index.components.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var axios = require('axios');
|
|
6
6
|
var upfiles = require('@thetechfossil/upfiles');
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
8
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
12
12
|
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
13
13
|
|
|
14
14
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -69,6 +69,11 @@ var HttpClient = class {
|
|
|
69
69
|
return Promise.reject(refreshError);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
if (error.response && error.response.data && error.response.data.message) {
|
|
73
|
+
const customError = new Error(error.response.data.message);
|
|
74
|
+
customError.response = error.response;
|
|
75
|
+
return Promise.reject(customError);
|
|
76
|
+
}
|
|
72
77
|
return Promise.reject(error);
|
|
73
78
|
}
|
|
74
79
|
);
|
|
@@ -508,11 +513,11 @@ var AuthService = class {
|
|
|
508
513
|
|
|
509
514
|
// src/react/use-auth.ts
|
|
510
515
|
var useAuth = (config) => {
|
|
511
|
-
const [authService] =
|
|
512
|
-
const [user, setUser] =
|
|
513
|
-
const [isAuthenticated, setIsAuthenticated] =
|
|
514
|
-
const [loading, setLoading] =
|
|
515
|
-
const checkAuthStatus =
|
|
516
|
+
const [authService] = React.useState(() => new AuthService(config));
|
|
517
|
+
const [user, setUser] = React.useState(null);
|
|
518
|
+
const [isAuthenticated, setIsAuthenticated] = React.useState(false);
|
|
519
|
+
const [loading, setLoading] = React.useState(true);
|
|
520
|
+
const checkAuthStatus = React.useCallback(() => {
|
|
516
521
|
const authenticated = authService.isAuthenticated();
|
|
517
522
|
setIsAuthenticated(authenticated);
|
|
518
523
|
if (authenticated) {
|
|
@@ -523,10 +528,10 @@ var useAuth = (config) => {
|
|
|
523
528
|
}
|
|
524
529
|
setLoading(false);
|
|
525
530
|
}, [authService]);
|
|
526
|
-
|
|
531
|
+
React.useEffect(() => {
|
|
527
532
|
checkAuthStatus();
|
|
528
533
|
}, [checkAuthStatus]);
|
|
529
|
-
const register =
|
|
534
|
+
const register = React.useCallback(async (data) => {
|
|
530
535
|
setLoading(true);
|
|
531
536
|
try {
|
|
532
537
|
const response = await authService.register(data);
|
|
@@ -535,7 +540,7 @@ var useAuth = (config) => {
|
|
|
535
540
|
setLoading(false);
|
|
536
541
|
}
|
|
537
542
|
}, [authService]);
|
|
538
|
-
const login =
|
|
543
|
+
const login = React.useCallback(async (data) => {
|
|
539
544
|
setLoading(true);
|
|
540
545
|
try {
|
|
541
546
|
const response = await authService.login(data);
|
|
@@ -548,7 +553,7 @@ var useAuth = (config) => {
|
|
|
548
553
|
setLoading(false);
|
|
549
554
|
}
|
|
550
555
|
}, [authService]);
|
|
551
|
-
const verify =
|
|
556
|
+
const verify = React.useCallback(async (data) => {
|
|
552
557
|
setLoading(true);
|
|
553
558
|
try {
|
|
554
559
|
const response = await authService.verify(data);
|
|
@@ -561,7 +566,7 @@ var useAuth = (config) => {
|
|
|
561
566
|
setLoading(false);
|
|
562
567
|
}
|
|
563
568
|
}, [authService]);
|
|
564
|
-
const verifyEmailToken =
|
|
569
|
+
const verifyEmailToken = React.useCallback(async (token) => {
|
|
565
570
|
setLoading(true);
|
|
566
571
|
try {
|
|
567
572
|
const response = await authService.verifyEmailToken(token);
|
|
@@ -574,7 +579,7 @@ var useAuth = (config) => {
|
|
|
574
579
|
setLoading(false);
|
|
575
580
|
}
|
|
576
581
|
}, [authService]);
|
|
577
|
-
const logout =
|
|
582
|
+
const logout = React.useCallback(async () => {
|
|
578
583
|
setLoading(true);
|
|
579
584
|
try {
|
|
580
585
|
await authService.logout();
|
|
@@ -584,7 +589,7 @@ var useAuth = (config) => {
|
|
|
584
589
|
setLoading(false);
|
|
585
590
|
}
|
|
586
591
|
}, [authService]);
|
|
587
|
-
const updateProfile =
|
|
592
|
+
const updateProfile = React.useCallback(async (data) => {
|
|
588
593
|
setLoading(true);
|
|
589
594
|
try {
|
|
590
595
|
const response = await authService.updateProfile(data);
|
|
@@ -596,7 +601,7 @@ var useAuth = (config) => {
|
|
|
596
601
|
setLoading(false);
|
|
597
602
|
}
|
|
598
603
|
}, [authService]);
|
|
599
|
-
const getProfile =
|
|
604
|
+
const getProfile = React.useCallback(async () => {
|
|
600
605
|
setLoading(true);
|
|
601
606
|
try {
|
|
602
607
|
const userData = await authService.getProfile();
|
|
@@ -606,7 +611,7 @@ var useAuth = (config) => {
|
|
|
606
611
|
setLoading(false);
|
|
607
612
|
}
|
|
608
613
|
}, [authService]);
|
|
609
|
-
const getAllUsers =
|
|
614
|
+
const getAllUsers = React.useCallback(async () => {
|
|
610
615
|
setLoading(true);
|
|
611
616
|
try {
|
|
612
617
|
return await authService.getAllUsers();
|
|
@@ -614,7 +619,7 @@ var useAuth = (config) => {
|
|
|
614
619
|
setLoading(false);
|
|
615
620
|
}
|
|
616
621
|
}, [authService]);
|
|
617
|
-
const getUserById =
|
|
622
|
+
const getUserById = React.useCallback(async (id) => {
|
|
618
623
|
setLoading(true);
|
|
619
624
|
try {
|
|
620
625
|
return await authService.getUserById(id);
|
|
@@ -622,7 +627,7 @@ var useAuth = (config) => {
|
|
|
622
627
|
setLoading(false);
|
|
623
628
|
}
|
|
624
629
|
}, [authService]);
|
|
625
|
-
const uploadAndUpdateAvatar =
|
|
630
|
+
const uploadAndUpdateAvatar = React.useCallback(async (file) => {
|
|
626
631
|
setLoading(true);
|
|
627
632
|
try {
|
|
628
633
|
const response = await authService.uploadAndUpdateAvatar(file);
|
|
@@ -650,9 +655,9 @@ var useAuth = (config) => {
|
|
|
650
655
|
uploadAndUpdateAvatar
|
|
651
656
|
};
|
|
652
657
|
};
|
|
653
|
-
var ThemeContext =
|
|
658
|
+
var ThemeContext = React__default.default.createContext({ theme: "light", mounted: false });
|
|
654
659
|
function useAuthTheme() {
|
|
655
|
-
return
|
|
660
|
+
return React.useContext(ThemeContext);
|
|
656
661
|
}
|
|
657
662
|
|
|
658
663
|
// src/react/hooks/useThemeColors.ts
|
|
@@ -704,7 +709,7 @@ try {
|
|
|
704
709
|
} catch (error) {
|
|
705
710
|
console.warn("react-phone-number-input not available, using fallback");
|
|
706
711
|
}
|
|
707
|
-
var CustomPhoneInput =
|
|
712
|
+
var CustomPhoneInput = React__default.default.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
708
713
|
"input",
|
|
709
714
|
{
|
|
710
715
|
...props,
|
|
@@ -723,8 +728,8 @@ var PhoneInput = ({
|
|
|
723
728
|
style = {}
|
|
724
729
|
}) => {
|
|
725
730
|
const colors = useThemeColors();
|
|
726
|
-
const [defaultCountry, setDefaultCountry] =
|
|
727
|
-
const styleContent =
|
|
731
|
+
const [defaultCountry, setDefaultCountry] = React.useState("US");
|
|
732
|
+
const styleContent = React.useMemo(() => `
|
|
728
733
|
.PhoneInput {
|
|
729
734
|
display: flex;
|
|
730
735
|
align-items: center;
|
|
@@ -836,7 +841,7 @@ var PhoneInput = ({
|
|
|
836
841
|
opacity: 0.6;
|
|
837
842
|
}
|
|
838
843
|
`, [colors]);
|
|
839
|
-
|
|
844
|
+
React.useEffect(() => {
|
|
840
845
|
const detectCountry = async () => {
|
|
841
846
|
try {
|
|
842
847
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
@@ -893,7 +898,7 @@ var PhoneInput = ({
|
|
|
893
898
|
};
|
|
894
899
|
detectCountry();
|
|
895
900
|
}, []);
|
|
896
|
-
const handleChange =
|
|
901
|
+
const handleChange = React.useMemo(() => (val) => {
|
|
897
902
|
onChange(val || "");
|
|
898
903
|
}, [onChange]);
|
|
899
904
|
if (!PhoneInputWithCountry) {
|
|
@@ -957,15 +962,15 @@ var LoginForm = ({
|
|
|
957
962
|
showOAuthButtons = true
|
|
958
963
|
}) => {
|
|
959
964
|
const colors = useThemeColors();
|
|
960
|
-
const [email, setEmail] =
|
|
961
|
-
const [phoneNumber, setPhoneNumber] =
|
|
962
|
-
const [usePhone, setUsePhone] =
|
|
963
|
-
const [password, setPassword] =
|
|
964
|
-
const [usePassword, setUsePassword] =
|
|
965
|
-
const [showPassword, setShowPassword] =
|
|
966
|
-
const [isLoading, setIsLoading] =
|
|
967
|
-
const [error, setError] =
|
|
968
|
-
const [rememberMe, setRememberMe] =
|
|
965
|
+
const [email, setEmail] = React.useState("");
|
|
966
|
+
const [phoneNumber, setPhoneNumber] = React.useState("");
|
|
967
|
+
const [usePhone, setUsePhone] = React.useState(false);
|
|
968
|
+
const [password, setPassword] = React.useState("");
|
|
969
|
+
const [usePassword, setUsePassword] = React.useState(false);
|
|
970
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
971
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
972
|
+
const [error, setError] = React.useState(null);
|
|
973
|
+
const [rememberMe, setRememberMe] = React.useState(false);
|
|
969
974
|
const { login } = useAuth({
|
|
970
975
|
baseUrl: config?.baseUrl || "http://localhost:7000"
|
|
971
976
|
});
|
|
@@ -1419,15 +1424,15 @@ var RegisterForm = ({
|
|
|
1419
1424
|
invitationToken
|
|
1420
1425
|
}) => {
|
|
1421
1426
|
const colors = useThemeColors();
|
|
1422
|
-
const [name, setName] =
|
|
1423
|
-
const [email, setEmail] =
|
|
1424
|
-
const [phoneNumber, setPhoneNumber] =
|
|
1425
|
-
const [password, setPassword] =
|
|
1426
|
-
const [confirmPassword, setConfirmPassword] =
|
|
1427
|
-
const [isLoading, setIsLoading] =
|
|
1428
|
-
const [error, setError] =
|
|
1429
|
-
const [showPassword, setShowPassword] =
|
|
1430
|
-
const [showConfirmPassword, setShowConfirmPassword] =
|
|
1427
|
+
const [name, setName] = React.useState("");
|
|
1428
|
+
const [email, setEmail] = React.useState("");
|
|
1429
|
+
const [phoneNumber, setPhoneNumber] = React.useState("");
|
|
1430
|
+
const [password, setPassword] = React.useState("");
|
|
1431
|
+
const [confirmPassword, setConfirmPassword] = React.useState("");
|
|
1432
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
1433
|
+
const [error, setError] = React.useState(null);
|
|
1434
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
1435
|
+
const [showConfirmPassword, setShowConfirmPassword] = React.useState(false);
|
|
1431
1436
|
const getPasswordStrength = (pwd) => {
|
|
1432
1437
|
if (!pwd) return { strength: "weak", score: 0, label: "" };
|
|
1433
1438
|
let score = 0;
|
|
@@ -1883,11 +1888,11 @@ var OtpForm = ({
|
|
|
1883
1888
|
baseUrl
|
|
1884
1889
|
}) => {
|
|
1885
1890
|
const colors = useThemeColors();
|
|
1886
|
-
const [otp, setOtp] =
|
|
1887
|
-
const [isLoading, setIsLoading] =
|
|
1888
|
-
const [error, setError] =
|
|
1889
|
-
const [resendCooldown, setResendCooldown] =
|
|
1890
|
-
const [resendLoading, setResendLoading] =
|
|
1891
|
+
const [otp, setOtp] = React.useState("");
|
|
1892
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
1893
|
+
const [error, setError] = React.useState(null);
|
|
1894
|
+
const [resendCooldown, setResendCooldown] = React.useState(0);
|
|
1895
|
+
const [resendLoading, setResendLoading] = React.useState(false);
|
|
1891
1896
|
const { verify, login } = useAuth({
|
|
1892
1897
|
baseUrl: baseUrl || process.env.NEXT_PUBLIC_AUTH_API_URL || "http://localhost:7000"
|
|
1893
1898
|
});
|
|
@@ -2098,9 +2103,9 @@ var AuthFlow = ({
|
|
|
2098
2103
|
initialStep = "login",
|
|
2099
2104
|
showTitle = true
|
|
2100
2105
|
}) => {
|
|
2101
|
-
const [step, setStep] =
|
|
2102
|
-
const [email, setEmail] =
|
|
2103
|
-
const [message, setMessage] =
|
|
2106
|
+
const [step, setStep] = React.useState(initialStep);
|
|
2107
|
+
const [email, setEmail] = React.useState("");
|
|
2108
|
+
const [message, setMessage] = React.useState(null);
|
|
2104
2109
|
const handleLoginSuccess = (email2, needsOtpVerification) => {
|
|
2105
2110
|
setEmail(email2);
|
|
2106
2111
|
if (needsOtpVerification) {
|
|
@@ -2235,13 +2240,13 @@ var EmailVerificationPage = ({
|
|
|
2235
2240
|
onVerificationError,
|
|
2236
2241
|
baseUrl
|
|
2237
2242
|
}) => {
|
|
2238
|
-
const [isLoading, setIsLoading] =
|
|
2239
|
-
const [message, setMessage] =
|
|
2240
|
-
const [isSuccess, setIsSuccess] =
|
|
2243
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
2244
|
+
const [message, setMessage] = React.useState("");
|
|
2245
|
+
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
2241
2246
|
const { verifyEmailToken } = useAuth({
|
|
2242
2247
|
baseUrl: baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
|
|
2243
2248
|
});
|
|
2244
|
-
|
|
2249
|
+
React.useEffect(() => {
|
|
2245
2250
|
const verifyEmail = async () => {
|
|
2246
2251
|
if (!token) {
|
|
2247
2252
|
setIsLoading(false);
|
|
@@ -2346,15 +2351,15 @@ var EmailVerificationPage = ({
|
|
|
2346
2351
|
] })
|
|
2347
2352
|
] }) });
|
|
2348
2353
|
};
|
|
2349
|
-
var AuthContext =
|
|
2354
|
+
var AuthContext = React.createContext(void 0);
|
|
2350
2355
|
var useAuth2 = () => {
|
|
2351
|
-
const context =
|
|
2356
|
+
const context = React.useContext(AuthContext);
|
|
2352
2357
|
if (context === void 0) {
|
|
2353
2358
|
throw new Error("useAuth must be used within an AuthProvider");
|
|
2354
2359
|
}
|
|
2355
2360
|
return context;
|
|
2356
2361
|
};
|
|
2357
|
-
var ThemeWrapper =
|
|
2362
|
+
var ThemeWrapper = React.forwardRef(
|
|
2358
2363
|
({ children, className = "", style }, ref) => {
|
|
2359
2364
|
const { theme, mounted } = useAuthTheme();
|
|
2360
2365
|
if (!mounted) {
|
|
@@ -2367,18 +2372,18 @@ ThemeWrapper.displayName = "ThemeWrapper";
|
|
|
2367
2372
|
var SignIn = ({ redirectUrl, appearance }) => {
|
|
2368
2373
|
const { signIn, isSignedIn, loading: authLoading } = useAuth2();
|
|
2369
2374
|
const colors = useThemeColors();
|
|
2370
|
-
const [email, setEmail] =
|
|
2371
|
-
const [phoneNumber, setPhoneNumber] =
|
|
2372
|
-
const [password, setPassword] =
|
|
2373
|
-
const [otp, setOtp] =
|
|
2374
|
-
const [usePassword, setUsePassword] =
|
|
2375
|
-
const [usePhone, setUsePhone] =
|
|
2376
|
-
const [showPassword, setShowPassword] =
|
|
2377
|
-
const [isLoading, setIsLoading] =
|
|
2378
|
-
const [error, setError] =
|
|
2379
|
-
const [needsOtp, setNeedsOtp] =
|
|
2380
|
-
const [success, setSuccess] =
|
|
2381
|
-
|
|
2375
|
+
const [email, setEmail] = React.useState("");
|
|
2376
|
+
const [phoneNumber, setPhoneNumber] = React.useState("");
|
|
2377
|
+
const [password, setPassword] = React.useState("");
|
|
2378
|
+
const [otp, setOtp] = React.useState("");
|
|
2379
|
+
const [usePassword, setUsePassword] = React.useState(false);
|
|
2380
|
+
const [usePhone, setUsePhone] = React.useState(false);
|
|
2381
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
2382
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
2383
|
+
const [error, setError] = React.useState(null);
|
|
2384
|
+
const [needsOtp, setNeedsOtp] = React.useState(false);
|
|
2385
|
+
const [success, setSuccess] = React.useState(null);
|
|
2386
|
+
React.useEffect(() => {
|
|
2382
2387
|
if (isSignedIn && redirectUrl) {
|
|
2383
2388
|
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
2384
2389
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -2769,16 +2774,16 @@ var SignIn = ({ redirectUrl, appearance }) => {
|
|
|
2769
2774
|
var SignUp = ({ redirectUrl, appearance }) => {
|
|
2770
2775
|
const { signUp, isSignedIn } = useAuth2();
|
|
2771
2776
|
const colors = useThemeColors();
|
|
2772
|
-
const [name, setName] =
|
|
2773
|
-
const [email, setEmail] =
|
|
2774
|
-
const [phoneNumber, setPhoneNumber] =
|
|
2775
|
-
const [password, setPassword] =
|
|
2776
|
-
const [confirmPassword, setConfirmPassword] =
|
|
2777
|
-
const [showPassword, setShowPassword] =
|
|
2778
|
-
const [isLoading, setIsLoading] =
|
|
2779
|
-
const [error, setError] =
|
|
2780
|
-
const [success, setSuccess] =
|
|
2781
|
-
|
|
2777
|
+
const [name, setName] = React.useState("");
|
|
2778
|
+
const [email, setEmail] = React.useState("");
|
|
2779
|
+
const [phoneNumber, setPhoneNumber] = React.useState("");
|
|
2780
|
+
const [password, setPassword] = React.useState("");
|
|
2781
|
+
const [confirmPassword, setConfirmPassword] = React.useState("");
|
|
2782
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
2783
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
2784
|
+
const [error, setError] = React.useState(null);
|
|
2785
|
+
const [success, setSuccess] = React.useState(null);
|
|
2786
|
+
React.useEffect(() => {
|
|
2782
2787
|
if (isSignedIn && redirectUrl) {
|
|
2783
2788
|
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_AFTER_REGISTER || "/dashboard";
|
|
2784
2789
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -3132,7 +3137,7 @@ var SignUp = ({ redirectUrl, appearance }) => {
|
|
|
3132
3137
|
};
|
|
3133
3138
|
var SignOut = ({ redirectUrl }) => {
|
|
3134
3139
|
const { signOut } = useAuth2();
|
|
3135
|
-
|
|
3140
|
+
React.useEffect(() => {
|
|
3136
3141
|
const performSignOut = async () => {
|
|
3137
3142
|
await signOut();
|
|
3138
3143
|
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
|
|
@@ -3146,9 +3151,9 @@ var SignOut = ({ redirectUrl }) => {
|
|
|
3146
3151
|
var UserButton = ({ showName = false, appearance }) => {
|
|
3147
3152
|
const { user, signOut } = useAuth2();
|
|
3148
3153
|
const colors = useThemeColors();
|
|
3149
|
-
const [isOpen, setIsOpen] =
|
|
3150
|
-
const dropdownRef =
|
|
3151
|
-
|
|
3154
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
3155
|
+
const dropdownRef = React.useRef(null);
|
|
3156
|
+
React.useEffect(() => {
|
|
3152
3157
|
const handleClickOutside = (event) => {
|
|
3153
3158
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
3154
3159
|
setIsOpen(false);
|
|
@@ -3191,7 +3196,19 @@ var UserButton = ({ showName = false, appearance }) => {
|
|
|
3191
3196
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
3192
3197
|
},
|
|
3193
3198
|
children: [
|
|
3194
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3199
|
+
user.avatar ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3200
|
+
"img",
|
|
3201
|
+
{
|
|
3202
|
+
src: user.avatar,
|
|
3203
|
+
alt: user.name,
|
|
3204
|
+
style: {
|
|
3205
|
+
width: "36px",
|
|
3206
|
+
height: "36px",
|
|
3207
|
+
borderRadius: "50%",
|
|
3208
|
+
objectFit: "cover"
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3195
3212
|
width: "36px",
|
|
3196
3213
|
height: "36px",
|
|
3197
3214
|
borderRadius: "50%",
|
|
@@ -3228,7 +3245,19 @@ var UserButton = ({ showName = false, appearance }) => {
|
|
|
3228
3245
|
alignItems: "center",
|
|
3229
3246
|
gap: "12px"
|
|
3230
3247
|
}, children: [
|
|
3231
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3248
|
+
user.avatar ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3249
|
+
"img",
|
|
3250
|
+
{
|
|
3251
|
+
src: user.avatar,
|
|
3252
|
+
alt: user.name,
|
|
3253
|
+
style: {
|
|
3254
|
+
width: "48px",
|
|
3255
|
+
height: "48px",
|
|
3256
|
+
borderRadius: "50%",
|
|
3257
|
+
objectFit: "cover"
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3232
3261
|
width: "48px",
|
|
3233
3262
|
height: "48px",
|
|
3234
3263
|
borderRadius: "50%",
|
|
@@ -3293,7 +3322,7 @@ var ProtectedRoute = ({
|
|
|
3293
3322
|
redirectTo
|
|
3294
3323
|
}) => {
|
|
3295
3324
|
const { isSignedIn, isLoaded } = useAuth2();
|
|
3296
|
-
|
|
3325
|
+
React.useEffect(() => {
|
|
3297
3326
|
if (isLoaded && !isSignedIn) {
|
|
3298
3327
|
const loginPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
3299
3328
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -3318,7 +3347,7 @@ var PublicRoute = ({
|
|
|
3318
3347
|
redirectTo
|
|
3319
3348
|
}) => {
|
|
3320
3349
|
const { isSignedIn, isLoaded } = useAuth2();
|
|
3321
|
-
|
|
3350
|
+
React.useEffect(() => {
|
|
3322
3351
|
if (isLoaded && isSignedIn) {
|
|
3323
3352
|
const dashboardPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
3324
3353
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -3340,9 +3369,9 @@ var PublicRoute = ({
|
|
|
3340
3369
|
};
|
|
3341
3370
|
var VerifyEmail = ({ token, onSuccess, onError }) => {
|
|
3342
3371
|
const { verifyEmailToken } = useAuth2();
|
|
3343
|
-
const [status, setStatus] =
|
|
3344
|
-
const [message, setMessage] =
|
|
3345
|
-
|
|
3372
|
+
const [status, setStatus] = React.useState("loading");
|
|
3373
|
+
const [message, setMessage] = React.useState("");
|
|
3374
|
+
React.useEffect(() => {
|
|
3346
3375
|
const verify = async () => {
|
|
3347
3376
|
const verifyToken = token || (typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("token") : null);
|
|
3348
3377
|
if (!verifyToken) {
|
|
@@ -3476,10 +3505,10 @@ var VerifyEmail = ({ token, onSuccess, onError }) => {
|
|
|
3476
3505
|
};
|
|
3477
3506
|
var ForgotPassword = ({ appearance }) => {
|
|
3478
3507
|
const { forgotPassword } = useAuth2();
|
|
3479
|
-
const [email, setEmail] =
|
|
3480
|
-
const [isLoading, setIsLoading] =
|
|
3481
|
-
const [error, setError] =
|
|
3482
|
-
const [success, setSuccess] =
|
|
3508
|
+
const [email, setEmail] = React.useState("");
|
|
3509
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
3510
|
+
const [error, setError] = React.useState(null);
|
|
3511
|
+
const [success, setSuccess] = React.useState(null);
|
|
3483
3512
|
const handleSubmit = async (e) => {
|
|
3484
3513
|
e.preventDefault();
|
|
3485
3514
|
setIsLoading(true);
|
|
@@ -3618,14 +3647,14 @@ var ForgotPassword = ({ appearance }) => {
|
|
|
3618
3647
|
};
|
|
3619
3648
|
var ResetPassword = ({ token, appearance }) => {
|
|
3620
3649
|
const { resetPassword } = useAuth2();
|
|
3621
|
-
const [resetToken, setResetToken] =
|
|
3622
|
-
const [password, setPassword] =
|
|
3623
|
-
const [confirmPassword, setConfirmPassword] =
|
|
3624
|
-
const [showPassword, setShowPassword] =
|
|
3625
|
-
const [isLoading, setIsLoading] =
|
|
3626
|
-
const [error, setError] =
|
|
3627
|
-
const [success, setSuccess] =
|
|
3628
|
-
|
|
3650
|
+
const [resetToken, setResetToken] = React.useState(token || "");
|
|
3651
|
+
const [password, setPassword] = React.useState("");
|
|
3652
|
+
const [confirmPassword, setConfirmPassword] = React.useState("");
|
|
3653
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
3654
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
3655
|
+
const [error, setError] = React.useState(null);
|
|
3656
|
+
const [success, setSuccess] = React.useState(false);
|
|
3657
|
+
React.useEffect(() => {
|
|
3629
3658
|
if (!resetToken && typeof window !== "undefined") {
|
|
3630
3659
|
const urlToken = new URLSearchParams(window.location.search).get("token");
|
|
3631
3660
|
if (urlToken) {
|
|
@@ -3872,13 +3901,13 @@ var ResetPassword = ({ token, appearance }) => {
|
|
|
3872
3901
|
};
|
|
3873
3902
|
var ChangePassword = ({ onSuccess, appearance }) => {
|
|
3874
3903
|
const { changePassword } = useAuth2();
|
|
3875
|
-
const [oldPassword, setOldPassword] =
|
|
3876
|
-
const [newPassword, setNewPassword] =
|
|
3877
|
-
const [confirmPassword, setConfirmPassword] =
|
|
3878
|
-
const [showPasswords, setShowPasswords] =
|
|
3879
|
-
const [isLoading, setIsLoading] =
|
|
3880
|
-
const [error, setError] =
|
|
3881
|
-
const [success, setSuccess] =
|
|
3904
|
+
const [oldPassword, setOldPassword] = React.useState("");
|
|
3905
|
+
const [newPassword, setNewPassword] = React.useState("");
|
|
3906
|
+
const [confirmPassword, setConfirmPassword] = React.useState("");
|
|
3907
|
+
const [showPasswords, setShowPasswords] = React.useState(false);
|
|
3908
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
3909
|
+
const [error, setError] = React.useState(null);
|
|
3910
|
+
const [success, setSuccess] = React.useState(false);
|
|
3882
3911
|
const getPasswordStrength = (pwd) => {
|
|
3883
3912
|
if (!pwd) return { strength: "weak", color: "#ddd" };
|
|
3884
3913
|
let score = 0;
|
|
@@ -4108,6 +4137,68 @@ var ChangePassword = ({ onSuccess, appearance }) => {
|
|
|
4108
4137
|
)
|
|
4109
4138
|
] }) });
|
|
4110
4139
|
};
|
|
4140
|
+
|
|
4141
|
+
// src/react/components/utils/injectModalStyles.ts
|
|
4142
|
+
var injectModalStyles = () => {
|
|
4143
|
+
if (document.getElementById("ttf-auth-modal-styles")) {
|
|
4144
|
+
return;
|
|
4145
|
+
}
|
|
4146
|
+
const styleElement = document.createElement("style");
|
|
4147
|
+
styleElement.id = "ttf-auth-modal-styles";
|
|
4148
|
+
styleElement.textContent = `
|
|
4149
|
+
/* ImageManager Modal Styles - Critical for proper modal display */
|
|
4150
|
+
/* Radix UI Dialog styles - Force visibility */
|
|
4151
|
+
[data-radix-portal] {
|
|
4152
|
+
z-index: 99999 !important;
|
|
4153
|
+
position: fixed !important;
|
|
4154
|
+
inset: 0 !important;
|
|
4155
|
+
pointer-events: none !important;
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
[data-radix-portal] > * {
|
|
4159
|
+
pointer-events: auto !important;
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
/* Dialog Overlay */
|
|
4163
|
+
[data-state="open"][data-radix-dialog-overlay],
|
|
4164
|
+
[role="dialog"] + [data-radix-dialog-overlay] {
|
|
4165
|
+
position: fixed !important;
|
|
4166
|
+
inset: 0 !important;
|
|
4167
|
+
z-index: 99998 !important;
|
|
4168
|
+
background-color: rgba(0, 0, 0, 0.6) !important;
|
|
4169
|
+
pointer-events: auto !important;
|
|
4170
|
+
}
|
|
4171
|
+
|
|
4172
|
+
/* Dialog Content - Center the modal properly */
|
|
4173
|
+
[data-state="open"][data-radix-dialog-content],
|
|
4174
|
+
[role="dialog"][data-radix-dialog-content] {
|
|
4175
|
+
position: fixed !important;
|
|
4176
|
+
left: 50% !important;
|
|
4177
|
+
top: 50% !important;
|
|
4178
|
+
transform: translate(-50%, -50%) !important;
|
|
4179
|
+
z-index: 99999 !important;
|
|
4180
|
+
background: white !important;
|
|
4181
|
+
border-radius: 16px !important;
|
|
4182
|
+
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
|
|
4183
|
+
pointer-events: auto !important;
|
|
4184
|
+
width: 95vw !important;
|
|
4185
|
+
max-width: 1280px !important;
|
|
4186
|
+
height: 90vh !important;
|
|
4187
|
+
max-height: 90vh !important;
|
|
4188
|
+
min-width: 800px !important;
|
|
4189
|
+
min-height: 600px !important;
|
|
4190
|
+
overflow: hidden !important;
|
|
4191
|
+
}
|
|
4192
|
+
|
|
4193
|
+
/* Dark mode support */
|
|
4194
|
+
.dark [data-state="open"][data-radix-dialog-content],
|
|
4195
|
+
.dark [role="dialog"][data-radix-dialog-content] {
|
|
4196
|
+
background: #0f172a !important;
|
|
4197
|
+
border: 1px solid #334155 !important;
|
|
4198
|
+
}
|
|
4199
|
+
`;
|
|
4200
|
+
document.head.appendChild(styleElement);
|
|
4201
|
+
};
|
|
4111
4202
|
var AvatarUploader = ({
|
|
4112
4203
|
onUploadComplete,
|
|
4113
4204
|
onError,
|
|
@@ -4118,32 +4209,30 @@ var AvatarUploader = ({
|
|
|
4118
4209
|
upfilesConfig,
|
|
4119
4210
|
buttonText = "Upload Avatar"
|
|
4120
4211
|
}) => {
|
|
4121
|
-
const {
|
|
4122
|
-
const [open, setOpen] =
|
|
4123
|
-
const [uploading, setUploading] =
|
|
4212
|
+
const { user, updateProfile } = useAuth2();
|
|
4213
|
+
const [open, setOpen] = React.useState(false);
|
|
4214
|
+
const [uploading, setUploading] = React.useState(false);
|
|
4215
|
+
React.useEffect(() => {
|
|
4216
|
+
injectModalStyles();
|
|
4217
|
+
}, []);
|
|
4218
|
+
const effectiveFolderPath = React.useMemo(() => {
|
|
4219
|
+
if (user?.id) {
|
|
4220
|
+
return `users/${user.id}/`;
|
|
4221
|
+
}
|
|
4222
|
+
return upfilesConfig.folderPath || "/";
|
|
4223
|
+
}, [user?.id, upfilesConfig.folderPath]);
|
|
4124
4224
|
const handleSelect = async (image) => {
|
|
4125
4225
|
setUploading(true);
|
|
4126
4226
|
try {
|
|
4127
|
-
const
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
[upfilesConfig.apiKeyHeader || "authorization"]: upfilesConfig.apiKey.startsWith("upk_") ? `Bearer ${upfilesConfig.apiKey}` : upfilesConfig.apiKey
|
|
4131
|
-
} : {}
|
|
4132
|
-
});
|
|
4133
|
-
if (!response.ok) {
|
|
4134
|
-
throw new Error("Failed to fetch image");
|
|
4135
|
-
}
|
|
4136
|
-
const blob = await response.blob();
|
|
4137
|
-
const file = new File([blob], image.originalName, { type: image.contentType });
|
|
4138
|
-
const result = await uploadAndUpdateAvatar(file);
|
|
4139
|
-
if (result.success && result.user?.avatar) {
|
|
4140
|
-
onUploadComplete?.(result.user.avatar);
|
|
4227
|
+
const response = await updateProfile({ avatar: image.url });
|
|
4228
|
+
if (response.success && response.user?.avatar) {
|
|
4229
|
+
onUploadComplete?.(response.user.avatar);
|
|
4141
4230
|
setOpen(false);
|
|
4142
4231
|
} else {
|
|
4143
|
-
throw new Error(
|
|
4232
|
+
throw new Error(response.message || "Failed to update avatar");
|
|
4144
4233
|
}
|
|
4145
4234
|
} catch (error) {
|
|
4146
|
-
const err = error instanceof Error ? error : new Error("
|
|
4235
|
+
const err = error instanceof Error ? error : new Error("Failed to update avatar");
|
|
4147
4236
|
onError?.(err);
|
|
4148
4237
|
} finally {
|
|
4149
4238
|
setUploading(false);
|
|
@@ -4173,7 +4262,7 @@ var AvatarUploader = ({
|
|
|
4173
4262
|
presignPath: upfilesConfig.presignPath
|
|
4174
4263
|
},
|
|
4175
4264
|
projectId: upfilesConfig.projectId,
|
|
4176
|
-
folderPath:
|
|
4265
|
+
folderPath: effectiveFolderPath,
|
|
4177
4266
|
title: "Select Avatar",
|
|
4178
4267
|
description: "Upload a new avatar or select from existing images.",
|
|
4179
4268
|
mode: "full",
|
|
@@ -4194,12 +4283,12 @@ var UserProfile = ({
|
|
|
4194
4283
|
}) => {
|
|
4195
4284
|
const { user, updateProfile, requestEmailChange } = useAuth2();
|
|
4196
4285
|
const colors = useThemeColors();
|
|
4197
|
-
const [name, setName] =
|
|
4198
|
-
const [phoneNumber, setPhoneNumber] =
|
|
4199
|
-
const [newEmail, setNewEmail] =
|
|
4200
|
-
const [isLoading, setIsLoading] =
|
|
4201
|
-
const [error, setError] =
|
|
4202
|
-
const [success, setSuccess] =
|
|
4286
|
+
const [name, setName] = React.useState(user?.name || "");
|
|
4287
|
+
const [phoneNumber, setPhoneNumber] = React.useState(user?.phoneNumber || "");
|
|
4288
|
+
const [newEmail, setNewEmail] = React.useState("");
|
|
4289
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
4290
|
+
const [error, setError] = React.useState(null);
|
|
4291
|
+
const [success, setSuccess] = React.useState(null);
|
|
4203
4292
|
const handleUpdateProfile = async (e) => {
|
|
4204
4293
|
e.preventDefault();
|
|
4205
4294
|
setIsLoading(true);
|
|
@@ -4490,12 +4579,27 @@ var AvatarManager = ({
|
|
|
4490
4579
|
gridClassName,
|
|
4491
4580
|
maxFileSize = 5 * 1024 * 1024,
|
|
4492
4581
|
// 5MB default
|
|
4582
|
+
maxFiles = 10,
|
|
4493
4583
|
mode = "full",
|
|
4494
4584
|
showDelete = false,
|
|
4585
|
+
autoRecordToDb = true,
|
|
4586
|
+
fetchThumbnails = true,
|
|
4587
|
+
projectId,
|
|
4588
|
+
deleteUrl,
|
|
4589
|
+
onDelete,
|
|
4495
4590
|
upfilesConfig
|
|
4496
4591
|
}) => {
|
|
4497
|
-
const { updateProfile } = useAuth2();
|
|
4498
|
-
const [updating, setUpdating] =
|
|
4592
|
+
const { user, updateProfile } = useAuth2();
|
|
4593
|
+
const [updating, setUpdating] = React.useState(false);
|
|
4594
|
+
React.useEffect(() => {
|
|
4595
|
+
injectModalStyles();
|
|
4596
|
+
}, []);
|
|
4597
|
+
const effectiveFolderPath = React.useMemo(() => {
|
|
4598
|
+
if (user?.id) {
|
|
4599
|
+
return `users/${user.id}/`;
|
|
4600
|
+
}
|
|
4601
|
+
return upfilesConfig.folderPath || "/";
|
|
4602
|
+
}, [user?.id, upfilesConfig.folderPath]);
|
|
4499
4603
|
const handleSelect = async (image) => {
|
|
4500
4604
|
setUpdating(true);
|
|
4501
4605
|
try {
|
|
@@ -4523,18 +4627,25 @@ var AvatarManager = ({
|
|
|
4523
4627
|
apiKey: upfilesConfig.apiKey,
|
|
4524
4628
|
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4525
4629
|
presignUrl: upfilesConfig.presignUrl,
|
|
4526
|
-
presignPath: upfilesConfig.presignPath
|
|
4630
|
+
presignPath: upfilesConfig.presignPath,
|
|
4631
|
+
headers: upfilesConfig.headers,
|
|
4632
|
+
withCredentials: upfilesConfig.withCredentials
|
|
4527
4633
|
},
|
|
4528
|
-
|
|
4634
|
+
projectId,
|
|
4635
|
+
folderPath: effectiveFolderPath,
|
|
4529
4636
|
title,
|
|
4530
4637
|
description,
|
|
4531
4638
|
className,
|
|
4532
4639
|
gridClassName,
|
|
4533
4640
|
onSelect: handleSelect,
|
|
4641
|
+
onDelete,
|
|
4642
|
+
deleteUrl,
|
|
4643
|
+
autoRecordToDb,
|
|
4644
|
+
fetchThumbnails,
|
|
4534
4645
|
maxFileSize,
|
|
4646
|
+
maxFiles,
|
|
4535
4647
|
mode,
|
|
4536
|
-
showDelete
|
|
4537
|
-
fetchThumbnails: true
|
|
4648
|
+
showDelete
|
|
4538
4649
|
}
|
|
4539
4650
|
);
|
|
4540
4651
|
};
|