@pubflow/core 0.4.2 → 0.4.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.
@@ -37,7 +37,7 @@ class AuthService {
37
37
  * @returns Login result
38
38
  */
39
39
  async login(credentials) {
40
- var _a;
40
+ var _a, _b, _c, _d, _e, _f;
41
41
  if (DEBUG_AUTH) {
42
42
  console.log('AuthService.login: Starting login process');
43
43
  }
@@ -48,13 +48,30 @@ class AuthService {
48
48
  if (DEBUG_AUTH) {
49
49
  console.log('AuthService.login: Login successful, storing session data');
50
50
  }
51
- // Store session ID and user data
52
- if (response.data.sessionId) {
53
- await this.storage.setItem(this.sessionKey, response.data.sessionId);
51
+ const data = response.data;
52
+ // Normalize snake_case → camelCase for 2FA fields returned by the backend
53
+ // Backend: { requires_2fa, session_id, available_methods }
54
+ // Client expects: { requires2fa, sessionId, availableMethods }
55
+ if (data.requires_2fa) {
56
+ const partialSessionId = (_b = data.session_id) !== null && _b !== void 0 ? _b : data.sessionId;
57
+ // ← CRITICAL: store the partial session so ApiClient can attach it
58
+ // to subsequent /auth/two_factor/:method/start calls.
59
+ if (partialSessionId) {
60
+ await this.storage.setItem(this.sessionKey, partialSessionId);
61
+ }
62
+ return {
63
+ success: true,
64
+ requires2fa: true,
65
+ sessionId: partialSessionId,
66
+ availableMethods: (_d = (_c = data.available_methods) !== null && _c !== void 0 ? _c : data.availableMethods) !== null && _d !== void 0 ? _d : [],
67
+ };
54
68
  }
55
- if (response.data.user) {
56
- // Store user data preserving ALL original fields exactly as received
57
- await this.storeUserData(response.data.user);
69
+ // Normal login — store session ID and user data
70
+ if ((_e = data.session_id) !== null && _e !== void 0 ? _e : data.sessionId) {
71
+ await this.storage.setItem(this.sessionKey, (_f = data.session_id) !== null && _f !== void 0 ? _f : data.sessionId);
72
+ }
73
+ if (data.user) {
74
+ await this.storeUserData(data.user);
58
75
  }
59
76
  return response.data;
60
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubflow/core",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Core functionality for Pubflow framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",