Skip to content

Commit 31d4ded

Browse files
authored
Merge pull request #3097 from processing/fix/address-outage-issues
Continue to Address Outage Issues
2 parents 6f3f5c7 + bf324af commit 31d4ded

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

client/modules/User/actions.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export function getUser() {
9696
const response = await apiClient.get('/session');
9797
const { data } = response;
9898

99+
if (data?.user === null) {
100+
return;
101+
}
102+
99103
dispatch(authenticateUser(data));
100104
dispatch({
101105
type: ActionTypes.SET_PREFERENCES,
@@ -112,21 +116,19 @@ export function getUser() {
112116
}
113117

114118
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-
});
119+
return async (dispatch, getState) => {
120+
try {
121+
const response = await apiClient.get('/session');
122+
const state = getState();
123+
124+
if (state.user.username !== response.data.username) {
125+
dispatch(showErrorModal('staleSession'));
126+
}
127+
} catch (error) {
128+
if (error.response && error.response.status === 404) {
129+
dispatch(showErrorModal('staleSession'));
130+
}
131+
}
130132
};
131133
}
132134

server/controllers/aws.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function getObjectKey(url) {
4141
}
4242

4343
export async function deleteObjectsFromS3(keyList, callback) {
44-
const objectsToDelete = keyList.map((key) => ({ Key: key }));
44+
const objectsToDelete = keyList?.map((key) => ({ Key: key }));
4545

4646
if (objectsToDelete.length > 0) {
4747
const params = {
@@ -168,7 +168,7 @@ export async function listObjectsInS3ForUser(userId) {
168168

169169
const data = await s3Client.send(new ListObjectsCommand(params));
170170

171-
assets = data.Contents.map((object) => ({
171+
assets = data.Contents?.map((object) => ({
172172
key: object.Key,
173173
size: object.Size
174174
}));
@@ -177,7 +177,7 @@ export async function listObjectsInS3ForUser(userId) {
177177
const projectAssets = [];
178178
let totalSize = 0;
179179

180-
assets.forEach((asset) => {
180+
assets?.forEach((asset) => {
181181
const name = asset.key.split('/').pop();
182182
const foundAsset = {
183183
key: asset.key,

server/controllers/session.controller.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ 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.status(200).send({ user: null });
2929
}
30-
return res.status(404).send({ message: 'Session does not exist' });
30+
if (req.user.banned) {
31+
return res.status(403).send({ message: 'Forbidden: User is banned.' });
32+
}
33+
34+
return res.json(userResponse(req.user));
3135
}
3236

3337
export function destroySession(req, res, next) {

server/models/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ userSchema.methods.comparePassword = async function comparePassword(
163163
candidatePassword
164164
) {
165165
if (!this.password) {
166-
throw new Error('No password is set for this user.');
166+
console.error('No password is set for this user.');
167+
return false;
167168
}
168169

169170
try {

0 commit comments

Comments
 (0)