auth bug fix 12

This commit is contained in:
Kallesh B S 2025-09-30 11:15:23 +05:30
parent 7a783994fd
commit 16881b9c0a
2 changed files with 100 additions and 29 deletions

View File

@ -48,21 +48,47 @@ export class AuthController {
let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, body.P_APPLICATIONNAME, req, 2);
if (k.access_token) {
res.cookie('access_token', k.access_token, {
// if (k.access_token) {
// res.cookie('access_token', k.access_token, {
// httpOnly: true,
// secure: true,
// sameSite: 'none'
// });
// }
// if (k.refresh_token) {
// res.cookie('refresh_token', k.refresh_token, {
// httpOnly: true,
// secure: true,
// sameSite: 'none'
// });
// }
const hostname = req.hostname;
// Check if we're on localhost (no domain scoping in that case)
const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1';
// Optional: you can also support ports, like 'localhost:3000'
const isDevEnv = isLocalhost || hostname.startsWith('localhost') || hostname.startsWith('127.0.0.1');
const cookieOptions: any = {
httpOnly: true,
secure: true,
sameSite: 'none'
});
};
if (!isDevEnv) {
cookieOptions.domain = hostname; // Set domain only for subdomains
}
if (k.refresh_token) {
res.cookie('refresh_token', k.refresh_token, {
httpOnly: true,
secure: true,
sameSite: 'none'
res.cookie('access_token', k.access_token, {
...cookieOptions
});
res.cookie('refresh_token', k.refresh_token, {
...cookieOptions
});
}
return { statusCode: 200, message: "Logged-In Successfully", email: k.email }
}
@ -118,6 +144,49 @@ export class AuthController {
const refreshToken = req.user?.refreshToken;
let rst: any = await this.authService.logoutUser(refreshToken);
if (rst.statusCode === 200) {
// res.clearCookie('access_token', {
// httpOnly: true,
// secure: true,
// sameSite: 'none'
// });
// res.clearCookie('refresh_token', {
// httpOnly: true,
// secure: true,
// sameSite: 'none'
// });
const hostname = req.hostname;
// Check if we're on localhost (no domain scoping in that case)
const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1';
// Optional: you can also support ports, like 'localhost:3000'
const isDevEnv = isLocalhost || hostname.startsWith('localhost') || hostname.startsWith('127.0.0.1');
const cookieOptions: any = {
httpOnly: true,
secure: true,
sameSite: 'none'
};
if (!isDevEnv) {
cookieOptions.domain = hostname; // Set domain only for subdomains
}
if (!isDevEnv) {
res.clearCookie('access_token', {
httpOnly: true,
secure: true,
sameSite: 'none',
domain: hostname
});
res.clearCookie('refresh_token', {
httpOnly: true,
secure: true,
sameSite: 'none',
domain: hostname
});
} else {
res.clearCookie('access_token', {
httpOnly: true,
secure: true,
@ -129,6 +198,8 @@ export class AuthController {
sameSite: 'none'
});
}
}
res.json({ ...rst })
}

View File

@ -1245,7 +1245,7 @@ export class CarnetApplicationService {
description: x.ITEMDESCRIPTION,
noOfPieces: x.NOOFPIECES,
weight: x.WEIGHT,
itemValue: x.ITEMVALUE,
itemValue: isNaN(Number(x.ITEMVALUE)) ? 0 : Number(x.ITEMVALUE),
countryOfOrigin: x.GOODSORIGINCOUNTRY
};
});
@ -1256,15 +1256,15 @@ export class CarnetApplicationService {
ISSUEDATE: fres[0].ISSUEDATE ?? "",
EXPDATE: fres[0].EXPDATE ?? "",
AUTHREP: fres[0].AUTHREP ?? "",
NOOFUSSETS: fres[0].NOOFUSSETS ?? 0,
NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS ?? 0,
NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS ?? 0,
NOOFUSSETS: isNaN(Number(fres[0].NOOFUSSETS)) ? 0 : Number(fres[0].NOOFUSSETS),
NOOFFOREIGNSETS: isNaN(Number(fres[0].NOOFFOREIGNSETS)) ? 0 : Number(fres[0].NOOFFOREIGNSETS),
NOOFTRANSITSETS: isNaN(Number(fres[0].NOOFTRANSITSETS)) ? 0 : Number(fres[0].NOOFTRANSITSETS),
PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED ?? "",
HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT ?? "",
CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS ?? 0,
NEXTUSCFNO: fres[0].NEXTUSCFNO ?? 0,
NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO ?? 0,
NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO ?? 0,
CONTINUATIONSHEETS: isNaN(Number(fres[0].CONTINUATIONSHEETS)) ? 0 : Number(fres[0].CONTINUATIONSHEETS),
NEXTUSCFNO: isNaN(Number(fres[0].NEXTUSCFNO)) ? 0 : Number(fres[0].NEXTUSCFNO),
NEXTFOREIGNCFNO: isNaN(fres[0].NEXTFOREIGNCFNO) ? 0 : Number(fres[0].NEXTFOREIGNCFNO),
NEXTTRANSITCFNO: isNaN(Number(fres[0].NEXTTRANSITCFNO)) ? 0 : Number(fres[0].NEXTTRANSITCFNO),
contPageNo: 0
}