Skip to content

Commit 6412f36

Browse files
committed
update status codes for getSession, clear cookies
1 parent ba794cc commit 6412f36

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

client/modules/User/actions.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,19 @@ export function getUser() {
112112
}
113113

114114
export function validateSession() {
115-
return (dispatch, getState) => {
116-
apiClient
117-
.get('/session')
118-
.then((response) => {
119-
const state = getState();
120-
if (state.user.username !== response.data.username) {
121-
dispatch(showErrorModal('staleSession'));
122-
}
123-
})
124-
.catch((error) => {
125-
const { response } = error;
126-
if (response.status === 404) {
127-
dispatch(showErrorModal('staleSession'));
128-
}
129-
});
115+
return async (dispatch, getState) => {
116+
try {
117+
const response = await apiClient.get('/session');
118+
const state = getState();
119+
120+
if (state.user.username !== response.data.username) {
121+
dispatch(showErrorModal('staleSession'));
122+
}
123+
} catch (error) {
124+
if (error.response && error.response.status === 404) {
125+
dispatch(showErrorModal('staleSession'));
126+
}
127+
}
130128
};
131129
}
132130

server/controllers/session.controller.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ export function createSession(req, res, next) {
2424
}
2525

2626
export function getSession(req, res) {
27-
if (req.user && !req.user.banned) {
28-
return res.json(userResponse(req.user));
27+
if (!req.user) {
28+
return res
29+
.status(200)
30+
.send({ message: 'Session does not exist.', user: null });
2931
}
30-
return res.status(404).send({ message: 'Session does not exist' });
32+
if (req.user.banned) {
33+
return res.status(403).send({ message: 'Forbidden: User is banned.' });
34+
}
35+
36+
return res.json(userResponse(req.user));
3137
}
3238

3339
export function destroySession(req, res, next) {
@@ -41,6 +47,7 @@ export function destroySession(req, res, next) {
4147
next(error);
4248
return;
4349
}
50+
res.clearCookie('connect.sid');
4451
res.json({ success: true });
4552
});
4653
});

0 commit comments

Comments
 (0)