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); let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, body.P_APPLICATIONNAME, req, 2);
if (k.access_token) { // if (k.access_token) {
res.cookie('access_token', k.access_token, { // res.cookie('access_token', k.access_token, {
httpOnly: true, // httpOnly: true,
secure: true, // secure: true,
sameSite: 'none' // 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('access_token', k.access_token, {
res.cookie('refresh_token', k.refresh_token, { ...cookieOptions
httpOnly: true, });
secure: true,
sameSite: 'none' res.cookie('refresh_token', k.refresh_token, {
}); ...cookieOptions
} });
return { statusCode: 200, message: "Logged-In Successfully", email: k.email } return { statusCode: 200, message: "Logged-In Successfully", email: k.email }
} }
@ -118,16 +144,61 @@ export class AuthController {
const refreshToken = req.user?.refreshToken; const refreshToken = req.user?.refreshToken;
let rst: any = await this.authService.logoutUser(refreshToken); let rst: any = await this.authService.logoutUser(refreshToken);
if (rst.statusCode === 200) { if (rst.statusCode === 200) {
res.clearCookie('access_token', { // 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, httpOnly: true,
secure: true, secure: true,
sameSite: 'none' sameSite: 'none'
}); };
res.clearCookie('refresh_token', {
httpOnly: true, if (!isDevEnv) {
secure: true, cookieOptions.domain = hostname; // Set domain only for subdomains
sameSite: 'none' }
});
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,
sameSite: 'none'
});
res.clearCookie('refresh_token', {
httpOnly: true,
secure: true,
sameSite: 'none'
});
}
} }
res.json({ ...rst }) res.json({ ...rst })
} }
@ -204,7 +275,7 @@ export class AuthController {
@UseGuards(JwtAuthGuard, RolesGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles('pua','psa','pca') @Roles('pua', 'psa', 'pca')
@Post('2/sendmail') @Post('2/sendmail')
@HttpCode(200) @HttpCode(200)
async sendMailb(@Body() body: SendMailDTO, @Req() req: Request) { async sendMailb(@Body() body: SendMailDTO, @Req() req: Request) {

View File

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