@micha.bigler/ui-core-micha 1.3.4 → 1.3.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.
@@ -373,32 +373,33 @@ export async function authenticateWithMFA({ code, credential }) {
373
373
  // Authentication: password (MODIFIZIERT)
374
374
  // -----------------------------
375
375
  export async function loginWithPassword(email, password) {
376
- var _a, _b;
376
+ var _a, _b, _c;
377
377
  try {
378
378
  await axios.post(`${HEADLESS_BASE}/auth/login`, { email, password }, { withCredentials: true });
379
379
  }
380
380
  catch (error) {
381
381
  const status = (_a = error.response) === null || _a === void 0 ? void 0 : _a.status;
382
382
  const data = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data;
383
- // --- SKEPTISCHER CHECK: MFA NÖTIG? ---
384
- // Wenn Allauth 401 mit flow="mfa_authenticate" sendet, ist das KEIN Fehler,
385
- // sondern die Aufforderung für Schritt 2.
386
- if (status === 401 && (data === null || data === void 0 ? void 0 : data.flow) === 'mfa_authenticate') {
383
+ console.log('Login Error Debug:', { status, data });
384
+ // --- SKEPTISCHER CHECK (KORRIGIERT) ---
385
+ // Wir suchen in der Liste 'flows' nach einem Eintrag mit id='mfa_authenticate'
386
+ // und prüfen, ob er 'is_pending' ist.
387
+ const mfaFlow = (_c = data === null || data === void 0 ? void 0 : data.flows) === null || _c === void 0 ? void 0 : _c.find(f => f.id === 'mfa_authenticate');
388
+ if (status === 401 && mfaFlow && mfaFlow.is_pending) {
387
389
  return {
388
390
  needsMfa: true,
389
- availableTypes: data.types || [], // z.B. ["webauthn", "totp"]
391
+ availableTypes: mfaFlow.types || [], // ["recovery_codes", "webauthn"]
390
392
  };
391
393
  }
392
- // --- "Already Logged In" Handling ---
394
+ // --- Already Logged In ---
393
395
  if (status === 409) {
394
- // User ist schon eingeloggt, wir machen einfach weiter
396
+ // user ist schon eingeloggt
395
397
  }
396
398
  else {
397
- // Echter Fehler (z.B. falsches Passwort oder Serverfehler)
398
399
  throw new Error(extractErrorMessage(error));
399
400
  }
400
401
  }
401
- // Wenn wir hier landen, war der Login direkt erfolgreich (kein MFA)
402
+ // Erfolg ohne MFA
402
403
  const user = await fetchCurrentUser();
403
404
  return { user, needsMfa: false };
404
405
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "private": false,
@@ -495,26 +495,29 @@ export async function loginWithPassword(email, password) {
495
495
  const status = error.response?.status;
496
496
  const data = error.response?.data;
497
497
 
498
- // --- SKEPTISCHER CHECK: MFA NÖTIG? ---
499
- // Wenn Allauth 401 mit flow="mfa_authenticate" sendet, ist das KEIN Fehler,
500
- // sondern die Aufforderung für Schritt 2.
501
- if (status === 401 && data?.flow === 'mfa_authenticate') {
498
+ console.log('Login Error Debug:', { status, data });
499
+
500
+ // --- SKEPTISCHER CHECK (KORRIGIERT) ---
501
+ // Wir suchen in der Liste 'flows' nach einem Eintrag mit id='mfa_authenticate'
502
+ // und prüfen, ob er 'is_pending' ist.
503
+ const mfaFlow = data?.flows?.find(f => f.id === 'mfa_authenticate');
504
+
505
+ if (status === 401 && mfaFlow && mfaFlow.is_pending) {
502
506
  return {
503
507
  needsMfa: true,
504
- availableTypes: data.types || [], // z.B. ["webauthn", "totp"]
508
+ availableTypes: mfaFlow.types || [], // ["recovery_codes", "webauthn"]
505
509
  };
506
510
  }
507
511
 
508
- // --- "Already Logged In" Handling ---
512
+ // --- Already Logged In ---
509
513
  if (status === 409) {
510
- // User ist schon eingeloggt, wir machen einfach weiter
514
+ // user ist schon eingeloggt
511
515
  } else {
512
- // Echter Fehler (z.B. falsches Passwort oder Serverfehler)
513
516
  throw new Error(extractErrorMessage(error));
514
517
  }
515
518
  }
516
519
 
517
- // Wenn wir hier landen, war der Login direkt erfolgreich (kein MFA)
520
+ // Erfolg ohne MFA
518
521
  const user = await fetchCurrentUser();
519
522
  return { user, needsMfa: false };
520
523
  }