diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index e61d627..d3cec86 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -48,47 +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, { - // 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.access_token) { + res.cookie('access_token', k.access_token, { + httpOnly: true, + secure: true, + sameSite: 'none' + }); } - res.cookie('access_token', k.access_token, { - ...cookieOptions - }); + if (k.refresh_token) { + res.cookie('refresh_token', k.refresh_token, { + httpOnly: true, + secure: true, + sameSite: 'none' + }); + } - res.cookie('refresh_token', k.refresh_token, { - ...cookieOptions - }); + // auth domain below + + // const hostname = req.hostname; + + // const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1'; + + // 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; + // } + + // 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 } } @@ -144,60 +144,60 @@ 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 = { + res.clearCookie('access_token', { httpOnly: true, secure: true, sameSite: 'none' - }; + }); + res.clearCookie('refresh_token', { + httpOnly: true, + secure: true, + sameSite: 'none' + }); - if (!isDevEnv) { - cookieOptions.domain = hostname; // Set domain only for subdomains - } + // to enable auth domain - 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' - }); - } + // const hostname = req.hostname; + + // const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1'; + + // 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; + // } + + // 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 })