ecrs-auth-core 1.0.75 → 1.0.78
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.controller.d.ts +1 -1
- package/dist/auth.controller.js +31 -21
- package/dist/auth.service.js +2 -0
- package/package.json +1 -1
|
@@ -42,7 +42,7 @@ export declare class AuthController {
|
|
|
42
42
|
*/
|
|
43
43
|
private parseUserAgent;
|
|
44
44
|
/**
|
|
45
|
-
* Extract client IP from request
|
|
45
|
+
* Extract client IP from request and clean IPv6-mapped IPv4 format
|
|
46
46
|
* Priority:
|
|
47
47
|
* 1. X-Forwarded-For header (proxy)
|
|
48
48
|
* 2. X-Real-IP header (nginx)
|
package/dist/auth.controller.js
CHANGED
|
@@ -34,8 +34,12 @@ let AuthController = class AuthController {
|
|
|
34
34
|
console.log(`🔐 User validation result for ${body.email}: ${user ? 'Success' : 'Failed'}`);
|
|
35
35
|
if (!user) {
|
|
36
36
|
// Save failed login attempt to both tables
|
|
37
|
-
await this.authService.saveLastLogin({ email: body.email }, clientIp, 'failed', 'Invalid credentials or IP not allowed', additionalData).catch(() => {
|
|
38
|
-
|
|
37
|
+
await this.authService.saveLastLogin({ email: body.email }, clientIp, 'failed', 'Invalid credentials or IP not allowed', additionalData).catch((err) => {
|
|
38
|
+
console.error('❌ Error saving failed login to tbl_user_last_login:', err.message);
|
|
39
|
+
}); // Log errors for debugging
|
|
40
|
+
await this.authService.saveLoginDetailsJson({ email: body.email }, clientIp, 'failed', 'Invalid credentials or IP not allowed', additionalData).catch((err) => {
|
|
41
|
+
console.error('❌ Error saving failed login to tbl_user_login_details:', err.message);
|
|
42
|
+
}); // Log errors for debugging
|
|
39
43
|
throw new common_1.UnauthorizedException('Login failed: email or password not matched or IP not allowed');
|
|
40
44
|
}
|
|
41
45
|
const requestedModuleId = Number(body.moduleId);
|
|
@@ -56,12 +60,16 @@ let AuthController = class AuthController {
|
|
|
56
60
|
await this.authService.saveLastLogin(user, clientIp, 'success', undefined, {
|
|
57
61
|
...additionalData,
|
|
58
62
|
moduleId: requestedModuleId,
|
|
59
|
-
}).catch(() => {
|
|
63
|
+
}).catch((err) => {
|
|
64
|
+
console.error('❌ Error saving successful login to tbl_user_last_login:', err.message);
|
|
65
|
+
}); // Log errors for debugging
|
|
60
66
|
// Save to JSON-based login details table
|
|
61
67
|
await this.authService.saveLoginDetailsJson(user, clientIp, 'success', undefined, {
|
|
62
68
|
...additionalData,
|
|
63
69
|
moduleId: requestedModuleId,
|
|
64
|
-
}).catch(() => {
|
|
70
|
+
}).catch((err) => {
|
|
71
|
+
console.error('❌ Error saving successful login to tbl_user_login_details:', err.message);
|
|
72
|
+
}); // Log errors for debugging
|
|
65
73
|
return loginResponse;
|
|
66
74
|
}
|
|
67
75
|
/**
|
|
@@ -120,7 +128,7 @@ let AuthController = class AuthController {
|
|
|
120
128
|
return { browser, os, deviceType };
|
|
121
129
|
}
|
|
122
130
|
/**
|
|
123
|
-
* Extract client IP from request
|
|
131
|
+
* Extract client IP from request and clean IPv6-mapped IPv4 format
|
|
124
132
|
* Priority:
|
|
125
133
|
* 1. X-Forwarded-For header (proxy)
|
|
126
134
|
* 2. X-Real-IP header (nginx)
|
|
@@ -129,36 +137,38 @@ let AuthController = class AuthController {
|
|
|
129
137
|
* 5. socket.remoteAddress (direct connection)
|
|
130
138
|
*/
|
|
131
139
|
getClientIp(request) {
|
|
140
|
+
let ip = '';
|
|
132
141
|
// Check X-Forwarded-For header (most common with proxies)
|
|
133
142
|
const xForwardedFor = request.headers['x-forwarded-for'];
|
|
134
|
-
console.log('X-Forwarded-For header:', xForwardedFor);
|
|
135
|
-
console.log('Request IP:', request.ip);
|
|
136
|
-
console.log('Socket Remote Address:', request.socket.remoteAddress);
|
|
137
|
-
console.log('X-Real-IP header:', request.headers['x-real-ip']);
|
|
138
|
-
console.log('CF-Connecting-IP header:', request.headers['cf-connecting-ip']);
|
|
139
143
|
if (xForwardedFor) {
|
|
140
144
|
const ips = Array.isArray(xForwardedFor)
|
|
141
145
|
? xForwardedFor
|
|
142
146
|
: xForwardedFor.split(',');
|
|
143
|
-
|
|
147
|
+
ip = ips[0].trim();
|
|
144
148
|
}
|
|
145
149
|
// Check X-Real-IP header (nginx)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
else if (request.headers['x-real-ip']) {
|
|
151
|
+
const xRealIp = request.headers['x-real-ip'];
|
|
152
|
+
ip = Array.isArray(xRealIp) ? xRealIp[0] : xRealIp;
|
|
149
153
|
}
|
|
150
154
|
// Check CF-Connecting-IP (Cloudflare)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
else if (request.headers['cf-connecting-ip']) {
|
|
156
|
+
const cfIp = request.headers['cf-connecting-ip'];
|
|
157
|
+
ip = Array.isArray(cfIp) ? cfIp[0] : cfIp;
|
|
154
158
|
}
|
|
155
159
|
// Use Express native request.ip (handles proxies if trust proxy is set)
|
|
156
|
-
if (request.ip) {
|
|
157
|
-
|
|
160
|
+
else if (request.ip) {
|
|
161
|
+
ip = request.ip;
|
|
158
162
|
}
|
|
159
163
|
// Fallback to socket remote address
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
else if (request.socket.remoteAddress) {
|
|
165
|
+
ip = request.socket.remoteAddress;
|
|
166
|
+
}
|
|
167
|
+
// Clean IPv6-mapped IPv4 format (::ffff:192.168.0.166 -> 192.168.0.166)
|
|
168
|
+
if (ip.startsWith('::ffff:')) {
|
|
169
|
+
ip = ip.substring(7);
|
|
170
|
+
}
|
|
171
|
+
return ip || 'Unknown';
|
|
162
172
|
}
|
|
163
173
|
};
|
|
164
174
|
exports.AuthController = AuthController;
|
package/dist/auth.service.js
CHANGED
|
@@ -178,6 +178,7 @@ let AuthService = class AuthService {
|
|
|
178
178
|
async saveLastLogin(user, clientIp, loginStatus = 'success', failureReason, additionalData) {
|
|
179
179
|
if (!this.userLastLoginRepo) {
|
|
180
180
|
// Last login tracking not configured
|
|
181
|
+
console.warn('⚠️ userLastLoginRepo not configured. Add loginDetailsRepo to AuthCoreModule repositories.');
|
|
181
182
|
return;
|
|
182
183
|
}
|
|
183
184
|
try {
|
|
@@ -231,6 +232,7 @@ let AuthService = class AuthService {
|
|
|
231
232
|
async saveLoginDetailsJson(user, clientIp, loginStatus = 'success', failureReason, additionalData) {
|
|
232
233
|
if (!this.loginDetailsRepo) {
|
|
233
234
|
// Login details tracking not configured
|
|
235
|
+
console.warn('⚠️ loginDetailsRepo not configured. Add loginDetailsRepo to AuthCoreModule repositories.');
|
|
234
236
|
return;
|
|
235
237
|
}
|
|
236
238
|
try {
|