Skip to content

Commit 9e70be3

Browse files
committed
fix(Authentication): correctly pass custom options to clear cookie calls
1 parent 9083f14 commit 9e70be3

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

server/src/routes/auth/@me/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ module.exports = {
2121
if (!user) return response.sendError('User not found.', 404);
2222

2323
if (userQuarantined) {
24-
response.clearCookie('token');
24+
response.clearCookie('token', {
25+
httpOnly: true,
26+
domain: `.${new URL(config.frontendUrl).hostname}`
27+
});
2528

2629
return response.sendError('You are not allowed to login.', 403);
2730
}

server/src/routes/auth/logout.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ module.exports = {
1515
async (request, response) => {
1616
await User.updateOne({ id: request.user.id }, { lastLogoutAt: new Date() }).catch(() => null);
1717

18-
response.clearCookie('token');
18+
response.clearCookie('token', {
19+
httpOnly: true,
20+
domain: `.${new URL(config.frontendUrl).hostname}`
21+
});
1922

2023
return response.json({ success: true });
2124
}

server/src/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ module.exports = class Server {
124124
} catch (error) {
125125
logger.error('There was an error verifying the token:', error);
126126

127-
response.clearCookie('token');
127+
response.clearCookie('token', {
128+
httpOnly: true,
129+
domain: `.${new URL(config.frontendUrl).hostname}`
130+
});
128131

129132
return response.sendError('Unauthorized', 401);
130133
}

server/src/utils/middlewares/checkAuthentication.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ module.exports = async function checkAuthentication(request, response, next) {
3030

3131
next();
3232
} catch (error) {
33-
response.clearCookie('token');
33+
response.clearCookie('token', {
34+
httpOnly: true,
35+
domain: `.${new URL(config.frontendUrl).hostname}`
36+
});
3437

3538
if (error instanceof AuthError) return response.sendError(error.message, 401);
3639

0 commit comments

Comments
 (0)