Skip to content

Commit c8ee9c5

Browse files
committed
oauth works and changed background of sign in and sign up
1 parent 4f11521 commit c8ee9c5

File tree

17 files changed

+252
-172
lines changed

17 files changed

+252
-172
lines changed

CHANGE_LOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Changes:<br>
1616
- Additional logic added for edge cases in inputs for state manager (passing in non-Arrays/non-Objects as Array type and Object type).
1717
- Fixed issue with the bottom panel not dragging or sticking to the mouse when the mouse is over the demorender iframe
1818
- Cleaned up hundreds of lines of outdated code and archived multiple unused and duplicate files
19+
- OAuth now linked to standalone gmail and github accounts
1920
- User Features:
2021
- UI updated with a modern style for a better developer experience
2122
- Added many user feedback alerts for better experience including alerts for when projects are published, cloned, deleted, HTML custom tags are created, context created, or custom component created.

app/src/components/App.tsx

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,38 @@ export const App = (): JSX.Element => {
3131
}, []);
3232

3333
// following useEffect runs on first mount
34-
useEffect(() => {
35-
// console.log('cookies.get in App', Cookies.get())
36-
// if user is a guest, see if a project exists in localforage and retrieve it
37-
// v17 May not currently work yet
38-
if (!state.isLoggedIn) {
39-
localforage.getItem('guestProject').then((project) => {
40-
// if project exists, use dispatch to set initial state to that project
41-
if (project) {
42-
dispatch(setInitialState(project));
43-
}
44-
});
45-
} else {
46-
// otherwise if a user is logged in, use a fetch request to load user's projects from DB
34+
// useEffect(() => {
35+
// // console.log('cookies.get in App', Cookies.get())
36+
// // if user is a guest, see if a project exists in localforage and retrieve it
37+
// // v17 May not currently work yet
38+
// if (!state.isLoggedIn) {
39+
// localforage.getItem('guestProject').then((project) => {
40+
// // if project exists, use dispatch to set initial state to that project
41+
// if (project) {
42+
// dispatch(setInitialState(project));
43+
// }
44+
// });
45+
// } else {
46+
// // otherwise if a user is logged in, use a fetch request to load user's projects from DB
4747

48-
let userId;
49-
if (Cookies.get('ssid')) {
50-
userId = Cookies.get('ssid');
51-
} else {
52-
userId = window.localStorage.getItem('ssid');
53-
}
54-
//also load user's last project, which was saved in localforage on logout
55-
localforage.getItem(userId).then((project) => {
56-
if (project) {
57-
dispatch(setInitialState(project));
58-
} else {
59-
console.log(
60-
'No user project found in localforage, setting initial state blank'
61-
);
62-
}
63-
});
64-
}
65-
}, []);
48+
// let userId;
49+
// if (Cookies.get('ssid')) {
50+
// userId = Cookies.get('ssid');
51+
// } else {
52+
// userId = window.localStorage.getItem('ssid');
53+
// }
54+
// //also load user's last project, which was saved in localforage on logout
55+
// localforage.getItem(userId).then((project) => {
56+
// if (project) {
57+
// dispatch(setInitialState(project));
58+
// } else {
59+
// console.log(
60+
// 'No user project found in localforage, setting initial state blank'
61+
// );
62+
// }
63+
// });
64+
// }
65+
// }, []);
6666
// useEffect(() => {
6767
// // provide config properties to legacy projects so new edits can be auto saved
6868
// // if (state.config === undefined) {

app/src/components/login/SignIn.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const useStyles = makeStyles((theme) => ({
5252
paper: {
5353
display: 'flex',
5454
flexDirection: 'column',
55-
alignItems: 'center'
55+
alignItems: 'center',
5656
},
5757
avatar: {
5858
backgroundColor: '#3EC1AC'
@@ -211,8 +211,8 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
211211

212212
return (
213213
<StyledEngineProvider injectFirst>
214-
<ThemeProvider theme={!isDarkMode ? SigninLight : SigninDark}>
215-
<Container component="main" maxWidth="xs">
214+
<ThemeProvider theme={SigninDark}>
215+
<Container component="main" maxWidth="xs" >
216216
<CssBaseline />
217217
<div className={classes.paper}>
218218
{/* <Button
@@ -227,7 +227,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
227227
onClick={handleDarkModeToggle}
228228
>
229229
{isDarkMode ? `Light Mode` : `Dark Mode`}
230-
</Button> */}
230+
</Button> */}
231231
<Avatar className={classes.avatar} sx={{ marginTop: '10vh' }}>
232232
<LockOutlinedIcon />
233233
</Avatar>
@@ -372,19 +372,20 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
372372
/>
373373
</svg>
374374
</Button>
375-
<Grid container>
375+
<Grid container justifyContent="flex-end">
376+
{/* forgot password currently not implemented
376377
<Grid item xs>
377378
<RouteLink
378-
style={{ color: isDarkMode ? '#aaaaaa' : 'black' }}
379+
style={{ color: '#aaaaaa' }}
379380
to={`/signup`}
380381
className="nav_link"
381382
>
382383
Forgot password?
383384
</RouteLink>
384-
</Grid>
385+
</Grid> */}
385386
<Grid item>
386387
<RouteLink
387-
style={{ color: isDarkMode ? '#aaaaaa' : 'black' }}
388+
style={{ color: '#aaaaaa' }}
388389
to={`/signup`}
389390
className="nav_link"
390391
>

app/src/components/login/SignUp.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ const SignUp: React.FC<LoginInt & RouteComponentProps> = (props) => {
206206

207207
return (
208208
<StyledEngineProvider injectFirst>
209-
<ThemeProvider theme={!isDarkMode ? SigninLight : SigninDark}>
209+
<ThemeProvider theme={SigninDark}>
210210
<Container component="main" maxWidth="xs">
211211
<CssBaseline />
212212
<div className={classes.paper}>
213-
<Button
213+
{/* <Button
214214
color="primary"
215215
style={{
216216
minWidth: '113.97px',
@@ -221,7 +221,7 @@ const SignUp: React.FC<LoginInt & RouteComponentProps> = (props) => {
221221
onClick={handleDarkModeToggle}
222222
>
223223
{`Dark Mode: ${isDarkMode}`}
224-
</Button>
224+
</Button> */}
225225
<Avatar className={classes.avatar} sx={{ marginTop: '10vh' }}>
226226
<AssignmentIcon />
227227
</Avatar>
@@ -332,7 +332,7 @@ const SignUp: React.FC<LoginInt & RouteComponentProps> = (props) => {
332332
<Grid container justifyContent="flex-end">
333333
<Grid item>
334334
<RouteLink
335-
style={{ color: isDarkMode ? '#aaaaaa' : 'black' }}
335+
style={{ color: '#aaaaaa' }}
336336
to={`/login`}
337337
className="nav_link"
338338
>

app/src/components/marketplace/MarketplaceCard.tsx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const MarketplaceCard = ({ proj }: { proj: Project }) => {
5151
const [s3ImgURL, setS3ImgURL] = React.useState<null | string>(null);
5252
const open = Boolean(anchorEl);
5353
const [alertOpen, setAlertOpen] = React.useState<boolean>(false);
54+
const [guest, setGuest] = React.useState<boolean>(null);
55+
const state = useSelector((store: RootState) => store.appState);
56+
5457

5558
useEffect(() => {
5659
async function s3ImgFetch() {
@@ -69,30 +72,34 @@ const MarketplaceCard = ({ proj }: { proj: Project }) => {
6972
}, []);
7073

7174

75+
7276
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
7377
setAnchorEl(event.currentTarget);
7478
};
7579
const handleClone = async () => {
76-
// creates a copy of the project
77-
const docId = proj._id;
78-
const response = await axios.get(`/cloneProject/${docId}`, {
79-
params: { username: window.localStorage.getItem('username') }
80-
}); //passing in username as a query param is query params
81-
const project = response.data;
82-
setAlertOpen(true);
83-
setAnchorEl(null);
84-
return {
85-
_id: project._id,
86-
name: project.name,
87-
published: project.published,
88-
...project.project
89-
};
80+
if(state.isLoggedIn){
81+
// creates a copy of the project
82+
const docId = proj._id;
83+
const response = await axios.get(`/cloneProject/${docId}`); //passing in username as a query param is query params
84+
const project = response.data;
85+
setAlertOpen(true);
86+
setAnchorEl(null);
87+
return {
88+
_id: project._id,
89+
name: project.name,
90+
published: project.published,
91+
...project.project
92+
};
93+
}
94+
setGuest(true);
9095
};
9196

9297
const handleCloneOpen = async () => {
93-
const project = await handleClone();
94-
history.push('/');
95-
dispatch(openProject(project));
98+
if(state.isLoggedIn){
99+
const project = await handleClone();
100+
history.push('/');
101+
dispatch(openProject(project));
102+
}
96103
};
97104

98105
const handleClose = () => {
@@ -197,6 +204,20 @@ const MarketplaceCard = ({ proj }: { proj: Project }) => {
197204
Project Cloned!
198205
</Alert>
199206
</Snackbar>
207+
<Snackbar
208+
open={guest}
209+
autoHideDuration={3000}
210+
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
211+
onClose={handleAlertClose}
212+
>
213+
<Alert
214+
onClose={handleAlertClose}
215+
severity="error"
216+
sx={{ width: '100%', color: 'white' }}
217+
>
218+
Please login to clone!
219+
</Alert>
220+
</Snackbar>
200221
</Card>
201222
</>
202223
);

app/src/components/right/LoginButton.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,35 @@ import config from '../../../../config.js';
55
import { RootState } from '../../redux/store';
66
import Cookies from 'js-cookie';
77
// note that API_BASE_URL is assigned to different pages on dev mode vs prod mode
8-
const { API_BASE_URL, API_BASE_URL2 } = config;
8+
const { DEV_PORT, API_BASE_URL, API_BASE_URL2 } = config;
9+
const isDev = process.env.NODE_ENV === 'development';
10+
let serverURL = API_BASE_URL;
11+
12+
//check if we're in dev mode
13+
if (isDev) {
14+
serverURL = `http://localhost:${DEV_PORT}`;
15+
}
16+
917

1018
export default function LoginButton() {
1119
const state = useSelector((store:RootState) => store.appState);
1220
const dispatch = useDispatch();
1321

1422
const handleLogout = () => {
23+
const projects = fetch(`${serverURL}/logout`, {
24+
method: 'GET',
25+
headers: {
26+
'content-type': 'application/json'
27+
},
28+
// need credentials for userid pull from cookie
29+
credentials: 'include'
30+
})
31+
.then((res) => res.json())
32+
.then((data) => {
33+
return data;
34+
})
35+
.catch((err) => console.log(`Error getting project ${err}`));
36+
1537

1638
window.localStorage.clear();
1739

@@ -25,8 +47,10 @@ export default function LoginButton() {
2547
};
2648

2749
const handleLogin = () => {
50+
window.localStorage.clear();
2851
window.location.href = `${API_BASE_URL2}/#/login`;
2952
};
53+
3054
if (state.isLoggedIn) {
3155
return (
3256
<button onClick={handleLogout}>

app/src/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const PrivateRoute = ({ component: Component, ...rest }) => {
5252
})
5353
.then((res) => res.json())
5454
.then((data) => {
55-
console.log('........................ data', data);
55+
5656
setIsLoggedIn(data);
5757

5858
})
@@ -63,13 +63,12 @@ return (
6363
<Route
6464
{...rest}
6565
render={(props) => {
66-
if (isLoggedIn === true) {
67-
console.log("should be app")
66+
if (isLoggedIn === true || window.localStorage.getItem('ssid') === 'guest') {
6867
// User is logged in, render the protected component
6968
return <Component {...props} />;
7069
} else if(isLoggedIn !== null) {
71-
console.log("redirect login")
7270
// User is not logged in, redirect to the login page
71+
// Ignores the initial render which would have isLoggedIn as null
7372
return <Redirect to="/login" />;
7473
}
7574
}}

app/src/public/styles/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ body {
2626
overflow: hidden;
2727
height: 100vh;
2828
width: 100vw;
29-
background-color:white
29+
background-color: #191919
3030
}
3131

3232
h4 {

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"@reduxjs/toolkit": "^1.9.3",
121121
"@types/js-cookie": "^3.0.2",
122122
"@types/node": "^18.6.3",
123+
"@types/passport": "^1.0.13",
123124
"@types/prettier": "^2.6.4",
124125
"@types/react-redux": "^7.1.24",
125126
"@types/react-router-dom": "^5.3.3",

server/controllers/cookieController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ const cookieController: CookieController = {
2121
return next();
2222
},
2323

24+
deleteCookies: (req, res, next) => {
25+
26+
res.clearCookie('ssid');
27+
res.clearCookie('username');
28+
res.clearCookie('connect.sid');
29+
return next();
30+
}
31+
2432

2533
};
2634

server/controllers/marketplaceController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const marketplaceController: MarketplaceController = {
124124
cloneProject: async (req, res, next) => {
125125
// pulls cookies from request
126126
const userId = req.cookies.ssid;
127-
const username = req.query.username;
127+
const username = req.cookies.username;
128128
try { // trying to find project, update its userId and username to a new project, then save it
129129
const originalProject = await Projects.findOne({ _id: req.params.docId }).exec();
130130
const updatedProject = originalProject.toObject({ minimize: false }); // minimize false makes sure Mongoose / MongoDB does not remove nested properties with values of empty objects {}

0 commit comments

Comments
 (0)