reverted auth domain
This commit is contained in:
parent
16881b9c0a
commit
60f59287c6
@ -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);
|
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,
|
|
||||||
// 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,
|
httpOnly: true,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: 'none'
|
sameSite: 'none'
|
||||||
};
|
});
|
||||||
|
|
||||||
if (!isDevEnv) {
|
|
||||||
cookieOptions.domain = hostname; // Set domain only for subdomains
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.cookie('access_token', k.access_token, {
|
if (k.refresh_token) {
|
||||||
...cookieOptions
|
|
||||||
});
|
|
||||||
|
|
||||||
res.cookie('refresh_token', k.refresh_token, {
|
res.cookie('refresh_token', k.refresh_token, {
|
||||||
...cookieOptions
|
httpOnly: true,
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'none'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 }
|
return { statusCode: 200, message: "Logged-In Successfully", email: k.email }
|
||||||
}
|
}
|
||||||
@ -144,6 +144,49 @@ 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', {
|
||||||
|
httpOnly: true,
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'none'
|
||||||
|
});
|
||||||
|
res.clearCookie('refresh_token', {
|
||||||
|
httpOnly: true,
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'none'
|
||||||
|
});
|
||||||
|
|
||||||
|
// to enable auth domain
|
||||||
|
|
||||||
|
// 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', {
|
// res.clearCookie('access_token', {
|
||||||
// httpOnly: true,
|
// httpOnly: true,
|
||||||
// secure: true,
|
// secure: true,
|
||||||
@ -154,50 +197,7 @@ export class AuthController {
|
|||||||
// secure: true,
|
// secure: true,
|
||||||
// sameSite: 'none'
|
// 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,
|
|
||||||
sameSite: 'none'
|
|
||||||
});
|
|
||||||
res.clearCookie('refresh_token', {
|
|
||||||
httpOnly: true,
|
|
||||||
secure: true,
|
|
||||||
sameSite: 'none'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
res.json({ ...rst })
|
res.json({ ...rst })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user