Skip to content

Continue to Address Outage Issues #3097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions client/modules/User/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export function getUser() {
const response = await apiClient.get('/session');
const { data } = response;

if (data?.user === null) {
return;
}

dispatch(authenticateUser(data));
dispatch({
type: ActionTypes.SET_PREFERENCES,
Expand All @@ -112,21 +116,19 @@ export function getUser() {
}

export function validateSession() {
return (dispatch, getState) => {
apiClient
.get('/session')
.then((response) => {
const state = getState();
if (state.user.username !== response.data.username) {
dispatch(showErrorModal('staleSession'));
}
})
.catch((error) => {
const { response } = error;
if (response.status === 404) {
dispatch(showErrorModal('staleSession'));
}
});
return async (dispatch, getState) => {
try {
const response = await apiClient.get('/session');
const state = getState();

if (state.user.username !== response.data.username) {
dispatch(showErrorModal('staleSession'));
}
} catch (error) {
if (error.response && error.response.status === 404) {
dispatch(showErrorModal('staleSession'));
}
}
};
}

Expand Down
6 changes: 3 additions & 3 deletions server/controllers/aws.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function getObjectKey(url) {
}

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

if (objectsToDelete.length > 0) {
const params = {
Expand Down Expand Up @@ -168,7 +168,7 @@ export async function listObjectsInS3ForUser(userId) {

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

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

assets.forEach((asset) => {
assets?.forEach((asset) => {
const name = asset.key.split('/').pop();
const foundAsset = {
key: asset.key,
Expand Down
10 changes: 7 additions & 3 deletions server/controllers/session.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ export function createSession(req, res, next) {
}

export function getSession(req, res) {
if (req.user && !req.user.banned) {
return res.json(userResponse(req.user));
if (!req.user) {
return res.status(200).send({ user: null });
}
return res.status(404).send({ message: 'Session does not exist' });
if (req.user.banned) {
return res.status(403).send({ message: 'Forbidden: User is banned.' });
}

return res.json(userResponse(req.user));
}

export function destroySession(req, res, next) {
Expand Down
3 changes: 2 additions & 1 deletion server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ userSchema.methods.comparePassword = async function comparePassword(
candidatePassword
) {
if (!this.password) {
throw new Error('No password is set for this user.');
console.error('No password is set for this user.');
return false;
}

try {
Expand Down
Loading