Skip to content

Commit bd728d2

Browse files
committed
starting oauth implementation
1 parent df06f78 commit bd728d2

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed

main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ const createWindow = () => {
9494
webPreferences: {
9595
zoomFactor: 0.7
9696
// for proper security measures, nodeIntegration should be set to false, but this results in a blank page when serving app
97-
//nodeIntegration: false
97+
//nodeIntegration: false,
98+
//preload: 'preload.js'
9899
},
99100
show: false,
100101
icon: path.join(__dirname, '/src/public/icons/png/256x256.png'),

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@
163163
"redux-devtools-extension": "^2.13.5",
164164
"redux-logger": "^3.0.6",
165165
"redux-thunk": "^2.3.0",
166-
"redux-undo": "^1.0.1"
166+
"redux-undo": "^1.0.1",
167+
"source-map-support": "^0.5.19"
167168
},
168169
"devDependencies": {
169170
"@babel/core": "^7.9.0",

src/components/login/SignIn.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useHistory,
99
RouteComponentProps
1010
} from 'react-router-dom';
11-
import { sessionIsCreated } from '../../helperFunctions/auth';
11+
import { sessionIsCreated, githubOauth } from '../../helperFunctions/auth';
1212

1313
import Avatar from '@material-ui/core/Avatar';
1414
import Button from '@material-ui/core/Button';
@@ -91,6 +91,20 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
9191
});
9292
};
9393

94+
// const handleOauth = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
95+
// e.preventDefault();
96+
// console.log('click fired on githubOauth');
97+
// githubOauth().then(isLoggedIn => {
98+
// if (isLoggedIn) {
99+
// console.log('session created');
100+
// dispatch(setLoginState()); // changes login state to true
101+
// props.history.push('/');
102+
// } else {
103+
// console.log("Couldn't login with github");
104+
// }
105+
// });
106+
// };
107+
94108
return (
95109
<Container component="main" maxWidth="xs">
96110
<CssBaseline />
@@ -142,6 +156,18 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
142156
Sign In
143157
</Button>
144158

159+
<a href="https://github.com/login/oauth/authorize?cliend_id=18e80c270cd6678592a7">
160+
<Button
161+
fullWidth
162+
variant="contained"
163+
color="primary"
164+
className={classes.submit}
165+
style={{ textDecoration: 'none' }}
166+
>
167+
Sign In With Github
168+
</Button>
169+
</a>
170+
145171
<Grid container>
146172
<Grid item xs>
147173
<Link href="#" variant="body2">

src/helperFunctions/auth.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
export const sessionIsCreated = (username: string, password: string): Promise<boolean> => {
1+
export const sessionIsCreated = (
2+
username: string,
3+
password: string
4+
): Promise<boolean> => {
25
const body = JSON.stringify({
36
username,
47
password
58
});
6-
const result = fetch('http://localhost:8080/login', {
9+
const result = fetch('https://localhost:8080/login', {
710
method: 'POST',
811
credentials: 'include',
912
headers: {
@@ -16,25 +19,30 @@ export const sessionIsCreated = (username: string, password: string): Promise<bo
1619
})
1720
.then(data => {
1821
console.log('the data', data);
19-
if (data.sessionId && typeof data.sessionId === 'string') { // check that a session id was passed down
22+
if (data.sessionId && typeof data.sessionId === 'string') {
23+
// check that a session id was passed down
2024
return true;
2125
}
2226
return false;
2327
})
2428
.catch(err => {
2529
console.log(err);
26-
return false
30+
return false;
2731
});
2832
return result;
29-
}
33+
};
3034

31-
export const newUserIsCreated = (username: string, email: string, password: string): Promise<boolean> => {
35+
export const newUserIsCreated = (
36+
username: string,
37+
email: string,
38+
password: string
39+
): Promise<boolean> => {
3240
const body = JSON.stringify({
3341
username,
3442
email,
3543
password
3644
});
37-
const result = fetch('http://localhost:8080/signup', {
45+
const result = fetch('https://localhost:8080/signup', {
3846
method: 'POST',
3947
credentials: 'include',
4048
headers: {
@@ -47,14 +55,35 @@ export const newUserIsCreated = (username: string, email: string, password: stri
4755
})
4856
.then(data => {
4957
console.log('the data', data);
50-
if (data.sessionId && typeof data.sessionId === 'string') { // check that a session id was passed down
58+
if (data.sessionId && typeof data.sessionId === 'string') {
59+
// check that a session id was passed down
5160
return true;
5261
}
5362
return false;
5463
})
5564
.catch(err => {
5665
console.log(err);
57-
return false
66+
return false;
67+
});
68+
return result;
69+
};
70+
71+
export const githubOauth = (): Promise<boolean> => {
72+
const result = fetch('https://github.com/login/oauth/authorize', {
73+
method: 'GET',
74+
mode: 'no-cors',
75+
params: {
76+
client_id: process.env.GITHUB_ID
77+
}
78+
})
79+
.then(res => res.json())
80+
.then(data => {
81+
console.log('Data from github oauth', data);
82+
return true;
83+
})
84+
.catch(err => {
85+
console.log('Error from github oauth', err);
86+
return false;
5887
});
5988
return result;
60-
}
89+
};

0 commit comments

Comments
 (0)