Skip to content

Commit 7da192e

Browse files
authored
Merge pull request #30 from oslabs-beta/oauth
Manage project functionality fully implemented
2 parents 6ba8652 + 38badfe commit 7da192e

File tree

6 files changed

+28
-29
lines changed

6 files changed

+28
-29
lines changed

app/src/components/right/OpenProjects.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function ProjectsDialog(props: ProjectDialogProps) {
3636
(project: any) => project.name === value
3737
)[0];
3838
// dispatch({ type: 'OPEN PROJECT', payload: selectedProject });
39+
console.log(selectedProject);
3940
dispatch(openProject(selectedProject))
4041
onClose();
4142
};

app/src/helperFunctions/projectGetSaveDel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const saveProject = (
3333
): Promise<Object> => {
3434
const body = JSON.stringify({
3535
name,
36-
project: workspace,
36+
project: { ...workspace, name },
3737
userId: window.localStorage.getItem('ssid'),
3838
username: window.localStorage.getItem('username'),
3939
comments: []

app/src/redux/reducers/slice/appStateSlice.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,7 @@ const appStateSlice = createSlice({
774774
},
775775
updateProjectName: (state, action) => {
776776
const projectName = action.payload;
777-
return {
778-
...state,
779-
name: projectName
780-
};
777+
state.name = projectName;
781778
},
782779
deleteElement: (state, action) => {
783780
let name: string = '';
@@ -867,12 +864,14 @@ const appStateSlice = createSlice({
867864
componentId: 1,
868865
childId: null
869866
};
870-
convertToJSX(action.payload.HTMLTypes);
867+
// convertToJSX(action.payload.HTMLTypes);
871868
state.canvasFocus = canvasFocus;
872869
},
873-
openProject: (state, action) => {
874-
convertToJSX(action.payload.HTMLTypes);
875-
state = action.payload;
870+
openProject: ( state, action) => {
871+
// convertToJSX(action.payload.HTMLTypes);
872+
873+
return action.payload
874+
876875
},
877876
addElement: (state, action) => {
878877
const HTMLTypes = [...state.HTMLTypes];

config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const config = {
44
DEV_PORT: 5656,
55
API_BASE_URL: isProduction
66
? 'http://reactypev15-env.eba-mbvivk7k.us-east-1.elasticbeanstalk.com'
7-
: 'http://localhost:5656',
7+
: 'http://localhost:8080',
88
API_BASE_URL2: isProduction
99
? 'http://reactypev15-env.eba-mbvivk7k.us-east-1.elasticbeanstalk.com'
10-
: 'http://localhost:8080'
10+
: 'http://localhost:8080',
1111
};
1212

1313
module.exports = config;

server/controllers/projectController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const projectController: ProjectController = {
1414
// pull ssid from cookies for user id
1515
Projects.findOneAndUpdate(
1616
// looks in projects collection for project by user and name
17-
{ name, userId, username },
17+
{ name, userId, username},
1818
// update or insert the project
1919
{ project, createdAt, comments },
2020
// Options:

server/controllers/sessionController.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,31 @@ import { SessionController, SessionCookie } from '../interfaces';
66
dotenv.config();
77

88
const sessionController: SessionController = {
9-
// isLoggedIn finds the right session, if the session is invalid in the database, the app redirect user straight to the root endpoint witht he login page, if not, continue session
10-
isLoggedIn: (req, res, next) => {
9+
isLoggedIn: async (req, res, next) => {
10+
try {
1111
let cookieId;
12-
if (req.cookies.ssid) {
12+
if (req.cookies) {
1313
cookieId = req.cookies.ssid;
1414
} else {
1515
cookieId = req.body.userId;
1616
}
1717

1818
// find session from request session ID in mongodb
19-
Sessions.findOne({ cookieId }, (err, session) => {
20-
if (err) {
21-
return next({
22-
log: `Error in sessionController.isLoggedIn: ${err}`,
23-
message: {
24-
err: 'Error in sessionController.isLoggedIn, check server logs for details'
25-
}
26-
});
27-
}
28-
if (!session) {
29-
return res.redirect('/');
19+
const session = await Sessions.findOne({ cookieId });
20+
21+
if (!session) {
22+
return res.redirect('/');
23+
}
24+
return next();
25+
} catch (err) {
26+
return next({
27+
log: `Error in sessionController.isLoggedIn: ${err}`,
28+
message: {
29+
err: 'Error in sessionController.isLoggedIn, check server logs for details'
3030
}
31-
return next();
3231
});
33-
},
34-
32+
}
33+
},
3534
// startSession - create and save a new session into the database
3635
startSession: (req, res, next) => {
3736
// first check if user is logged in already

0 commit comments

Comments
 (0)