@pubflow/core 0.4.3 → 0.4.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/auth/service.js +16 -5
- package/package.json +1 -1
package/dist/auth/service.js
CHANGED
|
@@ -49,18 +49,29 @@ class AuthService {
|
|
|
49
49
|
console.log('AuthService.login: Login successful, storing session data');
|
|
50
50
|
}
|
|
51
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 }
|
|
52
|
+
// Normalize snake_case → camelCase for 2FA fields returned by the backend.
|
|
53
|
+
// Backend: { success:false, requires_2fa:true, session_id, available_methods, user }
|
|
55
54
|
if (data.requires_2fa) {
|
|
55
|
+
const partialSessionId = (_b = data.session_id) !== null && _b !== void 0 ? _b : data.sessionId;
|
|
56
|
+
// Store the partial session so ApiClient can attach it on
|
|
57
|
+
// subsequent /auth/two_factor/:method/start and /verify calls.
|
|
58
|
+
if (partialSessionId) {
|
|
59
|
+
await this.storage.setItem(this.sessionKey, partialSessionId);
|
|
60
|
+
}
|
|
61
|
+
// The 2FA login response already includes safe user data.
|
|
62
|
+
// Store it now so getCurrentUser() returns the real user after OTP verify —
|
|
63
|
+
// no extra API call to /me or /validation needed.
|
|
64
|
+
if (data.user) {
|
|
65
|
+
await this.storeUserData(data.user);
|
|
66
|
+
}
|
|
56
67
|
return {
|
|
57
68
|
success: true,
|
|
58
69
|
requires2fa: true,
|
|
59
|
-
sessionId:
|
|
70
|
+
sessionId: partialSessionId,
|
|
60
71
|
availableMethods: (_d = (_c = data.available_methods) !== null && _c !== void 0 ? _c : data.availableMethods) !== null && _d !== void 0 ? _d : [],
|
|
61
72
|
};
|
|
62
73
|
}
|
|
63
|
-
// Normal login — store session ID and user data
|
|
74
|
+
// Normal (non-2FA) login — store session ID and user data
|
|
64
75
|
if ((_e = data.session_id) !== null && _e !== void 0 ? _e : data.sessionId) {
|
|
65
76
|
await this.storage.setItem(this.sessionKey, (_f = data.session_id) !== null && _f !== void 0 ? _f : data.sessionId);
|
|
66
77
|
}
|