@ollaid/native-sso 2.7.3 → 2.7.4

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/dist/index.cjs CHANGED
@@ -7401,15 +7401,22 @@ const getAuthToken = () => {
7401
7401
  };
7402
7402
  const clearAuthToken = () => {
7403
7403
  const storage = getNativeStorage();
7404
- storage.removeItem(STORAGE.AUTH_TOKEN);
7405
- storage.removeItem(STORAGE.TOKEN);
7406
- storage.removeItem(STORAGE.USER);
7407
- storage.removeItem(STORAGE.ACCOUNT_TYPE);
7408
- storage.removeItem(STORAGE.ALIAS_REFERENCE);
7409
- storage.removeItem(STORAGE.APP_ACCESS_TOKEN_REF);
7410
- storage.removeItem(STORAGE.REFRESH_TOKEN);
7411
- storage.removeItem(STORAGE.TOKEN_EXPIRES_AT);
7412
- storage.removeItem(STORAGE.REFRESH_EXPIRES_AT);
7404
+ [
7405
+ STORAGE.AUTH_TOKEN,
7406
+ STORAGE.TOKEN,
7407
+ STORAGE.USER,
7408
+ STORAGE.ACCOUNT_TYPE,
7409
+ STORAGE.ALIAS_REFERENCE,
7410
+ STORAGE.APP_ACCESS_TOKEN_REF,
7411
+ STORAGE.REFRESH_TOKEN,
7412
+ STORAGE.TOKEN_EXPIRES_AT,
7413
+ STORAGE.REFRESH_EXPIRES_AT
7414
+ ].forEach((key) => {
7415
+ try {
7416
+ storage.removeItem(key);
7417
+ } catch {
7418
+ }
7419
+ });
7413
7420
  };
7414
7421
  const clearNativeSsoStorage = (options) => {
7415
7422
  const storage = getNativeStorage();
@@ -7418,30 +7425,44 @@ const clearNativeSsoStorage = (options) => {
7418
7425
  if (preserveDeviceIdentity && (key === DEVICE_ID_KEY || key === SESSION_UUID_KEY || key === STORAGE_SEED_KEY)) {
7419
7426
  return;
7420
7427
  }
7421
- storage.removeItem(key);
7428
+ try {
7429
+ storage.removeItem(key);
7430
+ } catch {
7431
+ }
7422
7432
  });
7423
7433
  };
7424
7434
  const repairNativeSsoStorage = () => {
7425
- const storage = getNativeStorage();
7426
- const authToken = getAuthToken();
7427
- const userRaw = storage.getItem(STORAGE.USER);
7428
- if (userRaw && !authToken) {
7429
- clearNativeSsoStorage();
7430
- return { cleaned: true, reason: "incomplete_session" };
7431
- }
7432
- if (authToken && !userRaw) {
7433
- clearNativeSsoStorage();
7434
- return { cleaned: true, reason: "incomplete_session" };
7435
- }
7436
- if (userRaw) {
7435
+ try {
7436
+ const storage = getNativeStorage();
7437
+ const authToken = getAuthToken();
7438
+ const userRaw = storage.getItem(STORAGE.USER);
7439
+ if (userRaw && !authToken) {
7440
+ clearNativeSsoStorage();
7441
+ return { cleaned: true, reason: "incomplete_session" };
7442
+ }
7443
+ if (authToken && !userRaw) {
7444
+ clearNativeSsoStorage();
7445
+ return { cleaned: true, reason: "incomplete_session" };
7446
+ }
7447
+ if (userRaw) {
7448
+ try {
7449
+ JSON.parse(userRaw);
7450
+ } catch {
7451
+ clearNativeSsoStorage();
7452
+ return { cleaned: true, reason: "invalid_user_json" };
7453
+ }
7454
+ }
7455
+ return { cleaned: false, reason: null };
7456
+ } catch (error) {
7457
+ if (isDebugMode()) {
7458
+ console.warn("⚠️ [native-sso] Storage repair failed, forcing cleanup", error);
7459
+ }
7437
7460
  try {
7438
- JSON.parse(userRaw);
7439
- } catch {
7440
7461
  clearNativeSsoStorage();
7441
- return { cleaned: true, reason: "invalid_user_json" };
7462
+ } catch {
7442
7463
  }
7464
+ return { cleaned: true, reason: "incomplete_session" };
7443
7465
  }
7444
- return { cleaned: false, reason: null };
7445
7466
  };
7446
7467
  const logout = async () => {
7447
7468
  const { nativeAuthService: nativeAuthService2 } = await Promise.resolve().then(() => nativeAuth);
@@ -8275,6 +8296,12 @@ function getErrorMessage$2(err, context) {
8275
8296
  function useMobilePassword(options) {
8276
8297
  const { saasApiUrl, iamApiUrl, autoLoadCredentials = true } = options;
8277
8298
  const configuredRef = react.useRef(false);
8299
+ react.useEffect(() => {
8300
+ const repairResult = repairNativeSsoStorage();
8301
+ if (repairResult.cleaned && isDebugMode()) {
8302
+ console.warn("🔧 [useMobilePassword] Storage SSO réparé", repairResult.reason);
8303
+ }
8304
+ }, []);
8278
8305
  react.useEffect(() => {
8279
8306
  if (!configuredRef.current) {
8280
8307
  setNativeAuthConfig({ saasApiUrl, iamApiUrl });
@@ -8920,6 +8947,12 @@ function useNativeAuth(options) {
8920
8947
  setNativeStorage(storage);
8921
8948
  }
8922
8949
  const configuredRef = react.useRef(false);
8950
+ react.useEffect(() => {
8951
+ const repairResult = repairNativeSsoStorage();
8952
+ if (repairResult.cleaned && isDebugMode()) {
8953
+ console.warn("🔧 [useNativeAuth] Storage SSO réparé", repairResult.reason);
8954
+ }
8955
+ }, []);
8923
8956
  const [isDebug, setIsDebug] = react.useState(isDebugMode());
8924
8957
  react.useEffect(() => {
8925
8958
  if (!configuredRef.current) {