Skip to content

Commit 4a9e80b

Browse files
authored
Merge pull request #39 from andrewjcho84/serverSeparation
Add more server separation logic
2 parents b7ffaa6 + 2e2e626 commit 4a9e80b

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

app/electron/main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ app.on('web-contents-created', (event, contents) => {
222222
const parsedUrl = new URL(navigationUrl);
223223
const validOrigins = [
224224
selfHost,
225-
'https://localhost:8081',
225+
'http://localhost:8081',
226+
'http://reactype.heroku.com',
226227
'https://github.com/'
227228
];
228229
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
@@ -242,7 +243,9 @@ app.on('web-contents-created', (event, contents) => {
242243
//console.log('parsedUrl.origin is', parsedUrl.origin);
243244
const validOrigins = [
244245
selfHost,
245-
'https://localhost:8081',
246+
'http://localhost:8081',
247+
'http://localhost:5000',
248+
'http://reactype.heroku.com',
246249
'https://github.com',
247250
'app://rse/'
248251
];
@@ -331,7 +334,7 @@ ipcMain.on('choose_app_dir', event => {
331334
// for github oauth login in production, since cookies are not accessible through document.cookie on local filesystem, we need electron to grab the cookie that is set from oauth, this listens for an set cookie event from the renderer process then sends back the cookie
332335
ipcMain.on('set_cookie', event => {
333336
session.defaultSession.cookies
334-
.get({ url: 'https://localhost:8081' })
337+
.get({ url: 'https://reactype.heroku.com' })
335338
.then(cookie => {
336339
console.log(cookie);
337340
event.reply('give_cookie', cookie);
@@ -344,7 +347,7 @@ ipcMain.on('set_cookie', event => {
344347
// again for production, document.cookie is not accessible so we need this listener on main to delete the cookie on logout
345348
ipcMain.on('delete_cookie', event => {
346349
session.defaultSession.cookies
347-
.remove('https://localhost:8081', 'ssid')
350+
.remove('https://reactype.heroku.com', 'ssid')
348351
.then(removed => {
349352
console.log('Cookies deleted', removed);
350353
})

app/src/components/login/LoginButton.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useContext } from 'react';
22
import { stateContext } from '../../context/context';
33
import Button from '@material-ui/core/Button';
44
import ExitToAppIcon from '@material-ui/icons/ExitToApp';
5-
import { useHistory } from "react-router-dom";
5+
import { useHistory } from 'react-router-dom';
66

77
export default function LoginButton() {
88
let history = useHistory();
@@ -11,8 +11,12 @@ export default function LoginButton() {
1111
const handleLogout = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
1212
e.preventDefault();
1313
console.log('Logout clicked, destroying cookie, redirect to login');
14+
// clear local storage
15+
window.localStorage.clear();
1416
// destroys cookie by backdating expiration time
1517
document.cookie = 'ssid=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
18+
// destroy cookie in production via electron main process
19+
window.api.delCookie();
1620
// uses useHistory to return to the login page
1721
history.push('/login');
1822
};
@@ -28,7 +32,7 @@ export default function LoginButton() {
2832
>
2933
Log Out
3034
</Button>
31-
)
35+
);
3236
} else {
3337
return (
3438
<Button
@@ -40,6 +44,6 @@ export default function LoginButton() {
4044
>
4145
Log In
4246
</Button>
43-
)
47+
);
4448
}
45-
}
49+
}

app/src/components/login/ProjectsFolder.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ export default function ProjectsFolder() {
9797

9898
const handleClickOpen = () => {
9999
getProjects().then(data => {
100-
setProjects(data);
101-
setOpen(true);
100+
if (data) {
101+
setProjects(data);
102+
setOpen(true);
103+
}
102104
});
103105
};
104106

app/src/components/login/SignIn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
208208
variant="contained"
209209
color="default"
210210
className={classes.submit}
211-
href="https://localhost:8081/github"
211+
href="https://reactype.heroku.com/github"
212212
onClick={() => {
213213
console.log('Inside onclick of github');
214214
setTimeout(() => {

app/src/helperFunctions/auth.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
const isDev = process.env.NODE_ENV === 'development';
2+
let serverURL = 'https://reactype.herokuapp.com';
3+
if (isDev) {
4+
serverURL = 'http://localhost:5000';
5+
}
6+
17
export const sessionIsCreated = (
28
username: string,
39
password: string
410
): Promise<string> => {
5-
console.log('Username and pw in sessionIsCreated', username, password);
611
const body = JSON.stringify({
712
username,
813
password
914
});
10-
console.log('In sessionIsCreated, body is', body);
11-
const result = fetch('https://localhost:8081/login', {
15+
console.log(process.env.NODE_ENV);
16+
const result = fetch(`${serverURL}/login`, {
1217
method: 'POST',
1318
credentials: 'include',
1419
headers: {
15-
'Content-Type': 'application/json',
16-
Origin: 'reactype'
20+
'Content-Type': 'application/json'
1721
},
1822
body
1923
})
@@ -48,13 +52,11 @@ export const newUserIsCreated = (
4852
email,
4953
password
5054
});
51-
const result = fetch('https://localhost:8081/signup', {
55+
const result = fetch(`${serverURL}/signup`, {
5256
method: 'POST',
53-
//credentials: 'include',
54-
//mode: 'no-cors',
57+
credentials: 'include',
5558
headers: {
5659
'Content-Type': 'application/json'
57-
//'Access-Control-Allow-Origin': 'https://localhost:8081'
5860
},
5961
body
6062
})

app/src/helperFunctions/projectGetSave.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
const isDev = process.env.NODE_ENV === 'development';
2+
let serverURL = 'https://reactype.herokuapp.com';
3+
if (isDev) {
4+
serverURL = 'http://localhost:5000';
5+
}
16
// helper functions that will do fetch requests to get and save user/guest projects
27

38
export const getProjects = (): Promise<Object> => {
49
//console.log("Loading user's projects...");
510
let userId = window.localStorage.getItem('ssid');
611
//console.log('userId from localStorage is', userId);
712
const body = JSON.stringify({ userId });
8-
const projects = fetch('https://localhost:8081/getProjects', {
13+
const projects = fetch(`${serverURL}/getProjects`, {
914
method: 'POST',
1015
headers: {
1116
'content-type': 'application/json'
@@ -33,7 +38,7 @@ export const saveProject = (
3338
project: workspace,
3439
userId: window.localStorage.getItem('ssid')
3540
});
36-
const project = fetch('https://localhost:8081/saveProject', {
41+
const project = fetch(`${serverURL}/saveProject`, {
3742
method: 'POST',
3843
headers: {
3944
'content-type': 'application/json'

0 commit comments

Comments
 (0)