@thetechfossil/auth2 1.2.21 → 1.2.22
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 +7 -0
- package/dist/index.components.d.mts +14 -1
- package/dist/index.components.d.ts +14 -1
- package/dist/index.components.js +458 -59
- package/dist/index.components.js.map +1 -1
- package/dist/index.components.mjs +458 -60
- package/dist/index.components.mjs.map +1 -1
- package/dist/index.d.mts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +459 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +459 -60
- package/dist/index.mjs.map +1 -1
- package/dist/index.next.d.mts +16 -1
- package/dist/index.next.d.ts +16 -1
- package/dist/index.next.js +458 -59
- package/dist/index.next.js.map +1 -1
- package/dist/index.next.mjs +458 -60
- package/dist/index.next.mjs.map +1 -1
- package/dist/index.next.server.d.mts +2 -0
- package/dist/index.next.server.d.ts +2 -0
- package/dist/index.next.server.js +14 -0
- package/dist/index.next.server.js.map +1 -1
- package/dist/index.next.server.mjs +14 -0
- package/dist/index.next.server.mjs.map +1 -1
- package/dist/index.node.d.mts +2 -0
- package/dist/index.node.d.ts +2 -0
- package/dist/index.node.js +14 -0
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +14 -0
- package/dist/index.node.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.components.js
CHANGED
|
@@ -12,12 +12,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
12
12
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
13
13
|
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
14
14
|
|
|
15
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
16
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
17
|
-
}) : x)(function(x) {
|
|
18
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
19
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
20
|
-
});
|
|
21
15
|
var ERROR_MESSAGES = {
|
|
22
16
|
NETWORK_ERROR: "Unable to connect to the server. Please check your internet connection and try again.",
|
|
23
17
|
TIMEOUT: "The request took too long. Please try again.",
|
|
@@ -347,6 +341,7 @@ var AuthService = class {
|
|
|
347
341
|
if (token) {
|
|
348
342
|
this.token = token;
|
|
349
343
|
this.httpClient.setAuthToken(token);
|
|
344
|
+
this.setTokenCookie(token);
|
|
350
345
|
}
|
|
351
346
|
} catch (error) {
|
|
352
347
|
console.warn("Failed to load token from storage:", error);
|
|
@@ -357,15 +352,28 @@ var AuthService = class {
|
|
|
357
352
|
if (typeof window !== "undefined" && this.config.localStorageKey) {
|
|
358
353
|
try {
|
|
359
354
|
localStorage.setItem(this.config.localStorageKey, token);
|
|
355
|
+
this.setTokenCookie(token);
|
|
360
356
|
} catch (error) {
|
|
361
357
|
console.warn("Failed to save token to storage:", error);
|
|
362
358
|
}
|
|
363
359
|
}
|
|
364
360
|
}
|
|
361
|
+
setTokenCookie(token) {
|
|
362
|
+
if (typeof window !== "undefined") {
|
|
363
|
+
const maxAge = 7 * 24 * 60 * 60;
|
|
364
|
+
document.cookie = `auth_token=${token}; path=/; max-age=${maxAge}; SameSite=Lax`;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
removeTokenCookie() {
|
|
368
|
+
if (typeof window !== "undefined") {
|
|
369
|
+
document.cookie = "auth_token=; path=/; max-age=0; SameSite=Lax";
|
|
370
|
+
}
|
|
371
|
+
}
|
|
365
372
|
removeTokenFromStorage() {
|
|
366
373
|
if (typeof window !== "undefined" && this.config.localStorageKey) {
|
|
367
374
|
try {
|
|
368
375
|
localStorage.removeItem(this.config.localStorageKey);
|
|
376
|
+
this.removeTokenCookie();
|
|
369
377
|
} catch (error) {
|
|
370
378
|
console.warn("Failed to remove token from storage:", error);
|
|
371
379
|
}
|
|
@@ -965,14 +973,6 @@ function useThemeColors() {
|
|
|
965
973
|
const { theme } = useAuthTheme();
|
|
966
974
|
return theme === "dark" ? darkTheme : lightTheme;
|
|
967
975
|
}
|
|
968
|
-
var PhoneInputWithCountry = null;
|
|
969
|
-
try {
|
|
970
|
-
const module = __require("react-phone-number-input");
|
|
971
|
-
PhoneInputWithCountry = module.default || module;
|
|
972
|
-
__require("react-phone-number-input/style.css");
|
|
973
|
-
} catch (error) {
|
|
974
|
-
console.warn("react-phone-number-input not available, using fallback");
|
|
975
|
-
}
|
|
976
976
|
var CustomPhoneInput = React__default.default.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
977
977
|
"input",
|
|
978
978
|
{
|
|
@@ -993,6 +993,8 @@ var PhoneInput = ({
|
|
|
993
993
|
}) => {
|
|
994
994
|
const colors = useThemeColors();
|
|
995
995
|
const [defaultCountry, setDefaultCountry] = React.useState("US");
|
|
996
|
+
const [PhoneInputComponent, setPhoneInputComponent] = React.useState(null);
|
|
997
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
996
998
|
const styleContent = React.useMemo(() => `
|
|
997
999
|
.PhoneInput {
|
|
998
1000
|
display: flex;
|
|
@@ -1105,6 +1107,29 @@ var PhoneInput = ({
|
|
|
1105
1107
|
opacity: 0.6;
|
|
1106
1108
|
}
|
|
1107
1109
|
`, [colors]);
|
|
1110
|
+
React.useEffect(() => {
|
|
1111
|
+
let mounted = true;
|
|
1112
|
+
const loadPhoneInput = async () => {
|
|
1113
|
+
try {
|
|
1114
|
+
const module = await import('react-phone-number-input');
|
|
1115
|
+
if (mounted) {
|
|
1116
|
+
setPhoneInputComponent(() => module.default);
|
|
1117
|
+
}
|
|
1118
|
+
} catch (error) {
|
|
1119
|
+
if (mounted) {
|
|
1120
|
+
setPhoneInputComponent(null);
|
|
1121
|
+
}
|
|
1122
|
+
} finally {
|
|
1123
|
+
if (mounted) {
|
|
1124
|
+
setIsLoading(false);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
loadPhoneInput();
|
|
1129
|
+
return () => {
|
|
1130
|
+
mounted = false;
|
|
1131
|
+
};
|
|
1132
|
+
}, []);
|
|
1108
1133
|
React.useEffect(() => {
|
|
1109
1134
|
const detectCountry = async () => {
|
|
1110
1135
|
try {
|
|
@@ -1157,7 +1182,6 @@ var PhoneInput = ({
|
|
|
1157
1182
|
}
|
|
1158
1183
|
}
|
|
1159
1184
|
} catch (error) {
|
|
1160
|
-
console.log("Country detection failed, using default US");
|
|
1161
1185
|
}
|
|
1162
1186
|
};
|
|
1163
1187
|
detectCountry();
|
|
@@ -1165,7 +1189,31 @@ var PhoneInput = ({
|
|
|
1165
1189
|
const handleChange = React.useMemo(() => (val) => {
|
|
1166
1190
|
onChange(val || "");
|
|
1167
1191
|
}, [onChange]);
|
|
1168
|
-
if (
|
|
1192
|
+
if (isLoading) {
|
|
1193
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1194
|
+
"input",
|
|
1195
|
+
{
|
|
1196
|
+
id,
|
|
1197
|
+
type: "tel",
|
|
1198
|
+
value,
|
|
1199
|
+
onChange: (e) => onChange(e.target.value),
|
|
1200
|
+
disabled,
|
|
1201
|
+
required,
|
|
1202
|
+
placeholder,
|
|
1203
|
+
style: {
|
|
1204
|
+
width: "100%",
|
|
1205
|
+
padding: "12px 16px",
|
|
1206
|
+
border: `1px solid ${colors.borderSecondary}`,
|
|
1207
|
+
borderRadius: "8px",
|
|
1208
|
+
fontSize: "16px",
|
|
1209
|
+
backgroundColor: colors.bgSecondary,
|
|
1210
|
+
color: colors.textPrimary,
|
|
1211
|
+
...style
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
if (!PhoneInputComponent) {
|
|
1169
1217
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1170
1218
|
"input",
|
|
1171
1219
|
{
|
|
@@ -1199,7 +1247,7 @@ var PhoneInput = ({
|
|
|
1199
1247
|
children: [
|
|
1200
1248
|
/* @__PURE__ */ jsxRuntime.jsx("style", { children: styleContent }),
|
|
1201
1249
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1202
|
-
|
|
1250
|
+
PhoneInputComponent,
|
|
1203
1251
|
{
|
|
1204
1252
|
id,
|
|
1205
1253
|
international: true,
|
|
@@ -1697,6 +1745,28 @@ var RegisterForm = ({
|
|
|
1697
1745
|
const [error, setError] = React.useState(null);
|
|
1698
1746
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
1699
1747
|
const [showConfirmPassword, setShowConfirmPassword] = React.useState(false);
|
|
1748
|
+
const [invitationDetails, setInvitationDetails] = React.useState(null);
|
|
1749
|
+
const [isLoadingInvitation, setIsLoadingInvitation] = React.useState(false);
|
|
1750
|
+
const config = authConfig || {
|
|
1751
|
+
baseUrl: "http://localhost:7000"
|
|
1752
|
+
};
|
|
1753
|
+
React.useEffect(() => {
|
|
1754
|
+
if (invitationToken) {
|
|
1755
|
+
setIsLoadingInvitation(true);
|
|
1756
|
+
fetch(`${config.baseUrl}/api/v1/auth/verify-invitation/${invitationToken}`).then((res) => res.json()).then((data) => {
|
|
1757
|
+
setInvitationDetails(data);
|
|
1758
|
+
if (data.valid && data.email) {
|
|
1759
|
+
setEmail(data.email);
|
|
1760
|
+
}
|
|
1761
|
+
}).catch((err) => {
|
|
1762
|
+
console.error("Failed to verify invitation:", err);
|
|
1763
|
+
setError("Failed to verify invitation. Please try again.");
|
|
1764
|
+
}).finally(() => {
|
|
1765
|
+
setIsLoadingInvitation(false);
|
|
1766
|
+
});
|
|
1767
|
+
}
|
|
1768
|
+
}, [invitationToken, config.baseUrl]);
|
|
1769
|
+
const isEmailDisabled = isLoading || invitationDetails?.valid && !!invitationDetails?.email;
|
|
1700
1770
|
const getPasswordStrength = (pwd) => {
|
|
1701
1771
|
if (!pwd) return { strength: "weak", score: 0, label: "" };
|
|
1702
1772
|
let score = 0;
|
|
@@ -1710,9 +1780,6 @@ var RegisterForm = ({
|
|
|
1710
1780
|
return { strength: "strong", score, label: "Strong" };
|
|
1711
1781
|
};
|
|
1712
1782
|
getPasswordStrength(password);
|
|
1713
|
-
const config = authConfig || {
|
|
1714
|
-
baseUrl: "http://localhost:7000"
|
|
1715
|
-
};
|
|
1716
1783
|
const { register } = useAuth(config);
|
|
1717
1784
|
const handleSubmit = async (e) => {
|
|
1718
1785
|
e.preventDefault();
|
|
@@ -1747,6 +1814,25 @@ var RegisterForm = ({
|
|
|
1747
1814
|
if (response.ok && data.success) {
|
|
1748
1815
|
if (typeof window !== "undefined" && data.token) {
|
|
1749
1816
|
localStorage.setItem("auth_token", data.token);
|
|
1817
|
+
if (data.invitation?.organizationId && data.invitation?.role) {
|
|
1818
|
+
localStorage.setItem("currentOrganizationId", data.invitation.organizationId);
|
|
1819
|
+
const backendUrl = typeof window !== "undefined" ? process.env.NEXT_PUBLIC_INVENTORY_API_URL || process.env.NEXT_PUBLIC_BIZFLOW_API_URL || "http://localhost:5002" : "http://localhost:5002";
|
|
1820
|
+
try {
|
|
1821
|
+
await fetch(`${backendUrl}/api/auth/sync-with-role`, {
|
|
1822
|
+
method: "POST",
|
|
1823
|
+
headers: {
|
|
1824
|
+
"Content-Type": "application/json",
|
|
1825
|
+
"Authorization": `Bearer ${data.token}`
|
|
1826
|
+
},
|
|
1827
|
+
body: JSON.stringify({
|
|
1828
|
+
organizationId: data.invitation.organizationId,
|
|
1829
|
+
roleName: data.invitation.role
|
|
1830
|
+
})
|
|
1831
|
+
});
|
|
1832
|
+
} catch (syncError) {
|
|
1833
|
+
console.error("Failed to sync user role with backend:", syncError);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1750
1836
|
}
|
|
1751
1837
|
onRegisterSuccess?.();
|
|
1752
1838
|
} else {
|
|
@@ -1854,7 +1940,7 @@ var RegisterForm = ({
|
|
|
1854
1940
|
value: email,
|
|
1855
1941
|
onChange: (e) => setEmail(e.target.value),
|
|
1856
1942
|
required: !phoneNumber,
|
|
1857
|
-
disabled:
|
|
1943
|
+
disabled: isEmailDisabled,
|
|
1858
1944
|
style: {
|
|
1859
1945
|
width: "100%",
|
|
1860
1946
|
padding: "12px 16px",
|
|
@@ -1862,9 +1948,11 @@ var RegisterForm = ({
|
|
|
1862
1948
|
borderRadius: "8px",
|
|
1863
1949
|
fontSize: "16px",
|
|
1864
1950
|
boxSizing: "border-box",
|
|
1865
|
-
color: colors.textPrimary,
|
|
1951
|
+
color: isEmailDisabled ? colors.textSecondary : colors.textPrimary,
|
|
1866
1952
|
transition: "all 0.2s ease",
|
|
1867
|
-
backgroundColor: colors.bgSecondary
|
|
1953
|
+
backgroundColor: isEmailDisabled ? colors.bgHover : colors.bgSecondary,
|
|
1954
|
+
cursor: isEmailDisabled ? "not-allowed" : "text",
|
|
1955
|
+
opacity: isEmailDisabled ? 0.7 : 1
|
|
1868
1956
|
},
|
|
1869
1957
|
placeholder: "Enter your email"
|
|
1870
1958
|
}
|
|
@@ -2567,7 +2655,7 @@ var EmailVerificationPage = ({
|
|
|
2567
2655
|
} })
|
|
2568
2656
|
] }) });
|
|
2569
2657
|
}
|
|
2570
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
2658
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
2571
2659
|
maxWidth: "500px",
|
|
2572
2660
|
margin: "0 auto",
|
|
2573
2661
|
padding: "30px",
|
|
@@ -2576,44 +2664,86 @@ var EmailVerificationPage = ({
|
|
|
2576
2664
|
backgroundColor: "#ffffff",
|
|
2577
2665
|
textAlign: "center",
|
|
2578
2666
|
border: "1px solid #eaeaea"
|
|
2579
|
-
}, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
2580
|
-
padding: "20px"
|
|
2581
2667
|
}, children: [
|
|
2582
|
-
/* @__PURE__ */ jsxRuntime.
|
|
2583
|
-
|
|
2584
|
-
padding: "16px 20px",
|
|
2585
|
-
margin: "24px 0",
|
|
2586
|
-
borderRadius: "8px",
|
|
2587
|
-
fontSize: "15px",
|
|
2588
|
-
fontWeight: 500,
|
|
2589
|
-
backgroundColor: isSuccess ? "#d4edda" : "#f8d7da",
|
|
2590
|
-
color: isSuccess ? "#155724" : "#721c24",
|
|
2591
|
-
border: isSuccess ? "1px solid #c3e6cb" : "1px solid #f5c6cb"
|
|
2592
|
-
}, children: message }),
|
|
2593
|
-
isSuccess && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
2594
|
-
marginTop: "24px"
|
|
2668
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
2669
|
+
padding: "20px"
|
|
2595
2670
|
}, children: [
|
|
2596
|
-
/* @__PURE__ */ jsxRuntime.jsx("
|
|
2597
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2598
|
-
"
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2671
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: { color: "black" }, children: isSuccess ? "\u2713 Email Verified!" : "\u2717 Verification Failed" }),
|
|
2672
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2673
|
+
padding: "16px 20px",
|
|
2674
|
+
margin: "24px 0",
|
|
2675
|
+
borderRadius: "8px",
|
|
2676
|
+
fontSize: "15px",
|
|
2677
|
+
fontWeight: 500,
|
|
2678
|
+
backgroundColor: isSuccess ? "#d4edda" : "#f8d7da",
|
|
2679
|
+
color: isSuccess ? "#155724" : "#721c24",
|
|
2680
|
+
border: isSuccess ? "1px solid #c3e6cb" : "1px solid #f5c6cb"
|
|
2681
|
+
}, children: message }),
|
|
2682
|
+
isSuccess ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "24px" }, children: [
|
|
2683
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "#666", marginBottom: "16px" }, children: "Redirecting to login..." }),
|
|
2684
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2685
|
+
border: "3px solid #d4edda",
|
|
2686
|
+
borderTop: "3px solid #28a745",
|
|
2687
|
+
borderRadius: "50%",
|
|
2688
|
+
width: "30px",
|
|
2689
|
+
height: "30px",
|
|
2690
|
+
animation: "spin 1s linear infinite",
|
|
2691
|
+
margin: "0 auto"
|
|
2692
|
+
} })
|
|
2693
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "24px" }, children: [
|
|
2694
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "#666", marginBottom: "16px" }, children: "The verification link may have expired or already been used." }),
|
|
2695
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2696
|
+
"button",
|
|
2697
|
+
{
|
|
2698
|
+
onClick: () => {
|
|
2699
|
+
const registerPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_TO_REGISTER || "/auth/register";
|
|
2700
|
+
window.location.href = registerPath;
|
|
2701
|
+
},
|
|
2702
|
+
style: {
|
|
2703
|
+
padding: "12px 24px",
|
|
2704
|
+
backgroundColor: "#007bff",
|
|
2705
|
+
color: "white",
|
|
2706
|
+
border: "none",
|
|
2707
|
+
borderRadius: "8px",
|
|
2708
|
+
fontSize: "16px",
|
|
2709
|
+
fontWeight: 600,
|
|
2710
|
+
cursor: "pointer",
|
|
2711
|
+
transition: "all 0.2s ease",
|
|
2712
|
+
marginRight: "12px"
|
|
2713
|
+
},
|
|
2714
|
+
children: "Register Again"
|
|
2715
|
+
}
|
|
2716
|
+
),
|
|
2717
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2718
|
+
"button",
|
|
2719
|
+
{
|
|
2720
|
+
onClick: () => {
|
|
2721
|
+
const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
2722
|
+
window.location.href = loginPath;
|
|
2723
|
+
},
|
|
2724
|
+
style: {
|
|
2725
|
+
padding: "12px 24px",
|
|
2726
|
+
backgroundColor: "#6c757d",
|
|
2727
|
+
color: "white",
|
|
2728
|
+
border: "none",
|
|
2729
|
+
borderRadius: "8px",
|
|
2730
|
+
fontSize: "16px",
|
|
2731
|
+
fontWeight: 600,
|
|
2732
|
+
cursor: "pointer",
|
|
2733
|
+
transition: "all 0.2s ease"
|
|
2734
|
+
},
|
|
2735
|
+
children: "Go to Login"
|
|
2736
|
+
}
|
|
2737
|
+
)
|
|
2738
|
+
] })
|
|
2739
|
+
] }),
|
|
2740
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
2741
|
+
@keyframes spin {
|
|
2742
|
+
0% { transform: rotate(0deg); }
|
|
2743
|
+
100% { transform: rotate(360deg); }
|
|
2613
2744
|
}
|
|
2614
|
-
)
|
|
2615
|
-
|
|
2616
|
-
] }) });
|
|
2745
|
+
` })
|
|
2746
|
+
] });
|
|
2617
2747
|
};
|
|
2618
2748
|
var AuthContext = React.createContext(void 0);
|
|
2619
2749
|
var useAuth2 = () => {
|
|
@@ -4832,6 +4962,274 @@ var UserProfile = ({
|
|
|
4832
4962
|
] })
|
|
4833
4963
|
] });
|
|
4834
4964
|
};
|
|
4965
|
+
var SuperAdminSignIn = ({ redirectUrl, appearance }) => {
|
|
4966
|
+
const { signIn, isSignedIn, loading: authLoading, user } = useAuth2();
|
|
4967
|
+
const colors = useThemeColors();
|
|
4968
|
+
const [email, setEmail] = React.useState("");
|
|
4969
|
+
const [password, setPassword] = React.useState("");
|
|
4970
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
4971
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
4972
|
+
const [error, setError] = React.useState(null);
|
|
4973
|
+
const [success, setSuccess] = React.useState(null);
|
|
4974
|
+
React.useEffect(() => {
|
|
4975
|
+
if (isSignedIn && user) {
|
|
4976
|
+
const isSuperAdmin = user.role === "SUPER_ADMIN" || user.role === "SUPERADMIN";
|
|
4977
|
+
if (isSuperAdmin) {
|
|
4978
|
+
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
4979
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
4980
|
+
window.location.href = `${baseUrl}${redirect}`;
|
|
4981
|
+
} else {
|
|
4982
|
+
setError("Access denied. Only Super Admin users can access this portal.");
|
|
4983
|
+
document.cookie = "auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
4984
|
+
document.cookie = "refresh_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
}, [isSignedIn, user, redirectUrl]);
|
|
4988
|
+
const handleSubmit = async (e) => {
|
|
4989
|
+
e.preventDefault();
|
|
4990
|
+
setIsLoading(true);
|
|
4991
|
+
setError(null);
|
|
4992
|
+
setSuccess(null);
|
|
4993
|
+
try {
|
|
4994
|
+
const response = await signIn({ email, password });
|
|
4995
|
+
if (response.success) {
|
|
4996
|
+
const userRole = response.user?.role;
|
|
4997
|
+
const isSuperAdmin = userRole === "SUPER_ADMIN" || userRole === "SUPERADMIN";
|
|
4998
|
+
if (!isSuperAdmin) {
|
|
4999
|
+
document.cookie = "auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
5000
|
+
document.cookie = "refresh_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
5001
|
+
setError("Access denied. Only Super Admin users can access this portal.");
|
|
5002
|
+
return;
|
|
5003
|
+
}
|
|
5004
|
+
setSuccess("Login successful! Redirecting...");
|
|
5005
|
+
} else {
|
|
5006
|
+
setError(response.message || "Login failed. Please check your credentials.");
|
|
5007
|
+
}
|
|
5008
|
+
} catch (err) {
|
|
5009
|
+
setError(err instanceof Error ? err.message : "An error occurred during login.");
|
|
5010
|
+
} finally {
|
|
5011
|
+
setIsLoading(false);
|
|
5012
|
+
}
|
|
5013
|
+
};
|
|
5014
|
+
if (authLoading) {
|
|
5015
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }) });
|
|
5016
|
+
}
|
|
5017
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5018
|
+
ThemeWrapper,
|
|
5019
|
+
{
|
|
5020
|
+
style: {
|
|
5021
|
+
maxWidth: "400px",
|
|
5022
|
+
margin: "0 auto",
|
|
5023
|
+
padding: "30px",
|
|
5024
|
+
borderRadius: "12px",
|
|
5025
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
5026
|
+
backgroundColor: colors.bgPrimary,
|
|
5027
|
+
border: `1px solid ${colors.borderPrimary}`,
|
|
5028
|
+
...appearance?.elements?.card
|
|
5029
|
+
},
|
|
5030
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
|
|
5031
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", marginBottom: "24px" }, children: [
|
|
5032
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
5033
|
+
width: "60px",
|
|
5034
|
+
height: "60px",
|
|
5035
|
+
margin: "0 auto 16px",
|
|
5036
|
+
backgroundColor: colors.buttonPrimary + "20",
|
|
5037
|
+
borderRadius: "12px",
|
|
5038
|
+
display: "flex",
|
|
5039
|
+
alignItems: "center",
|
|
5040
|
+
justifyContent: "center"
|
|
5041
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: colors.buttonPrimary, strokeWidth: "2", children: [
|
|
5042
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" }),
|
|
5043
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 12l2 2 4-4" })
|
|
5044
|
+
] }) }),
|
|
5045
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
5046
|
+
color: colors.textPrimary,
|
|
5047
|
+
fontSize: "24px",
|
|
5048
|
+
fontWeight: 600,
|
|
5049
|
+
margin: 0,
|
|
5050
|
+
...appearance?.elements?.headerTitle
|
|
5051
|
+
}, children: "Super Admin Portal" }),
|
|
5052
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: {
|
|
5053
|
+
color: colors.textSecondary,
|
|
5054
|
+
fontSize: "14px",
|
|
5055
|
+
marginTop: "8px"
|
|
5056
|
+
}, children: "Sign in with your administrator credentials" })
|
|
5057
|
+
] }),
|
|
5058
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
5059
|
+
padding: "12px 16px",
|
|
5060
|
+
marginBottom: "20px",
|
|
5061
|
+
backgroundColor: colors.errorBg,
|
|
5062
|
+
color: colors.errorText,
|
|
5063
|
+
border: `1px solid ${colors.errorBorder}`,
|
|
5064
|
+
borderRadius: "8px",
|
|
5065
|
+
fontSize: "14px"
|
|
5066
|
+
}, children: error }),
|
|
5067
|
+
success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
5068
|
+
padding: "12px 16px",
|
|
5069
|
+
marginBottom: "20px",
|
|
5070
|
+
backgroundColor: colors.successBg,
|
|
5071
|
+
color: colors.successText,
|
|
5072
|
+
border: `1px solid ${colors.successBorder}`,
|
|
5073
|
+
borderRadius: "8px",
|
|
5074
|
+
fontSize: "14px"
|
|
5075
|
+
}, children: success }),
|
|
5076
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
5077
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
|
|
5078
|
+
display: "block",
|
|
5079
|
+
marginBottom: "8px",
|
|
5080
|
+
fontWeight: 500,
|
|
5081
|
+
color: colors.textSecondary,
|
|
5082
|
+
fontSize: "14px"
|
|
5083
|
+
}, children: "Email Address" }),
|
|
5084
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5085
|
+
"input",
|
|
5086
|
+
{
|
|
5087
|
+
id: "email",
|
|
5088
|
+
type: "email",
|
|
5089
|
+
value: email,
|
|
5090
|
+
onChange: (e) => setEmail(e.target.value),
|
|
5091
|
+
onFocus: (e) => {
|
|
5092
|
+
e.currentTarget.style.borderColor = colors.buttonPrimary;
|
|
5093
|
+
e.currentTarget.style.outline = `2px solid ${colors.buttonPrimary}40`;
|
|
5094
|
+
},
|
|
5095
|
+
onBlur: (e) => {
|
|
5096
|
+
e.currentTarget.style.borderColor = colors.borderSecondary;
|
|
5097
|
+
e.currentTarget.style.outline = "none";
|
|
5098
|
+
},
|
|
5099
|
+
required: true,
|
|
5100
|
+
disabled: isLoading,
|
|
5101
|
+
autoComplete: "email",
|
|
5102
|
+
style: {
|
|
5103
|
+
width: "100%",
|
|
5104
|
+
padding: "12px 16px",
|
|
5105
|
+
border: `1px solid ${colors.borderSecondary}`,
|
|
5106
|
+
borderRadius: "8px",
|
|
5107
|
+
fontSize: "16px",
|
|
5108
|
+
boxSizing: "border-box",
|
|
5109
|
+
backgroundColor: colors.bgSecondary,
|
|
5110
|
+
color: colors.textPrimary,
|
|
5111
|
+
transition: "all 0.2s ease",
|
|
5112
|
+
WebkitTextFillColor: colors.textPrimary,
|
|
5113
|
+
WebkitBoxShadow: `0 0 0 1000px ${colors.bgSecondary} inset`,
|
|
5114
|
+
...appearance?.elements?.formFieldInput
|
|
5115
|
+
},
|
|
5116
|
+
placeholder: "admin@example.com"
|
|
5117
|
+
}
|
|
5118
|
+
)
|
|
5119
|
+
] }),
|
|
5120
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "24px", position: "relative" }, children: [
|
|
5121
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
|
|
5122
|
+
display: "block",
|
|
5123
|
+
marginBottom: "8px",
|
|
5124
|
+
fontWeight: 500,
|
|
5125
|
+
color: colors.textSecondary,
|
|
5126
|
+
fontSize: "14px"
|
|
5127
|
+
}, children: "Password" }),
|
|
5128
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5129
|
+
"input",
|
|
5130
|
+
{
|
|
5131
|
+
id: "password",
|
|
5132
|
+
type: showPassword ? "text" : "password",
|
|
5133
|
+
value: password,
|
|
5134
|
+
onChange: (e) => setPassword(e.target.value),
|
|
5135
|
+
onFocus: (e) => {
|
|
5136
|
+
e.currentTarget.style.borderColor = colors.buttonPrimary;
|
|
5137
|
+
e.currentTarget.style.outline = `2px solid ${colors.buttonPrimary}40`;
|
|
5138
|
+
},
|
|
5139
|
+
onBlur: (e) => {
|
|
5140
|
+
e.currentTarget.style.borderColor = colors.borderSecondary;
|
|
5141
|
+
e.currentTarget.style.outline = "none";
|
|
5142
|
+
},
|
|
5143
|
+
required: true,
|
|
5144
|
+
disabled: isLoading,
|
|
5145
|
+
autoComplete: "current-password",
|
|
5146
|
+
style: {
|
|
5147
|
+
width: "100%",
|
|
5148
|
+
padding: "12px 16px",
|
|
5149
|
+
paddingRight: "60px",
|
|
5150
|
+
border: `1px solid ${colors.borderSecondary}`,
|
|
5151
|
+
borderRadius: "8px",
|
|
5152
|
+
fontSize: "16px",
|
|
5153
|
+
boxSizing: "border-box",
|
|
5154
|
+
backgroundColor: colors.bgSecondary,
|
|
5155
|
+
color: colors.textPrimary,
|
|
5156
|
+
transition: "all 0.2s ease",
|
|
5157
|
+
WebkitTextFillColor: colors.textPrimary,
|
|
5158
|
+
WebkitBoxShadow: `0 0 0 1000px ${colors.bgSecondary} inset`,
|
|
5159
|
+
...appearance?.elements?.formFieldInput
|
|
5160
|
+
},
|
|
5161
|
+
placeholder: "Enter your password"
|
|
5162
|
+
}
|
|
5163
|
+
),
|
|
5164
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5165
|
+
"button",
|
|
5166
|
+
{
|
|
5167
|
+
type: "button",
|
|
5168
|
+
onClick: () => setShowPassword(!showPassword),
|
|
5169
|
+
style: {
|
|
5170
|
+
position: "absolute",
|
|
5171
|
+
right: "12px",
|
|
5172
|
+
top: "38px",
|
|
5173
|
+
background: "none",
|
|
5174
|
+
border: "none",
|
|
5175
|
+
cursor: "pointer",
|
|
5176
|
+
color: colors.textTertiary,
|
|
5177
|
+
fontSize: "14px",
|
|
5178
|
+
padding: "4px 8px"
|
|
5179
|
+
},
|
|
5180
|
+
children: showPassword ? "Hide" : "Show"
|
|
5181
|
+
}
|
|
5182
|
+
)
|
|
5183
|
+
] }),
|
|
5184
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5185
|
+
"button",
|
|
5186
|
+
{
|
|
5187
|
+
type: "submit",
|
|
5188
|
+
disabled: isLoading || !email || !password,
|
|
5189
|
+
onMouseEnter: (e) => {
|
|
5190
|
+
if (!isLoading && email && password) {
|
|
5191
|
+
e.currentTarget.style.backgroundColor = colors.buttonPrimaryHover;
|
|
5192
|
+
}
|
|
5193
|
+
},
|
|
5194
|
+
onMouseLeave: (e) => {
|
|
5195
|
+
e.currentTarget.style.backgroundColor = colors.buttonPrimary;
|
|
5196
|
+
},
|
|
5197
|
+
style: {
|
|
5198
|
+
width: "100%",
|
|
5199
|
+
padding: "14px",
|
|
5200
|
+
backgroundColor: colors.buttonPrimary,
|
|
5201
|
+
color: "white",
|
|
5202
|
+
border: "none",
|
|
5203
|
+
borderRadius: "8px",
|
|
5204
|
+
fontSize: "16px",
|
|
5205
|
+
fontWeight: 600,
|
|
5206
|
+
cursor: isLoading || !email || !password ? "not-allowed" : "pointer",
|
|
5207
|
+
opacity: isLoading || !email || !password ? 0.6 : 1,
|
|
5208
|
+
transition: "all 0.2s ease",
|
|
5209
|
+
...appearance?.elements?.formButtonPrimary
|
|
5210
|
+
},
|
|
5211
|
+
children: isLoading ? "Signing in..." : "Sign In"
|
|
5212
|
+
}
|
|
5213
|
+
),
|
|
5214
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
5215
|
+
marginTop: "20px",
|
|
5216
|
+
padding: "12px",
|
|
5217
|
+
backgroundColor: colors.bgSecondary,
|
|
5218
|
+
borderRadius: "8px",
|
|
5219
|
+
textAlign: "center"
|
|
5220
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
|
|
5221
|
+
color: colors.textTertiary,
|
|
5222
|
+
fontSize: "12px",
|
|
5223
|
+
margin: 0
|
|
5224
|
+
}, children: [
|
|
5225
|
+
"\u{1F512} This portal is restricted to Super Admin users only.",
|
|
5226
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
5227
|
+
"Contact your system administrator if you need access."
|
|
5228
|
+
] }) })
|
|
5229
|
+
] })
|
|
5230
|
+
}
|
|
5231
|
+
);
|
|
5232
|
+
};
|
|
4835
5233
|
var AvatarManager = ({
|
|
4836
5234
|
open,
|
|
4837
5235
|
onOpenChange,
|
|
@@ -4930,6 +5328,7 @@ exports.ResetPassword = ResetPassword;
|
|
|
4930
5328
|
exports.SignIn = SignIn;
|
|
4931
5329
|
exports.SignOut = SignOut;
|
|
4932
5330
|
exports.SignUp = SignUp;
|
|
5331
|
+
exports.SuperAdminSignIn = SuperAdminSignIn;
|
|
4933
5332
|
exports.UserButton = UserButton;
|
|
4934
5333
|
exports.UserProfile = UserProfile;
|
|
4935
5334
|
exports.VerifyEmail = VerifyEmail;
|