ecrs-auth-core 1.0.117 → 1.0.118

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.
@@ -6,6 +6,7 @@ export declare class AuthCustomerController {
6
6
  private readonly authCustomerService;
7
7
  private readonly jwtService;
8
8
  constructor(authCustomerService: AuthCustomerService, jwtService: JwtService);
9
+ private extractSubdomain;
9
10
  login(request: Request, body: LoginCustomerDto): Promise<{
10
11
  status: boolean;
11
12
  message: string;
@@ -24,17 +24,28 @@ let AuthCustomerController = class AuthCustomerController {
24
24
  this.authCustomerService = authCustomerService;
25
25
  this.jwtService = jwtService;
26
26
  }
27
+ extractSubdomain(url) {
28
+ if (!url)
29
+ return null;
30
+ try {
31
+ const hostname = new URL(url).hostname; // e.g. "acme.ecrs.com" or "wht.localhost"
32
+ const parts = hostname.split(".");
33
+ if (parts.length > 2)
34
+ return parts[0];
35
+ if (parts.length === 2 && parts[1] === "localhost")
36
+ return parts[0];
37
+ return null;
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
27
43
  async login(request, body) {
28
44
  const clientIp = this.getClientIp(request);
29
45
  const userAgent = request.get("user-agent") || "Unknown";
30
46
  const additionalData = this.extractClientData(request, userAgent);
31
- const host = request.get("host") || "";
32
- const hostParts = host.split(".");
33
- const subdomain = hostParts.length > 2
34
- ? hostParts[0]
35
- : hostParts.length === 2 && hostParts[1].split(":")[0] === "localhost"
36
- ? hostParts[0]
37
- : null;
47
+ const origin = request.get("origin") || request.get("referer") || "";
48
+ const subdomain = this.extractSubdomain(origin);
38
49
  console.log(`📍 Customer Emplyee login attempt from IP: ${clientIp}, User-Agent: ${userAgent}, subdomain: ${subdomain ?? "none"}`);
39
50
  const user = await this.authCustomerService.validateUser(body.email, body.password, clientIp, subdomain ?? undefined);
40
51
  if (!user) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecrs-auth-core",
3
- "version": "1.0.117",
3
+ "version": "1.0.118",
4
4
  "description": "Centralized authentication and authorization module for ECRS apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",