@ollaid/native-sso 1.0.0 → 1.0.3
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 +232 -8
- package/dist/components/AppsLogoSlider.d.ts +2 -1
- package/dist/components/LoginModal.d.ts +3 -2
- package/dist/components/NativeSSOPage.d.ts +8 -3
- package/dist/components/PasswordRecoveryModal.d.ts +1 -2
- package/dist/components/SignupModal.d.ts +3 -2
- package/dist/hooks/useMobilePassword.d.ts +0 -1
- package/dist/hooks/useMobileRegistration.d.ts +0 -1
- package/dist/hooks/useNativeAuth.d.ts +73 -6
- package/dist/index.cjs +119 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +119 -48
- package/dist/index.js.map +1 -1
- package/dist/services/api.d.ts +9 -1
- package/dist/services/nativeAuth.d.ts +4 -0
- package/dist/types/native.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -454,7 +454,8 @@ let config = {
|
|
|
454
454
|
saasApiUrl: "",
|
|
455
455
|
iamApiUrl: "",
|
|
456
456
|
timeout: 3e4,
|
|
457
|
-
debug: false
|
|
457
|
+
debug: false,
|
|
458
|
+
configPrefix: "iam"
|
|
458
459
|
};
|
|
459
460
|
const setNativeAuthConfig = (newConfig) => {
|
|
460
461
|
config = { ...config, ...newConfig };
|
|
@@ -481,7 +482,8 @@ const STORAGE = {
|
|
|
481
482
|
AUTH_TOKEN: "auth_token",
|
|
482
483
|
TOKEN: "token",
|
|
483
484
|
USER: "user",
|
|
484
|
-
ACCOUNT_TYPE: "account_type"
|
|
485
|
+
ACCOUNT_TYPE: "account_type",
|
|
486
|
+
ALIAS_REFERENCE: "alias_reference"
|
|
485
487
|
};
|
|
486
488
|
const setAuthToken = (token) => {
|
|
487
489
|
if (typeof localStorage !== "undefined") {
|
|
@@ -499,6 +501,7 @@ const clearAuthToken = () => {
|
|
|
499
501
|
localStorage.removeItem(STORAGE.TOKEN);
|
|
500
502
|
localStorage.removeItem(STORAGE.USER);
|
|
501
503
|
localStorage.removeItem(STORAGE.ACCOUNT_TYPE);
|
|
504
|
+
localStorage.removeItem(STORAGE.ALIAS_REFERENCE);
|
|
502
505
|
}
|
|
503
506
|
};
|
|
504
507
|
const setAuthUser = (user) => {
|
|
@@ -572,7 +575,7 @@ async function fetchWithTimeout(url, options, timeout) {
|
|
|
572
575
|
throw new ApiError("Erreur inattendue", "unknown");
|
|
573
576
|
}
|
|
574
577
|
}
|
|
575
|
-
function getHeaders(token) {
|
|
578
|
+
function getHeaders(token, includeConfigPrefix = false) {
|
|
576
579
|
const headers = {
|
|
577
580
|
"Content-Type": "application/json",
|
|
578
581
|
"Accept": "application/json"
|
|
@@ -581,12 +584,19 @@ function getHeaders(token) {
|
|
|
581
584
|
if (deviceId) {
|
|
582
585
|
headers["X-Device-Id"] = deviceId;
|
|
583
586
|
}
|
|
587
|
+
if (includeConfigPrefix && config.configPrefix) {
|
|
588
|
+
headers["X-IAM-Config-Prefix"] = config.configPrefix;
|
|
589
|
+
}
|
|
584
590
|
if (token) {
|
|
585
591
|
headers["Authorization"] = `Bearer ${token}`;
|
|
586
592
|
}
|
|
587
593
|
return headers;
|
|
588
594
|
}
|
|
589
595
|
let credentials = null;
|
|
596
|
+
let credentialsLoadedAt = 0;
|
|
597
|
+
let credentialsTtl = 300;
|
|
598
|
+
const DEFAULT_TTL = 300;
|
|
599
|
+
const REFRESH_MARGIN = 30;
|
|
590
600
|
const nativeAuthService = {
|
|
591
601
|
hasCredentials() {
|
|
592
602
|
return credentials !== null;
|
|
@@ -594,6 +604,26 @@ const nativeAuthService = {
|
|
|
594
604
|
getCredentials() {
|
|
595
605
|
return credentials ? { ...credentials } : null;
|
|
596
606
|
},
|
|
607
|
+
getCredentialsTtl() {
|
|
608
|
+
return credentialsTtl;
|
|
609
|
+
},
|
|
610
|
+
getCredentialsAge() {
|
|
611
|
+
if (!credentialsLoadedAt) return Infinity;
|
|
612
|
+
return (Date.now() - credentialsLoadedAt) / 1e3;
|
|
613
|
+
},
|
|
614
|
+
areCredentialsExpiringSoon() {
|
|
615
|
+
if (!credentials || !credentialsLoadedAt) return true;
|
|
616
|
+
const age = this.getCredentialsAge();
|
|
617
|
+
return age >= credentialsTtl - REFRESH_MARGIN;
|
|
618
|
+
},
|
|
619
|
+
async ensureFreshCredentials() {
|
|
620
|
+
if (!credentials || this.areCredentialsExpiringSoon()) {
|
|
621
|
+
if (isDebugMode()) {
|
|
622
|
+
console.log("🔄 [Native] Credentials expirés ou proches — auto-refresh");
|
|
623
|
+
}
|
|
624
|
+
await this.loadCredentials();
|
|
625
|
+
}
|
|
626
|
+
},
|
|
597
627
|
async loadCredentials() {
|
|
598
628
|
const config2 = getNativeAuthConfig();
|
|
599
629
|
if (!config2.saasApiUrl) {
|
|
@@ -604,7 +634,7 @@ const nativeAuthService = {
|
|
|
604
634
|
}
|
|
605
635
|
const response = await fetchWithTimeout(
|
|
606
636
|
`${config2.saasApiUrl}/native/config`,
|
|
607
|
-
{ method: "GET", headers: getHeaders() },
|
|
637
|
+
{ method: "GET", headers: getHeaders(void 0, true) },
|
|
608
638
|
config2.timeout || 3e4
|
|
609
639
|
);
|
|
610
640
|
if (!response.success || !response.encrypted_credentials || !response.app_key) {
|
|
@@ -614,6 +644,8 @@ const nativeAuthService = {
|
|
|
614
644
|
appKey: response.app_key,
|
|
615
645
|
encryptedCredentials: response.encrypted_credentials
|
|
616
646
|
};
|
|
647
|
+
credentialsLoadedAt = Date.now();
|
|
648
|
+
credentialsTtl = response.credentials_ttl || DEFAULT_TTL;
|
|
617
649
|
if (typeof response.debug === "boolean") {
|
|
618
650
|
const currentConfig = getNativeAuthConfig();
|
|
619
651
|
if (currentConfig.debug !== true) {
|
|
@@ -621,11 +653,12 @@ const nativeAuthService = {
|
|
|
621
653
|
}
|
|
622
654
|
}
|
|
623
655
|
if (isDebugMode()) {
|
|
624
|
-
console.log("✅ [SaaS] Credentials chargés (debug:", response.debug ?? "non défini", ")");
|
|
656
|
+
console.log("✅ [SaaS] Credentials chargés (ttl:", credentialsTtl, "s, debug:", response.debug ?? "non défini", ")");
|
|
625
657
|
}
|
|
626
658
|
return credentials;
|
|
627
659
|
},
|
|
628
660
|
async encrypt(type, data) {
|
|
661
|
+
await this.ensureFreshCredentials();
|
|
629
662
|
if (!credentials) {
|
|
630
663
|
throw new ApiError("Credentials non chargés. Appelez loadCredentials() d'abord.", "auth");
|
|
631
664
|
}
|
|
@@ -776,7 +809,7 @@ const nativeAuthService = {
|
|
|
776
809
|
`${config2.saasApiUrl}/native/exchange`,
|
|
777
810
|
{
|
|
778
811
|
method: "POST",
|
|
779
|
-
headers: getHeaders(),
|
|
812
|
+
headers: getHeaders(void 0, true),
|
|
780
813
|
body: JSON.stringify({ callback_token: callbackToken })
|
|
781
814
|
},
|
|
782
815
|
config2.timeout || 3e4
|
|
@@ -805,7 +838,7 @@ const nativeAuthService = {
|
|
|
805
838
|
`${cfg.saasApiUrl}/native/check-token`,
|
|
806
839
|
{
|
|
807
840
|
method: "POST",
|
|
808
|
-
headers: getHeaders(token)
|
|
841
|
+
headers: getHeaders(token, true)
|
|
809
842
|
},
|
|
810
843
|
1e4
|
|
811
844
|
);
|
|
@@ -827,21 +860,24 @@ const nativeAuthService = {
|
|
|
827
860
|
`${config2.saasApiUrl}/native/logout`,
|
|
828
861
|
{
|
|
829
862
|
method: "POST",
|
|
830
|
-
headers: getHeaders(token)
|
|
863
|
+
headers: getHeaders(token, true)
|
|
831
864
|
},
|
|
832
865
|
config2.timeout || 3e4
|
|
833
866
|
);
|
|
834
867
|
clearAuthToken();
|
|
835
868
|
credentials = null;
|
|
869
|
+
credentialsLoadedAt = 0;
|
|
836
870
|
return response;
|
|
837
871
|
} catch {
|
|
838
872
|
clearAuthToken();
|
|
839
873
|
credentials = null;
|
|
874
|
+
credentialsLoadedAt = 0;
|
|
840
875
|
return { success: true };
|
|
841
876
|
}
|
|
842
877
|
},
|
|
843
878
|
clearCredentials() {
|
|
844
879
|
credentials = null;
|
|
880
|
+
credentialsLoadedAt = 0;
|
|
845
881
|
},
|
|
846
882
|
// ============================================
|
|
847
883
|
// High-level methods
|
|
@@ -1024,14 +1060,14 @@ function getErrorMessage$2(err, context) {
|
|
|
1024
1060
|
return { message: `Erreur lors de ${context}`, type: "unknown" };
|
|
1025
1061
|
}
|
|
1026
1062
|
function useMobilePassword(options) {
|
|
1027
|
-
const { saasApiUrl, iamApiUrl, autoLoadCredentials = true
|
|
1063
|
+
const { saasApiUrl, iamApiUrl, autoLoadCredentials = true } = options;
|
|
1028
1064
|
const configuredRef = react.useRef(false);
|
|
1029
1065
|
react.useEffect(() => {
|
|
1030
1066
|
if (!configuredRef.current) {
|
|
1031
|
-
setNativeAuthConfig({ saasApiUrl, iamApiUrl
|
|
1067
|
+
setNativeAuthConfig({ saasApiUrl, iamApiUrl });
|
|
1032
1068
|
configuredRef.current = true;
|
|
1033
1069
|
}
|
|
1034
|
-
}, [saasApiUrl, iamApiUrl
|
|
1070
|
+
}, [saasApiUrl, iamApiUrl]);
|
|
1035
1071
|
const [state, setState] = react.useState({
|
|
1036
1072
|
credentialsLoaded: false,
|
|
1037
1073
|
processToken: null,
|
|
@@ -1267,7 +1303,7 @@ const backBtnStyle$2 = {
|
|
|
1267
1303
|
color: C$3.gray700,
|
|
1268
1304
|
zIndex: 10
|
|
1269
1305
|
};
|
|
1270
|
-
function PasswordRecoveryModal({ open, onOpenChange, onSuccess, saasApiUrl, iamApiUrl
|
|
1306
|
+
function PasswordRecoveryModal({ open, onOpenChange, onSuccess, saasApiUrl, iamApiUrl }) {
|
|
1271
1307
|
const {
|
|
1272
1308
|
status,
|
|
1273
1309
|
loading: pwLoading,
|
|
@@ -1282,7 +1318,7 @@ function PasswordRecoveryModal({ open, onOpenChange, onSuccess, saasApiUrl, iamA
|
|
|
1282
1318
|
resendOtp,
|
|
1283
1319
|
reset: resetHook,
|
|
1284
1320
|
clearError
|
|
1285
|
-
} = useMobilePassword({ saasApiUrl, iamApiUrl
|
|
1321
|
+
} = useMobilePassword({ saasApiUrl, iamApiUrl });
|
|
1286
1322
|
const [step, setStep] = react.useState("email");
|
|
1287
1323
|
const [email, setEmail] = react.useState("");
|
|
1288
1324
|
const [otp, setOtp] = react.useState("");
|
|
@@ -1569,11 +1605,22 @@ function useTokenHealthCheck(options) {
|
|
|
1569
1605
|
}, [enabled, saasApiUrl, performCheck, debug]);
|
|
1570
1606
|
}
|
|
1571
1607
|
function saveSession(exchangeResult, accountType) {
|
|
1608
|
+
var _a, _b;
|
|
1572
1609
|
const sanctumToken = exchangeResult.auth_token || exchangeResult.token;
|
|
1573
1610
|
localStorage.setItem(STORAGE.AUTH_TOKEN, sanctumToken);
|
|
1574
1611
|
localStorage.setItem(STORAGE.TOKEN, sanctumToken);
|
|
1575
|
-
const
|
|
1576
|
-
const
|
|
1612
|
+
const baseUser = exchangeResult.user_infos ? { ...exchangeResult.user, ...exchangeResult.user_infos } : exchangeResult.user;
|
|
1613
|
+
const aliasRef = ((_a = exchangeResult.user) == null ? void 0 : _a.alias_reference) || exchangeResult.alias_reference || "";
|
|
1614
|
+
const iamRef = ((_b = exchangeResult.user) == null ? void 0 : _b.reference) || "";
|
|
1615
|
+
const userToStore = {
|
|
1616
|
+
...baseUser,
|
|
1617
|
+
iam_reference: iamRef,
|
|
1618
|
+
alias_reference: aliasRef
|
|
1619
|
+
};
|
|
1620
|
+
if (aliasRef) {
|
|
1621
|
+
localStorage.setItem(STORAGE.ALIAS_REFERENCE, aliasRef);
|
|
1622
|
+
}
|
|
1623
|
+
const acctType = typeof accountType === "string" ? accountType : "user";
|
|
1577
1624
|
localStorage.setItem(STORAGE.USER, JSON.stringify(userToStore));
|
|
1578
1625
|
localStorage.setItem(STORAGE.ACCOUNT_TYPE, acctType);
|
|
1579
1626
|
return { token: sanctumToken, user: userToStore };
|
|
@@ -1583,6 +1630,7 @@ function clearSession() {
|
|
|
1583
1630
|
localStorage.removeItem(STORAGE.TOKEN);
|
|
1584
1631
|
localStorage.removeItem(STORAGE.USER);
|
|
1585
1632
|
localStorage.removeItem(STORAGE.ACCOUNT_TYPE);
|
|
1633
|
+
localStorage.removeItem(STORAGE.ALIAS_REFERENCE);
|
|
1586
1634
|
}
|
|
1587
1635
|
function getErrorMessage$1(err, context) {
|
|
1588
1636
|
if (err instanceof Error) {
|
|
@@ -1597,14 +1645,15 @@ function getErrorMessage$1(err, context) {
|
|
|
1597
1645
|
return { message: `Erreur lors de ${context}`, type: "unknown" };
|
|
1598
1646
|
}
|
|
1599
1647
|
function useNativeAuth(options) {
|
|
1600
|
-
const { saasApiUrl, iamApiUrl, autoLoadCredentials = true,
|
|
1648
|
+
const { saasApiUrl, iamApiUrl, autoLoadCredentials = true, defaultAccountType = "user", configPrefix = "iam" } = options;
|
|
1601
1649
|
const configuredRef = react.useRef(false);
|
|
1650
|
+
const [isDebug, setIsDebug] = react.useState(isDebugMode());
|
|
1602
1651
|
react.useEffect(() => {
|
|
1603
1652
|
if (!configuredRef.current) {
|
|
1604
|
-
setNativeAuthConfig({ saasApiUrl, iamApiUrl,
|
|
1653
|
+
setNativeAuthConfig({ saasApiUrl, iamApiUrl, configPrefix });
|
|
1605
1654
|
configuredRef.current = true;
|
|
1606
1655
|
}
|
|
1607
|
-
}, [saasApiUrl, iamApiUrl,
|
|
1656
|
+
}, [saasApiUrl, iamApiUrl, configPrefix]);
|
|
1608
1657
|
const [state, setState] = react.useState({
|
|
1609
1658
|
credentialsLoaded: false,
|
|
1610
1659
|
processToken: null,
|
|
@@ -1622,7 +1671,7 @@ function useNativeAuth(options) {
|
|
|
1622
1671
|
});
|
|
1623
1672
|
const [accountType, setAccountType] = react.useState("email");
|
|
1624
1673
|
const handleTokenInvalid = react.useCallback(() => {
|
|
1625
|
-
if (
|
|
1674
|
+
if (isDebug) console.log("🔐 [HealthCheck] Token invalide — déconnexion locale");
|
|
1626
1675
|
clearSession();
|
|
1627
1676
|
setState({
|
|
1628
1677
|
credentialsLoaded: false,
|
|
@@ -1639,7 +1688,7 @@ function useNativeAuth(options) {
|
|
|
1639
1688
|
otpMethod: null,
|
|
1640
1689
|
otpSentTo: null
|
|
1641
1690
|
});
|
|
1642
|
-
}, [
|
|
1691
|
+
}, [isDebug]);
|
|
1643
1692
|
const handleUserUpdated = react.useCallback((userInfos) => {
|
|
1644
1693
|
const storedRaw = localStorage.getItem(STORAGE.USER);
|
|
1645
1694
|
if (storedRaw) {
|
|
@@ -1657,7 +1706,7 @@ function useNativeAuth(options) {
|
|
|
1657
1706
|
saasApiUrl,
|
|
1658
1707
|
onTokenInvalid: handleTokenInvalid,
|
|
1659
1708
|
onUserUpdated: handleUserUpdated,
|
|
1660
|
-
debug
|
|
1709
|
+
debug: isDebug
|
|
1661
1710
|
});
|
|
1662
1711
|
react.useEffect(() => {
|
|
1663
1712
|
const storedToken = localStorage.getItem(STORAGE.AUTH_TOKEN) || localStorage.getItem(STORAGE.TOKEN);
|
|
@@ -1676,10 +1725,29 @@ function useNativeAuth(options) {
|
|
|
1676
1725
|
loadCredentials();
|
|
1677
1726
|
}
|
|
1678
1727
|
}, [autoLoadCredentials, state.credentialsLoaded, state.user]);
|
|
1728
|
+
react.useEffect(() => {
|
|
1729
|
+
if (state.status === "completed" || !state.credentialsLoaded) return;
|
|
1730
|
+
const ttl = nativeAuthService.getCredentialsTtl();
|
|
1731
|
+
const refreshInterval = Math.max((ttl - 30) * 1e3, 3e4);
|
|
1732
|
+
if (isDebug) {
|
|
1733
|
+
console.log(`🔄 [Native] Auto-refresh credentials every ${refreshInterval / 1e3}s (TTL: ${ttl}s)`);
|
|
1734
|
+
}
|
|
1735
|
+
const timer = setInterval(async () => {
|
|
1736
|
+
try {
|
|
1737
|
+
await nativeAuthService.loadCredentials();
|
|
1738
|
+
setIsDebug(isDebugMode());
|
|
1739
|
+
if (isDebugMode()) console.log("✅ [Native] Credentials auto-refreshed");
|
|
1740
|
+
} catch (err) {
|
|
1741
|
+
if (isDebugMode()) console.warn("⚠️ [Native] Auto-refresh failed:", err);
|
|
1742
|
+
}
|
|
1743
|
+
}, refreshInterval);
|
|
1744
|
+
return () => clearInterval(timer);
|
|
1745
|
+
}, [state.status, state.credentialsLoaded, isDebug]);
|
|
1679
1746
|
const loadCredentials = react.useCallback(async () => {
|
|
1680
1747
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
1681
1748
|
try {
|
|
1682
1749
|
await nativeAuthService.loadCredentials();
|
|
1750
|
+
setIsDebug(isDebugMode());
|
|
1683
1751
|
setState((prev) => ({ ...prev, credentialsLoaded: true, loading: false }));
|
|
1684
1752
|
return { success: true };
|
|
1685
1753
|
} catch (err) {
|
|
@@ -1903,7 +1971,7 @@ function useNativeAuth(options) {
|
|
|
1903
1971
|
if (response.success && response.callback_token) {
|
|
1904
1972
|
const exchangeResult = await nativeAuthService.exchange(response.callback_token);
|
|
1905
1973
|
if (exchangeResult.success) {
|
|
1906
|
-
const { user: savedUser } = saveSession(exchangeResult,
|
|
1974
|
+
const { user: savedUser } = saveSession(exchangeResult, defaultAccountType);
|
|
1907
1975
|
setState((prev) => ({
|
|
1908
1976
|
...prev,
|
|
1909
1977
|
status: "completed",
|
|
@@ -1964,7 +2032,7 @@ function useNativeAuth(options) {
|
|
|
1964
2032
|
if (response.success && response.callback_token) {
|
|
1965
2033
|
const exchangeResult = await nativeAuthService.exchange(response.callback_token);
|
|
1966
2034
|
if (exchangeResult.success) {
|
|
1967
|
-
const { user: savedUser } = saveSession(exchangeResult,
|
|
2035
|
+
const { user: savedUser } = saveSession(exchangeResult, defaultAccountType);
|
|
1968
2036
|
setState((prev) => ({
|
|
1969
2037
|
...prev,
|
|
1970
2038
|
status: "completed",
|
|
@@ -2025,7 +2093,7 @@ function useNativeAuth(options) {
|
|
|
2025
2093
|
if (response.success && response.callback_token) {
|
|
2026
2094
|
const exchangeResult = await nativeAuthService.exchange(response.callback_token);
|
|
2027
2095
|
if (exchangeResult.success) {
|
|
2028
|
-
const { user: savedUser } = saveSession(exchangeResult,
|
|
2096
|
+
const { user: savedUser } = saveSession(exchangeResult, defaultAccountType);
|
|
2029
2097
|
setState((prev) => ({
|
|
2030
2098
|
...prev,
|
|
2031
2099
|
status: "completed",
|
|
@@ -2059,7 +2127,7 @@ function useNativeAuth(options) {
|
|
|
2059
2127
|
if (response.success && response.callback_token) {
|
|
2060
2128
|
const exchangeResult = await nativeAuthService.exchange(response.callback_token);
|
|
2061
2129
|
if (exchangeResult.success) {
|
|
2062
|
-
const { user: savedUser } = saveSession(exchangeResult,
|
|
2130
|
+
const { user: savedUser } = saveSession(exchangeResult, defaultAccountType);
|
|
2063
2131
|
setState((prev) => ({
|
|
2064
2132
|
...prev,
|
|
2065
2133
|
status: "completed",
|
|
@@ -2104,14 +2172,14 @@ function useNativeAuth(options) {
|
|
|
2104
2172
|
}
|
|
2105
2173
|
}, [state.processToken]);
|
|
2106
2174
|
const setSession = react.useCallback((data) => {
|
|
2107
|
-
const { user: savedUser } = saveSession(data,
|
|
2175
|
+
const { user: savedUser } = saveSession(data, defaultAccountType);
|
|
2108
2176
|
setState((prev) => ({
|
|
2109
2177
|
...prev,
|
|
2110
2178
|
user: savedUser,
|
|
2111
2179
|
status: "completed",
|
|
2112
2180
|
processToken: null
|
|
2113
2181
|
}));
|
|
2114
|
-
}, [
|
|
2182
|
+
}, [defaultAccountType]);
|
|
2115
2183
|
const logout = react.useCallback(async () => {
|
|
2116
2184
|
const token = localStorage.getItem(STORAGE.AUTH_TOKEN) || localStorage.getItem(STORAGE.TOKEN);
|
|
2117
2185
|
try {
|
|
@@ -2167,6 +2235,8 @@ function useNativeAuth(options) {
|
|
|
2167
2235
|
error: state.error,
|
|
2168
2236
|
errorType: state.errorType,
|
|
2169
2237
|
isAuthenticated: state.status === "completed" && state.user !== null,
|
|
2238
|
+
/** Debug réactif — mis à jour après loadCredentials */
|
|
2239
|
+
isDebug,
|
|
2170
2240
|
accountType,
|
|
2171
2241
|
isPhoneOnly: accountType === "phone-only",
|
|
2172
2242
|
otpMethod: state.otpMethod,
|
|
@@ -2271,7 +2341,7 @@ function LoginModal({
|
|
|
2271
2341
|
iamApiUrl,
|
|
2272
2342
|
loading,
|
|
2273
2343
|
showSwitchToSignup = true,
|
|
2274
|
-
|
|
2344
|
+
defaultAccountType
|
|
2275
2345
|
}) {
|
|
2276
2346
|
const {
|
|
2277
2347
|
status,
|
|
@@ -2290,7 +2360,7 @@ function LoginModal({
|
|
|
2290
2360
|
setSession,
|
|
2291
2361
|
reset: resetAuth,
|
|
2292
2362
|
clearError
|
|
2293
|
-
} = useNativeAuth({ saasApiUrl, iamApiUrl,
|
|
2363
|
+
} = useNativeAuth({ saasApiUrl, iamApiUrl, defaultAccountType });
|
|
2294
2364
|
const [step, setStep] = react.useState("choice");
|
|
2295
2365
|
const [email, setEmail] = react.useState("");
|
|
2296
2366
|
const [password, setPassword] = react.useState("");
|
|
@@ -2799,8 +2869,7 @@ function LoginModal({
|
|
|
2799
2869
|
onOpenChange: setShowPasswordRecovery,
|
|
2800
2870
|
onSuccess: () => setShowPasswordRecovery(false),
|
|
2801
2871
|
saasApiUrl,
|
|
2802
|
-
iamApiUrl
|
|
2803
|
-
debug
|
|
2872
|
+
iamApiUrl
|
|
2804
2873
|
}
|
|
2805
2874
|
)
|
|
2806
2875
|
] });
|
|
@@ -2885,17 +2954,18 @@ function PhoneInput({
|
|
|
2885
2954
|
] })
|
|
2886
2955
|
] });
|
|
2887
2956
|
}
|
|
2888
|
-
function AppsLogoSlider({ speed = "normal", className = "" }) {
|
|
2957
|
+
function AppsLogoSlider({ speed = "normal", className = "", iamApiUrl: iamApiUrlProp }) {
|
|
2889
2958
|
const scrollRef = react.useRef(null);
|
|
2890
2959
|
const [isPaused, setIsPaused] = react.useState(false);
|
|
2891
2960
|
const [applications, setApplications] = react.useState([]);
|
|
2892
2961
|
const [isLoading, setIsLoading] = react.useState(true);
|
|
2893
2962
|
const speedMap = { slow: 50, normal: 30, fast: 15 };
|
|
2894
2963
|
react.useEffect(() => {
|
|
2964
|
+
const resolvedIamApiUrl = iamApiUrlProp || getNativeAuthConfig().iamApiUrl;
|
|
2965
|
+
if (!resolvedIamApiUrl) return;
|
|
2895
2966
|
const fetchApps = async () => {
|
|
2896
2967
|
try {
|
|
2897
|
-
const
|
|
2898
|
-
const iamBaseUrl = config2.iamApiUrl.replace("/api", "");
|
|
2968
|
+
const iamBaseUrl = resolvedIamApiUrl.replace("/api", "");
|
|
2899
2969
|
const response = await fetch(`${iamBaseUrl}/api/public/applications`, { headers: { "Accept": "application/json" } });
|
|
2900
2970
|
if (response.ok) {
|
|
2901
2971
|
const data = await response.json();
|
|
@@ -2907,7 +2977,7 @@ function AppsLogoSlider({ speed = "normal", className = "" }) {
|
|
|
2907
2977
|
}
|
|
2908
2978
|
};
|
|
2909
2979
|
fetchApps();
|
|
2910
|
-
}, []);
|
|
2980
|
+
}, [iamApiUrlProp]);
|
|
2911
2981
|
react.useEffect(() => {
|
|
2912
2982
|
const container = scrollRef.current;
|
|
2913
2983
|
if (!container || applications.length === 0) return;
|
|
@@ -2924,8 +2994,8 @@ function AppsLogoSlider({ speed = "normal", className = "" }) {
|
|
|
2924
2994
|
const getLogoUrl = (logo) => {
|
|
2925
2995
|
if (!logo) return null;
|
|
2926
2996
|
if (logo.startsWith("http")) return logo;
|
|
2927
|
-
const
|
|
2928
|
-
return `${
|
|
2997
|
+
const resolvedUrl = iamApiUrlProp || getNativeAuthConfig().iamApiUrl;
|
|
2998
|
+
return `${resolvedUrl.replace("/api", "")}/storage/applications/${logo}`;
|
|
2929
2999
|
};
|
|
2930
3000
|
if (isLoading) {
|
|
2931
3001
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", gap: "1rem", padding: "0.5rem 0" }, children: [1, 2, 3, 4, 5].map((i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flexShrink: 0, display: "flex", flexDirection: "column", alignItems: "center", gap: "0.5rem" }, children: [
|
|
@@ -3058,8 +3128,7 @@ function useMobileRegistration(options) {
|
|
|
3058
3128
|
if (options && !configuredRef.current) {
|
|
3059
3129
|
setNativeAuthConfig({
|
|
3060
3130
|
saasApiUrl: options.saasApiUrl,
|
|
3061
|
-
iamApiUrl: options.iamApiUrl
|
|
3062
|
-
debug: options.debug
|
|
3131
|
+
iamApiUrl: options.iamApiUrl
|
|
3063
3132
|
});
|
|
3064
3133
|
configuredRef.current = true;
|
|
3065
3134
|
}
|
|
@@ -3358,7 +3427,7 @@ function SuccessOrbit() {
|
|
|
3358
3427
|
})
|
|
3359
3428
|
] });
|
|
3360
3429
|
}
|
|
3361
|
-
function SignupModal({ open, onOpenChange, onSwitchToLogin, onSignupSuccess, saasApiUrl, iamApiUrl,
|
|
3430
|
+
function SignupModal({ open, onOpenChange, onSwitchToLogin, onSignupSuccess, saasApiUrl, iamApiUrl, defaultAccountType }) {
|
|
3362
3431
|
const {
|
|
3363
3432
|
status,
|
|
3364
3433
|
formData,
|
|
@@ -3374,7 +3443,7 @@ function SignupModal({ open, onOpenChange, onSwitchToLogin, onSignupSuccess, saa
|
|
|
3374
3443
|
resendOtp,
|
|
3375
3444
|
reset: resetReg,
|
|
3376
3445
|
clearError
|
|
3377
|
-
} = useMobileRegistration({ saasApiUrl, iamApiUrl
|
|
3446
|
+
} = useMobileRegistration({ saasApiUrl, iamApiUrl });
|
|
3378
3447
|
const [step, setStep] = react.useState("intro");
|
|
3379
3448
|
const [otpCode, setOtpCode] = react.useState("");
|
|
3380
3449
|
const [password, setPassword] = react.useState("");
|
|
@@ -3521,7 +3590,7 @@ function SignupModal({ open, onOpenChange, onSwitchToLogin, onSignupSuccess, saa
|
|
|
3521
3590
|
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: "Ouvrez un compte Ollaid" }),
|
|
3522
3591
|
/* @__PURE__ */ jsxRuntime.jsx(DialogDescription, { children: "Un compte unique qui vous donne accès à toutes les applications" })
|
|
3523
3592
|
] }),
|
|
3524
|
-
/* @__PURE__ */ jsxRuntime.jsx(AppsLogoSlider, {}),
|
|
3593
|
+
/* @__PURE__ */ jsxRuntime.jsx(AppsLogoSlider, { iamApiUrl }),
|
|
3525
3594
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", flexDirection: "column", gap: "0.75rem", fontSize: "0.875rem", color: C$1.gray500, margin: "1rem 0" }, children: ["Un seul compte pour toutes les applications", "Plus besoin de multiples mots de passe", "Connexion simplifiée et sécurisée"].map((text) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "0.75rem" }, children: [
|
|
3526
3595
|
/* @__PURE__ */ jsxRuntime.jsx(IconCheckCircle2, { style: { width: "1.25rem", height: "1.25rem", color: C$1.green, flexShrink: 0 } }),
|
|
3527
3596
|
text
|
|
@@ -4075,7 +4144,8 @@ function NativeSSOPage({
|
|
|
4075
4144
|
onLoginSuccess,
|
|
4076
4145
|
onLogout,
|
|
4077
4146
|
onOnboardingComplete,
|
|
4078
|
-
|
|
4147
|
+
accountType = "user",
|
|
4148
|
+
configPrefix = "iam",
|
|
4079
4149
|
title = "Un compte, plusieurs accès",
|
|
4080
4150
|
description = "Connectez-vous avec votre compte Ollaid pour accéder à toutes les applications partenaires.",
|
|
4081
4151
|
logoUrl,
|
|
@@ -4093,7 +4163,7 @@ function NativeSSOPage({
|
|
|
4093
4163
|
}
|
|
4094
4164
|
return null;
|
|
4095
4165
|
});
|
|
4096
|
-
const resolvedDebug =
|
|
4166
|
+
const { isDebug: resolvedDebug } = useNativeAuth({ saasApiUrl, iamApiUrl, configPrefix, autoLoadCredentials: true });
|
|
4097
4167
|
react.useEffect(() => {
|
|
4098
4168
|
const root = document.documentElement;
|
|
4099
4169
|
const originalValues = {};
|
|
@@ -4172,6 +4242,7 @@ function NativeSSOPage({
|
|
|
4172
4242
|
localStorage.removeItem(STORAGE.TOKEN);
|
|
4173
4243
|
localStorage.removeItem(STORAGE.USER);
|
|
4174
4244
|
localStorage.removeItem(STORAGE.ACCOUNT_TYPE);
|
|
4245
|
+
localStorage.removeItem(STORAGE.ALIAS_REFERENCE);
|
|
4175
4246
|
setSession(null);
|
|
4176
4247
|
onLogout == null ? void 0 : onLogout();
|
|
4177
4248
|
}, [onLogout]);
|
|
@@ -4209,7 +4280,7 @@ function NativeSSOPage({
|
|
|
4209
4280
|
] }) });
|
|
4210
4281
|
if (session) {
|
|
4211
4282
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyle, children: [
|
|
4212
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: "100%", maxWidth: "28rem", marginBottom: "1.5rem" }, children: /* @__PURE__ */ jsxRuntime.jsx(AppsLogoSlider, {}) }),
|
|
4283
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: "100%", maxWidth: "28rem", marginBottom: "1.5rem" }, children: /* @__PURE__ */ jsxRuntime.jsx(AppsLogoSlider, { iamApiUrl }) }),
|
|
4213
4284
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: cardStyle, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { padding: "2rem 1.5rem 1.5rem" }, children: [
|
|
4214
4285
|
/* @__PURE__ */ jsxRuntime.jsx(BrandingHeader, {}),
|
|
4215
4286
|
/* @__PURE__ */ jsxRuntime.jsxs("h2", { style: { fontSize: "1.25rem", fontWeight: 600, textAlign: "center", color: COLORS.cardForeground }, children: [
|
|
@@ -4229,7 +4300,7 @@ function NativeSSOPage({
|
|
|
4229
4300
|
] });
|
|
4230
4301
|
}
|
|
4231
4302
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyle, children: [
|
|
4232
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: "100%", maxWidth: "28rem", marginBottom: "1.5rem" }, children: logoUrl ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: logoUrl, alt: "Logo", style: { height: "3rem", margin: "0 auto" } }) : /* @__PURE__ */ jsxRuntime.jsx(AppsLogoSlider, {}) }),
|
|
4303
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: "100%", maxWidth: "28rem", marginBottom: "1.5rem" }, children: logoUrl ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: logoUrl, alt: "Logo", style: { height: "3rem", margin: "0 auto" } }) : /* @__PURE__ */ jsxRuntime.jsx(AppsLogoSlider, { iamApiUrl }) }),
|
|
4233
4304
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: cardStyle, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { padding: "2rem 1.5rem 1.5rem" }, children: [
|
|
4234
4305
|
/* @__PURE__ */ jsxRuntime.jsx(BrandingHeader, {}),
|
|
4235
4306
|
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: { fontSize: "1.25rem", fontWeight: 600, textAlign: "center", color: COLORS.cardForeground, marginBottom: "0.5rem" }, children: title }),
|
|
@@ -4270,7 +4341,7 @@ function NativeSSOPage({
|
|
|
4270
4341
|
onLoginSuccess: handleLoginSuccess,
|
|
4271
4342
|
saasApiUrl,
|
|
4272
4343
|
iamApiUrl,
|
|
4273
|
-
|
|
4344
|
+
defaultAccountType: accountType
|
|
4274
4345
|
}
|
|
4275
4346
|
),
|
|
4276
4347
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4284,7 +4355,7 @@ function NativeSSOPage({
|
|
|
4284
4355
|
onSignupSuccess: handleLoginSuccess,
|
|
4285
4356
|
saasApiUrl,
|
|
4286
4357
|
iamApiUrl,
|
|
4287
|
-
|
|
4358
|
+
defaultAccountType: accountType
|
|
4288
4359
|
}
|
|
4289
4360
|
),
|
|
4290
4361
|
pendingSession && /* @__PURE__ */ jsxRuntime.jsx(
|