@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.next.mjs
CHANGED
|
@@ -5,12 +5,6 @@ import { UpfilesClient, ImageManager } from '@thetechfossil/upfiles';
|
|
|
5
5
|
import React, { createContext, forwardRef, useContext, useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
|
|
8
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
-
});
|
|
14
8
|
var ERROR_MESSAGES = {
|
|
15
9
|
NETWORK_ERROR: "Unable to connect to the server. Please check your internet connection and try again.",
|
|
16
10
|
TIMEOUT: "The request took too long. Please try again.",
|
|
@@ -340,6 +334,7 @@ var AuthService = class {
|
|
|
340
334
|
if (token) {
|
|
341
335
|
this.token = token;
|
|
342
336
|
this.httpClient.setAuthToken(token);
|
|
337
|
+
this.setTokenCookie(token);
|
|
343
338
|
}
|
|
344
339
|
} catch (error) {
|
|
345
340
|
console.warn("Failed to load token from storage:", error);
|
|
@@ -350,15 +345,28 @@ var AuthService = class {
|
|
|
350
345
|
if (typeof window !== "undefined" && this.config.localStorageKey) {
|
|
351
346
|
try {
|
|
352
347
|
localStorage.setItem(this.config.localStorageKey, token);
|
|
348
|
+
this.setTokenCookie(token);
|
|
353
349
|
} catch (error) {
|
|
354
350
|
console.warn("Failed to save token to storage:", error);
|
|
355
351
|
}
|
|
356
352
|
}
|
|
357
353
|
}
|
|
354
|
+
setTokenCookie(token) {
|
|
355
|
+
if (typeof window !== "undefined") {
|
|
356
|
+
const maxAge = 7 * 24 * 60 * 60;
|
|
357
|
+
document.cookie = `auth_token=${token}; path=/; max-age=${maxAge}; SameSite=Lax`;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
removeTokenCookie() {
|
|
361
|
+
if (typeof window !== "undefined") {
|
|
362
|
+
document.cookie = "auth_token=; path=/; max-age=0; SameSite=Lax";
|
|
363
|
+
}
|
|
364
|
+
}
|
|
358
365
|
removeTokenFromStorage() {
|
|
359
366
|
if (typeof window !== "undefined" && this.config.localStorageKey) {
|
|
360
367
|
try {
|
|
361
368
|
localStorage.removeItem(this.config.localStorageKey);
|
|
369
|
+
this.removeTokenCookie();
|
|
362
370
|
} catch (error) {
|
|
363
371
|
console.warn("Failed to remove token from storage:", error);
|
|
364
372
|
}
|
|
@@ -1337,14 +1345,6 @@ function useThemeColors() {
|
|
|
1337
1345
|
const { theme } = useAuthTheme();
|
|
1338
1346
|
return theme === "dark" ? darkTheme : lightTheme;
|
|
1339
1347
|
}
|
|
1340
|
-
var PhoneInputWithCountry = null;
|
|
1341
|
-
try {
|
|
1342
|
-
const module = __require("react-phone-number-input");
|
|
1343
|
-
PhoneInputWithCountry = module.default || module;
|
|
1344
|
-
__require("react-phone-number-input/style.css");
|
|
1345
|
-
} catch (error) {
|
|
1346
|
-
console.warn("react-phone-number-input not available, using fallback");
|
|
1347
|
-
}
|
|
1348
1348
|
var CustomPhoneInput = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(
|
|
1349
1349
|
"input",
|
|
1350
1350
|
{
|
|
@@ -1365,6 +1365,8 @@ var PhoneInput = ({
|
|
|
1365
1365
|
}) => {
|
|
1366
1366
|
const colors = useThemeColors();
|
|
1367
1367
|
const [defaultCountry, setDefaultCountry] = useState("US");
|
|
1368
|
+
const [PhoneInputComponent, setPhoneInputComponent] = useState(null);
|
|
1369
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
1368
1370
|
const styleContent = useMemo(() => `
|
|
1369
1371
|
.PhoneInput {
|
|
1370
1372
|
display: flex;
|
|
@@ -1477,6 +1479,29 @@ var PhoneInput = ({
|
|
|
1477
1479
|
opacity: 0.6;
|
|
1478
1480
|
}
|
|
1479
1481
|
`, [colors]);
|
|
1482
|
+
useEffect(() => {
|
|
1483
|
+
let mounted = true;
|
|
1484
|
+
const loadPhoneInput = async () => {
|
|
1485
|
+
try {
|
|
1486
|
+
const module = await import('react-phone-number-input');
|
|
1487
|
+
if (mounted) {
|
|
1488
|
+
setPhoneInputComponent(() => module.default);
|
|
1489
|
+
}
|
|
1490
|
+
} catch (error) {
|
|
1491
|
+
if (mounted) {
|
|
1492
|
+
setPhoneInputComponent(null);
|
|
1493
|
+
}
|
|
1494
|
+
} finally {
|
|
1495
|
+
if (mounted) {
|
|
1496
|
+
setIsLoading(false);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
loadPhoneInput();
|
|
1501
|
+
return () => {
|
|
1502
|
+
mounted = false;
|
|
1503
|
+
};
|
|
1504
|
+
}, []);
|
|
1480
1505
|
useEffect(() => {
|
|
1481
1506
|
const detectCountry = async () => {
|
|
1482
1507
|
try {
|
|
@@ -1529,7 +1554,6 @@ var PhoneInput = ({
|
|
|
1529
1554
|
}
|
|
1530
1555
|
}
|
|
1531
1556
|
} catch (error) {
|
|
1532
|
-
console.log("Country detection failed, using default US");
|
|
1533
1557
|
}
|
|
1534
1558
|
};
|
|
1535
1559
|
detectCountry();
|
|
@@ -1537,7 +1561,31 @@ var PhoneInput = ({
|
|
|
1537
1561
|
const handleChange = useMemo(() => (val) => {
|
|
1538
1562
|
onChange(val || "");
|
|
1539
1563
|
}, [onChange]);
|
|
1540
|
-
if (
|
|
1564
|
+
if (isLoading) {
|
|
1565
|
+
return /* @__PURE__ */ jsx(
|
|
1566
|
+
"input",
|
|
1567
|
+
{
|
|
1568
|
+
id,
|
|
1569
|
+
type: "tel",
|
|
1570
|
+
value,
|
|
1571
|
+
onChange: (e) => onChange(e.target.value),
|
|
1572
|
+
disabled,
|
|
1573
|
+
required,
|
|
1574
|
+
placeholder,
|
|
1575
|
+
style: {
|
|
1576
|
+
width: "100%",
|
|
1577
|
+
padding: "12px 16px",
|
|
1578
|
+
border: `1px solid ${colors.borderSecondary}`,
|
|
1579
|
+
borderRadius: "8px",
|
|
1580
|
+
fontSize: "16px",
|
|
1581
|
+
backgroundColor: colors.bgSecondary,
|
|
1582
|
+
color: colors.textPrimary,
|
|
1583
|
+
...style
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
if (!PhoneInputComponent) {
|
|
1541
1589
|
return /* @__PURE__ */ jsx(
|
|
1542
1590
|
"input",
|
|
1543
1591
|
{
|
|
@@ -1571,7 +1619,7 @@ var PhoneInput = ({
|
|
|
1571
1619
|
children: [
|
|
1572
1620
|
/* @__PURE__ */ jsx("style", { children: styleContent }),
|
|
1573
1621
|
/* @__PURE__ */ jsx(
|
|
1574
|
-
|
|
1622
|
+
PhoneInputComponent,
|
|
1575
1623
|
{
|
|
1576
1624
|
id,
|
|
1577
1625
|
international: true,
|
|
@@ -2069,6 +2117,28 @@ var RegisterForm = ({
|
|
|
2069
2117
|
const [error, setError] = useState(null);
|
|
2070
2118
|
const [showPassword, setShowPassword] = useState(false);
|
|
2071
2119
|
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
|
2120
|
+
const [invitationDetails, setInvitationDetails] = useState(null);
|
|
2121
|
+
const [isLoadingInvitation, setIsLoadingInvitation] = useState(false);
|
|
2122
|
+
const config = authConfig || {
|
|
2123
|
+
baseUrl: "http://localhost:7000"
|
|
2124
|
+
};
|
|
2125
|
+
useEffect(() => {
|
|
2126
|
+
if (invitationToken) {
|
|
2127
|
+
setIsLoadingInvitation(true);
|
|
2128
|
+
fetch(`${config.baseUrl}/api/v1/auth/verify-invitation/${invitationToken}`).then((res) => res.json()).then((data) => {
|
|
2129
|
+
setInvitationDetails(data);
|
|
2130
|
+
if (data.valid && data.email) {
|
|
2131
|
+
setEmail(data.email);
|
|
2132
|
+
}
|
|
2133
|
+
}).catch((err) => {
|
|
2134
|
+
console.error("Failed to verify invitation:", err);
|
|
2135
|
+
setError("Failed to verify invitation. Please try again.");
|
|
2136
|
+
}).finally(() => {
|
|
2137
|
+
setIsLoadingInvitation(false);
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
}, [invitationToken, config.baseUrl]);
|
|
2141
|
+
const isEmailDisabled = isLoading || invitationDetails?.valid && !!invitationDetails?.email;
|
|
2072
2142
|
const getPasswordStrength = (pwd) => {
|
|
2073
2143
|
if (!pwd) return { strength: "weak", score: 0, label: "" };
|
|
2074
2144
|
let score = 0;
|
|
@@ -2082,9 +2152,6 @@ var RegisterForm = ({
|
|
|
2082
2152
|
return { strength: "strong", score, label: "Strong" };
|
|
2083
2153
|
};
|
|
2084
2154
|
getPasswordStrength(password);
|
|
2085
|
-
const config = authConfig || {
|
|
2086
|
-
baseUrl: "http://localhost:7000"
|
|
2087
|
-
};
|
|
2088
2155
|
const { register } = useAuth(config);
|
|
2089
2156
|
const handleSubmit = async (e) => {
|
|
2090
2157
|
e.preventDefault();
|
|
@@ -2119,6 +2186,25 @@ var RegisterForm = ({
|
|
|
2119
2186
|
if (response.ok && data.success) {
|
|
2120
2187
|
if (typeof window !== "undefined" && data.token) {
|
|
2121
2188
|
localStorage.setItem("auth_token", data.token);
|
|
2189
|
+
if (data.invitation?.organizationId && data.invitation?.role) {
|
|
2190
|
+
localStorage.setItem("currentOrganizationId", data.invitation.organizationId);
|
|
2191
|
+
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";
|
|
2192
|
+
try {
|
|
2193
|
+
await fetch(`${backendUrl}/api/auth/sync-with-role`, {
|
|
2194
|
+
method: "POST",
|
|
2195
|
+
headers: {
|
|
2196
|
+
"Content-Type": "application/json",
|
|
2197
|
+
"Authorization": `Bearer ${data.token}`
|
|
2198
|
+
},
|
|
2199
|
+
body: JSON.stringify({
|
|
2200
|
+
organizationId: data.invitation.organizationId,
|
|
2201
|
+
roleName: data.invitation.role
|
|
2202
|
+
})
|
|
2203
|
+
});
|
|
2204
|
+
} catch (syncError) {
|
|
2205
|
+
console.error("Failed to sync user role with backend:", syncError);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2122
2208
|
}
|
|
2123
2209
|
onRegisterSuccess?.();
|
|
2124
2210
|
} else {
|
|
@@ -2226,7 +2312,7 @@ var RegisterForm = ({
|
|
|
2226
2312
|
value: email,
|
|
2227
2313
|
onChange: (e) => setEmail(e.target.value),
|
|
2228
2314
|
required: !phoneNumber,
|
|
2229
|
-
disabled:
|
|
2315
|
+
disabled: isEmailDisabled,
|
|
2230
2316
|
style: {
|
|
2231
2317
|
width: "100%",
|
|
2232
2318
|
padding: "12px 16px",
|
|
@@ -2234,9 +2320,11 @@ var RegisterForm = ({
|
|
|
2234
2320
|
borderRadius: "8px",
|
|
2235
2321
|
fontSize: "16px",
|
|
2236
2322
|
boxSizing: "border-box",
|
|
2237
|
-
color: colors.textPrimary,
|
|
2323
|
+
color: isEmailDisabled ? colors.textSecondary : colors.textPrimary,
|
|
2238
2324
|
transition: "all 0.2s ease",
|
|
2239
|
-
backgroundColor: colors.bgSecondary
|
|
2325
|
+
backgroundColor: isEmailDisabled ? colors.bgHover : colors.bgSecondary,
|
|
2326
|
+
cursor: isEmailDisabled ? "not-allowed" : "text",
|
|
2327
|
+
opacity: isEmailDisabled ? 0.7 : 1
|
|
2240
2328
|
},
|
|
2241
2329
|
placeholder: "Enter your email"
|
|
2242
2330
|
}
|
|
@@ -2939,7 +3027,7 @@ var EmailVerificationPage = ({
|
|
|
2939
3027
|
} })
|
|
2940
3028
|
] }) });
|
|
2941
3029
|
}
|
|
2942
|
-
return /* @__PURE__ */
|
|
3030
|
+
return /* @__PURE__ */ jsxs("div", { style: {
|
|
2943
3031
|
maxWidth: "500px",
|
|
2944
3032
|
margin: "0 auto",
|
|
2945
3033
|
padding: "30px",
|
|
@@ -2948,44 +3036,86 @@ var EmailVerificationPage = ({
|
|
|
2948
3036
|
backgroundColor: "#ffffff",
|
|
2949
3037
|
textAlign: "center",
|
|
2950
3038
|
border: "1px solid #eaeaea"
|
|
2951
|
-
}, children: /* @__PURE__ */ jsxs("div", { style: {
|
|
2952
|
-
padding: "20px"
|
|
2953
3039
|
}, children: [
|
|
2954
|
-
/* @__PURE__ */
|
|
2955
|
-
|
|
2956
|
-
padding: "16px 20px",
|
|
2957
|
-
margin: "24px 0",
|
|
2958
|
-
borderRadius: "8px",
|
|
2959
|
-
fontSize: "15px",
|
|
2960
|
-
fontWeight: 500,
|
|
2961
|
-
backgroundColor: isSuccess ? "#d4edda" : "#f8d7da",
|
|
2962
|
-
color: isSuccess ? "#155724" : "#721c24",
|
|
2963
|
-
border: isSuccess ? "1px solid #c3e6cb" : "1px solid #f5c6cb"
|
|
2964
|
-
}, children: message }),
|
|
2965
|
-
isSuccess && /* @__PURE__ */ jsxs("div", { style: {
|
|
2966
|
-
marginTop: "24px"
|
|
3040
|
+
/* @__PURE__ */ jsxs("div", { style: {
|
|
3041
|
+
padding: "20px"
|
|
2967
3042
|
}, children: [
|
|
2968
|
-
/* @__PURE__ */ jsx("
|
|
2969
|
-
/* @__PURE__ */ jsx(
|
|
2970
|
-
"
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
3043
|
+
/* @__PURE__ */ jsx("h2", { style: { color: "black" }, children: isSuccess ? "\u2713 Email Verified!" : "\u2717 Verification Failed" }),
|
|
3044
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
3045
|
+
padding: "16px 20px",
|
|
3046
|
+
margin: "24px 0",
|
|
3047
|
+
borderRadius: "8px",
|
|
3048
|
+
fontSize: "15px",
|
|
3049
|
+
fontWeight: 500,
|
|
3050
|
+
backgroundColor: isSuccess ? "#d4edda" : "#f8d7da",
|
|
3051
|
+
color: isSuccess ? "#155724" : "#721c24",
|
|
3052
|
+
border: isSuccess ? "1px solid #c3e6cb" : "1px solid #f5c6cb"
|
|
3053
|
+
}, children: message }),
|
|
3054
|
+
isSuccess ? /* @__PURE__ */ jsxs("div", { style: { marginTop: "24px" }, children: [
|
|
3055
|
+
/* @__PURE__ */ jsx("p", { style: { color: "#666", marginBottom: "16px" }, children: "Redirecting to login..." }),
|
|
3056
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
3057
|
+
border: "3px solid #d4edda",
|
|
3058
|
+
borderTop: "3px solid #28a745",
|
|
3059
|
+
borderRadius: "50%",
|
|
3060
|
+
width: "30px",
|
|
3061
|
+
height: "30px",
|
|
3062
|
+
animation: "spin 1s linear infinite",
|
|
3063
|
+
margin: "0 auto"
|
|
3064
|
+
} })
|
|
3065
|
+
] }) : /* @__PURE__ */ jsxs("div", { style: { marginTop: "24px" }, children: [
|
|
3066
|
+
/* @__PURE__ */ jsx("p", { style: { color: "#666", marginBottom: "16px" }, children: "The verification link may have expired or already been used." }),
|
|
3067
|
+
/* @__PURE__ */ jsx(
|
|
3068
|
+
"button",
|
|
3069
|
+
{
|
|
3070
|
+
onClick: () => {
|
|
3071
|
+
const registerPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_TO_REGISTER || "/auth/register";
|
|
3072
|
+
window.location.href = registerPath;
|
|
3073
|
+
},
|
|
3074
|
+
style: {
|
|
3075
|
+
padding: "12px 24px",
|
|
3076
|
+
backgroundColor: "#007bff",
|
|
3077
|
+
color: "white",
|
|
3078
|
+
border: "none",
|
|
3079
|
+
borderRadius: "8px",
|
|
3080
|
+
fontSize: "16px",
|
|
3081
|
+
fontWeight: 600,
|
|
3082
|
+
cursor: "pointer",
|
|
3083
|
+
transition: "all 0.2s ease",
|
|
3084
|
+
marginRight: "12px"
|
|
3085
|
+
},
|
|
3086
|
+
children: "Register Again"
|
|
3087
|
+
}
|
|
3088
|
+
),
|
|
3089
|
+
/* @__PURE__ */ jsx(
|
|
3090
|
+
"button",
|
|
3091
|
+
{
|
|
3092
|
+
onClick: () => {
|
|
3093
|
+
const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
3094
|
+
window.location.href = loginPath;
|
|
3095
|
+
},
|
|
3096
|
+
style: {
|
|
3097
|
+
padding: "12px 24px",
|
|
3098
|
+
backgroundColor: "#6c757d",
|
|
3099
|
+
color: "white",
|
|
3100
|
+
border: "none",
|
|
3101
|
+
borderRadius: "8px",
|
|
3102
|
+
fontSize: "16px",
|
|
3103
|
+
fontWeight: 600,
|
|
3104
|
+
cursor: "pointer",
|
|
3105
|
+
transition: "all 0.2s ease"
|
|
3106
|
+
},
|
|
3107
|
+
children: "Go to Login"
|
|
3108
|
+
}
|
|
3109
|
+
)
|
|
3110
|
+
] })
|
|
3111
|
+
] }),
|
|
3112
|
+
/* @__PURE__ */ jsx("style", { children: `
|
|
3113
|
+
@keyframes spin {
|
|
3114
|
+
0% { transform: rotate(0deg); }
|
|
3115
|
+
100% { transform: rotate(360deg); }
|
|
2985
3116
|
}
|
|
2986
|
-
)
|
|
2987
|
-
|
|
2988
|
-
] }) });
|
|
3117
|
+
` })
|
|
3118
|
+
] });
|
|
2989
3119
|
};
|
|
2990
3120
|
var ThemeWrapper = forwardRef(
|
|
2991
3121
|
({ children, className = "", style }, ref) => {
|
|
@@ -5196,6 +5326,274 @@ var UserProfile = ({
|
|
|
5196
5326
|
] })
|
|
5197
5327
|
] });
|
|
5198
5328
|
};
|
|
5329
|
+
var SuperAdminSignIn = ({ redirectUrl, appearance }) => {
|
|
5330
|
+
const { signIn, isSignedIn, loading: authLoading, user } = useAuth2();
|
|
5331
|
+
const colors = useThemeColors();
|
|
5332
|
+
const [email, setEmail] = useState("");
|
|
5333
|
+
const [password, setPassword] = useState("");
|
|
5334
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
5335
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
5336
|
+
const [error, setError] = useState(null);
|
|
5337
|
+
const [success, setSuccess] = useState(null);
|
|
5338
|
+
useEffect(() => {
|
|
5339
|
+
if (isSignedIn && user) {
|
|
5340
|
+
const isSuperAdmin = user.role === "SUPER_ADMIN" || user.role === "SUPERADMIN";
|
|
5341
|
+
if (isSuperAdmin) {
|
|
5342
|
+
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
5343
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
5344
|
+
window.location.href = `${baseUrl}${redirect}`;
|
|
5345
|
+
} else {
|
|
5346
|
+
setError("Access denied. Only Super Admin users can access this portal.");
|
|
5347
|
+
document.cookie = "auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
5348
|
+
document.cookie = "refresh_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
}, [isSignedIn, user, redirectUrl]);
|
|
5352
|
+
const handleSubmit = async (e) => {
|
|
5353
|
+
e.preventDefault();
|
|
5354
|
+
setIsLoading(true);
|
|
5355
|
+
setError(null);
|
|
5356
|
+
setSuccess(null);
|
|
5357
|
+
try {
|
|
5358
|
+
const response = await signIn({ email, password });
|
|
5359
|
+
if (response.success) {
|
|
5360
|
+
const userRole = response.user?.role;
|
|
5361
|
+
const isSuperAdmin = userRole === "SUPER_ADMIN" || userRole === "SUPERADMIN";
|
|
5362
|
+
if (!isSuperAdmin) {
|
|
5363
|
+
document.cookie = "auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
5364
|
+
document.cookie = "refresh_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
5365
|
+
setError("Access denied. Only Super Admin users can access this portal.");
|
|
5366
|
+
return;
|
|
5367
|
+
}
|
|
5368
|
+
setSuccess("Login successful! Redirecting...");
|
|
5369
|
+
} else {
|
|
5370
|
+
setError(response.message || "Login failed. Please check your credentials.");
|
|
5371
|
+
}
|
|
5372
|
+
} catch (err) {
|
|
5373
|
+
setError(err instanceof Error ? err.message : "An error occurred during login.");
|
|
5374
|
+
} finally {
|
|
5375
|
+
setIsLoading(false);
|
|
5376
|
+
}
|
|
5377
|
+
};
|
|
5378
|
+
if (authLoading) {
|
|
5379
|
+
return /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsx("div", { children: "Loading..." }) });
|
|
5380
|
+
}
|
|
5381
|
+
return /* @__PURE__ */ jsx(
|
|
5382
|
+
ThemeWrapper,
|
|
5383
|
+
{
|
|
5384
|
+
style: {
|
|
5385
|
+
maxWidth: "400px",
|
|
5386
|
+
margin: "0 auto",
|
|
5387
|
+
padding: "30px",
|
|
5388
|
+
borderRadius: "12px",
|
|
5389
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
5390
|
+
backgroundColor: colors.bgPrimary,
|
|
5391
|
+
border: `1px solid ${colors.borderPrimary}`,
|
|
5392
|
+
...appearance?.elements?.card
|
|
5393
|
+
},
|
|
5394
|
+
children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, children: [
|
|
5395
|
+
/* @__PURE__ */ jsxs("div", { style: { textAlign: "center", marginBottom: "24px" }, children: [
|
|
5396
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
5397
|
+
width: "60px",
|
|
5398
|
+
height: "60px",
|
|
5399
|
+
margin: "0 auto 16px",
|
|
5400
|
+
backgroundColor: colors.buttonPrimary + "20",
|
|
5401
|
+
borderRadius: "12px",
|
|
5402
|
+
display: "flex",
|
|
5403
|
+
alignItems: "center",
|
|
5404
|
+
justifyContent: "center"
|
|
5405
|
+
}, children: /* @__PURE__ */ jsxs("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: colors.buttonPrimary, strokeWidth: "2", children: [
|
|
5406
|
+
/* @__PURE__ */ jsx("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" }),
|
|
5407
|
+
/* @__PURE__ */ jsx("path", { d: "M9 12l2 2 4-4" })
|
|
5408
|
+
] }) }),
|
|
5409
|
+
/* @__PURE__ */ jsx("h2", { style: {
|
|
5410
|
+
color: colors.textPrimary,
|
|
5411
|
+
fontSize: "24px",
|
|
5412
|
+
fontWeight: 600,
|
|
5413
|
+
margin: 0,
|
|
5414
|
+
...appearance?.elements?.headerTitle
|
|
5415
|
+
}, children: "Super Admin Portal" }),
|
|
5416
|
+
/* @__PURE__ */ jsx("p", { style: {
|
|
5417
|
+
color: colors.textSecondary,
|
|
5418
|
+
fontSize: "14px",
|
|
5419
|
+
marginTop: "8px"
|
|
5420
|
+
}, children: "Sign in with your administrator credentials" })
|
|
5421
|
+
] }),
|
|
5422
|
+
error && /* @__PURE__ */ jsx("div", { style: {
|
|
5423
|
+
padding: "12px 16px",
|
|
5424
|
+
marginBottom: "20px",
|
|
5425
|
+
backgroundColor: colors.errorBg,
|
|
5426
|
+
color: colors.errorText,
|
|
5427
|
+
border: `1px solid ${colors.errorBorder}`,
|
|
5428
|
+
borderRadius: "8px",
|
|
5429
|
+
fontSize: "14px"
|
|
5430
|
+
}, children: error }),
|
|
5431
|
+
success && /* @__PURE__ */ jsx("div", { style: {
|
|
5432
|
+
padding: "12px 16px",
|
|
5433
|
+
marginBottom: "20px",
|
|
5434
|
+
backgroundColor: colors.successBg,
|
|
5435
|
+
color: colors.successText,
|
|
5436
|
+
border: `1px solid ${colors.successBorder}`,
|
|
5437
|
+
borderRadius: "8px",
|
|
5438
|
+
fontSize: "14px"
|
|
5439
|
+
}, children: success }),
|
|
5440
|
+
/* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
5441
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "email", style: {
|
|
5442
|
+
display: "block",
|
|
5443
|
+
marginBottom: "8px",
|
|
5444
|
+
fontWeight: 500,
|
|
5445
|
+
color: colors.textSecondary,
|
|
5446
|
+
fontSize: "14px"
|
|
5447
|
+
}, children: "Email Address" }),
|
|
5448
|
+
/* @__PURE__ */ jsx(
|
|
5449
|
+
"input",
|
|
5450
|
+
{
|
|
5451
|
+
id: "email",
|
|
5452
|
+
type: "email",
|
|
5453
|
+
value: email,
|
|
5454
|
+
onChange: (e) => setEmail(e.target.value),
|
|
5455
|
+
onFocus: (e) => {
|
|
5456
|
+
e.currentTarget.style.borderColor = colors.buttonPrimary;
|
|
5457
|
+
e.currentTarget.style.outline = `2px solid ${colors.buttonPrimary}40`;
|
|
5458
|
+
},
|
|
5459
|
+
onBlur: (e) => {
|
|
5460
|
+
e.currentTarget.style.borderColor = colors.borderSecondary;
|
|
5461
|
+
e.currentTarget.style.outline = "none";
|
|
5462
|
+
},
|
|
5463
|
+
required: true,
|
|
5464
|
+
disabled: isLoading,
|
|
5465
|
+
autoComplete: "email",
|
|
5466
|
+
style: {
|
|
5467
|
+
width: "100%",
|
|
5468
|
+
padding: "12px 16px",
|
|
5469
|
+
border: `1px solid ${colors.borderSecondary}`,
|
|
5470
|
+
borderRadius: "8px",
|
|
5471
|
+
fontSize: "16px",
|
|
5472
|
+
boxSizing: "border-box",
|
|
5473
|
+
backgroundColor: colors.bgSecondary,
|
|
5474
|
+
color: colors.textPrimary,
|
|
5475
|
+
transition: "all 0.2s ease",
|
|
5476
|
+
WebkitTextFillColor: colors.textPrimary,
|
|
5477
|
+
WebkitBoxShadow: `0 0 0 1000px ${colors.bgSecondary} inset`,
|
|
5478
|
+
...appearance?.elements?.formFieldInput
|
|
5479
|
+
},
|
|
5480
|
+
placeholder: "admin@example.com"
|
|
5481
|
+
}
|
|
5482
|
+
)
|
|
5483
|
+
] }),
|
|
5484
|
+
/* @__PURE__ */ jsxs("div", { style: { marginBottom: "24px", position: "relative" }, children: [
|
|
5485
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "password", style: {
|
|
5486
|
+
display: "block",
|
|
5487
|
+
marginBottom: "8px",
|
|
5488
|
+
fontWeight: 500,
|
|
5489
|
+
color: colors.textSecondary,
|
|
5490
|
+
fontSize: "14px"
|
|
5491
|
+
}, children: "Password" }),
|
|
5492
|
+
/* @__PURE__ */ jsx(
|
|
5493
|
+
"input",
|
|
5494
|
+
{
|
|
5495
|
+
id: "password",
|
|
5496
|
+
type: showPassword ? "text" : "password",
|
|
5497
|
+
value: password,
|
|
5498
|
+
onChange: (e) => setPassword(e.target.value),
|
|
5499
|
+
onFocus: (e) => {
|
|
5500
|
+
e.currentTarget.style.borderColor = colors.buttonPrimary;
|
|
5501
|
+
e.currentTarget.style.outline = `2px solid ${colors.buttonPrimary}40`;
|
|
5502
|
+
},
|
|
5503
|
+
onBlur: (e) => {
|
|
5504
|
+
e.currentTarget.style.borderColor = colors.borderSecondary;
|
|
5505
|
+
e.currentTarget.style.outline = "none";
|
|
5506
|
+
},
|
|
5507
|
+
required: true,
|
|
5508
|
+
disabled: isLoading,
|
|
5509
|
+
autoComplete: "current-password",
|
|
5510
|
+
style: {
|
|
5511
|
+
width: "100%",
|
|
5512
|
+
padding: "12px 16px",
|
|
5513
|
+
paddingRight: "60px",
|
|
5514
|
+
border: `1px solid ${colors.borderSecondary}`,
|
|
5515
|
+
borderRadius: "8px",
|
|
5516
|
+
fontSize: "16px",
|
|
5517
|
+
boxSizing: "border-box",
|
|
5518
|
+
backgroundColor: colors.bgSecondary,
|
|
5519
|
+
color: colors.textPrimary,
|
|
5520
|
+
transition: "all 0.2s ease",
|
|
5521
|
+
WebkitTextFillColor: colors.textPrimary,
|
|
5522
|
+
WebkitBoxShadow: `0 0 0 1000px ${colors.bgSecondary} inset`,
|
|
5523
|
+
...appearance?.elements?.formFieldInput
|
|
5524
|
+
},
|
|
5525
|
+
placeholder: "Enter your password"
|
|
5526
|
+
}
|
|
5527
|
+
),
|
|
5528
|
+
/* @__PURE__ */ jsx(
|
|
5529
|
+
"button",
|
|
5530
|
+
{
|
|
5531
|
+
type: "button",
|
|
5532
|
+
onClick: () => setShowPassword(!showPassword),
|
|
5533
|
+
style: {
|
|
5534
|
+
position: "absolute",
|
|
5535
|
+
right: "12px",
|
|
5536
|
+
top: "38px",
|
|
5537
|
+
background: "none",
|
|
5538
|
+
border: "none",
|
|
5539
|
+
cursor: "pointer",
|
|
5540
|
+
color: colors.textTertiary,
|
|
5541
|
+
fontSize: "14px",
|
|
5542
|
+
padding: "4px 8px"
|
|
5543
|
+
},
|
|
5544
|
+
children: showPassword ? "Hide" : "Show"
|
|
5545
|
+
}
|
|
5546
|
+
)
|
|
5547
|
+
] }),
|
|
5548
|
+
/* @__PURE__ */ jsx(
|
|
5549
|
+
"button",
|
|
5550
|
+
{
|
|
5551
|
+
type: "submit",
|
|
5552
|
+
disabled: isLoading || !email || !password,
|
|
5553
|
+
onMouseEnter: (e) => {
|
|
5554
|
+
if (!isLoading && email && password) {
|
|
5555
|
+
e.currentTarget.style.backgroundColor = colors.buttonPrimaryHover;
|
|
5556
|
+
}
|
|
5557
|
+
},
|
|
5558
|
+
onMouseLeave: (e) => {
|
|
5559
|
+
e.currentTarget.style.backgroundColor = colors.buttonPrimary;
|
|
5560
|
+
},
|
|
5561
|
+
style: {
|
|
5562
|
+
width: "100%",
|
|
5563
|
+
padding: "14px",
|
|
5564
|
+
backgroundColor: colors.buttonPrimary,
|
|
5565
|
+
color: "white",
|
|
5566
|
+
border: "none",
|
|
5567
|
+
borderRadius: "8px",
|
|
5568
|
+
fontSize: "16px",
|
|
5569
|
+
fontWeight: 600,
|
|
5570
|
+
cursor: isLoading || !email || !password ? "not-allowed" : "pointer",
|
|
5571
|
+
opacity: isLoading || !email || !password ? 0.6 : 1,
|
|
5572
|
+
transition: "all 0.2s ease",
|
|
5573
|
+
...appearance?.elements?.formButtonPrimary
|
|
5574
|
+
},
|
|
5575
|
+
children: isLoading ? "Signing in..." : "Sign In"
|
|
5576
|
+
}
|
|
5577
|
+
),
|
|
5578
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
5579
|
+
marginTop: "20px",
|
|
5580
|
+
padding: "12px",
|
|
5581
|
+
backgroundColor: colors.bgSecondary,
|
|
5582
|
+
borderRadius: "8px",
|
|
5583
|
+
textAlign: "center"
|
|
5584
|
+
}, children: /* @__PURE__ */ jsxs("p", { style: {
|
|
5585
|
+
color: colors.textTertiary,
|
|
5586
|
+
fontSize: "12px",
|
|
5587
|
+
margin: 0
|
|
5588
|
+
}, children: [
|
|
5589
|
+
"\u{1F512} This portal is restricted to Super Admin users only.",
|
|
5590
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
5591
|
+
"Contact your system administrator if you need access."
|
|
5592
|
+
] }) })
|
|
5593
|
+
] })
|
|
5594
|
+
}
|
|
5595
|
+
);
|
|
5596
|
+
};
|
|
5199
5597
|
var AvatarManager = ({
|
|
5200
5598
|
open,
|
|
5201
5599
|
onOpenChange,
|
|
@@ -5469,6 +5867,6 @@ var useNextAuth = (config) => {
|
|
|
5469
5867
|
};
|
|
5470
5868
|
};
|
|
5471
5869
|
|
|
5472
|
-
export { AuthFlow, AuthProvider, AuthService, AuthThemeProvider, AvatarManager, AvatarUploader, ChangePassword, EmailVerificationPage, ForgotPassword, HttpClient, LoginForm, OtpForm, PhoneInput, ProtectedRoute, PublicRoute, RegisterForm, ResetPassword, SignIn, SignOut, SignUp, UserButton, UserProfile, VerifyEmail, useAuth2 as useAuth, useAuth as useAuthLegacy, useAuthTheme, useNextAuth };
|
|
5870
|
+
export { AuthFlow, AuthProvider, AuthService, AuthThemeProvider, AvatarManager, AvatarUploader, ChangePassword, EmailVerificationPage, ForgotPassword, HttpClient, LoginForm, OtpForm, PhoneInput, ProtectedRoute, PublicRoute, RegisterForm, ResetPassword, SignIn, SignOut, SignUp, SuperAdminSignIn, UserButton, UserProfile, VerifyEmail, useAuth2 as useAuth, useAuth as useAuthLegacy, useAuthTheme, useNextAuth };
|
|
5473
5871
|
//# sourceMappingURL=index.next.mjs.map
|
|
5474
5872
|
//# sourceMappingURL=index.next.mjs.map
|