@ollaid/native-sso 2.1.2 → 2.1.5

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.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * } />
10
10
  * ```
11
11
  *
12
- * @version 1.0.0
12
+ * @version 2.1.4
13
13
  */
14
14
  export { NativeSSOPage } from './components/NativeSSOPage';
15
15
  export type { NativeSSOPageProps } from './components/NativeSSOPage';
package/dist/index.js CHANGED
@@ -2527,17 +2527,11 @@ function LoginModal({
2527
2527
  setPhone(initialPhone);
2528
2528
  }
2529
2529
  }, [open, initialPhone]);
2530
- const exchangeCallbackToken = async (callbackToken) => {
2531
- try {
2532
- const response = await nativeAuthService.exchange(callbackToken);
2533
- if (response.success && response.token) {
2534
- setLoginData({ token: response.token, user: response.user });
2535
- setLoginSuccess(true);
2536
- } else {
2537
- setLocalError("Erreur lors de la finalisation de la connexion");
2538
- }
2539
- } catch {
2540
- setLocalError("Erreur de connexion au serveur");
2530
+ const finalizeLogin = (result) => {
2531
+ if (result.success && result.user) {
2532
+ const token = localStorage.getItem("native_auth_token") || localStorage.getItem("auth_token") || "";
2533
+ setLoginData({ token, user: result.user });
2534
+ setLoginSuccess(true);
2541
2535
  }
2542
2536
  };
2543
2537
  const handleEmailCheck = async () => {
@@ -2567,7 +2561,7 @@ function LoginModal({
2567
2561
  return;
2568
2562
  }
2569
2563
  const result = await submitPassword(password);
2570
- if (result.success && result.callback_token) await exchangeCallbackToken(result.callback_token);
2564
+ finalizeLogin(result);
2571
2565
  };
2572
2566
  const handleEmailOtpVerify = async () => {
2573
2567
  setLocalError(null);
@@ -2577,7 +2571,7 @@ function LoginModal({
2577
2571
  return;
2578
2572
  }
2579
2573
  const result = await submitOtp(emailOtpCode);
2580
- if (result.success && result.callback_token) await exchangeCallbackToken(result.callback_token);
2574
+ finalizeLogin(result);
2581
2575
  };
2582
2576
  const handlePhoneInit = async () => {
2583
2577
  setLocalError(null);
@@ -2597,7 +2591,7 @@ function LoginModal({
2597
2591
  return;
2598
2592
  }
2599
2593
  const result = await submitOtp(phoneOtpCode);
2600
- if (result.success && result.callback_token) await exchangeCallbackToken(result.callback_token);
2594
+ finalizeLogin(result);
2601
2595
  };
2602
2596
  const handleAccessOtpSubmit = async () => {
2603
2597
  setLocalError(null);
@@ -2607,17 +2601,13 @@ function LoginModal({
2607
2601
  return;
2608
2602
  }
2609
2603
  const result = await loginWithAccessOtp(accessOtpCode);
2610
- if (result.success) {
2611
- if (result.callback_token) {
2612
- await exchangeCallbackToken(result.callback_token);
2613
- }
2614
- }
2604
+ finalizeLogin(result);
2615
2605
  };
2616
2606
  const handleGrantAccess = async () => {
2617
2607
  setLocalError(null);
2618
2608
  clearError();
2619
2609
  const result = await grantAccess();
2620
- if (result.success && result.callback_token) await exchangeCallbackToken(result.callback_token);
2610
+ finalizeLogin(result);
2621
2611
  };
2622
2612
  const handleResendOTP = async () => {
2623
2613
  if (resendCooldown > 0) return;