Skip to content

Commit d001f9e

Browse files
committed
github oauth implementation
1 parent 54a7b32 commit d001f9e

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

app/electron/main.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ ipcMain.on('choose_app_dir', event => {
326326
// 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
327327
ipcMain.on('set_cookie', event => {
328328
session.defaultSession.cookies
329-
.get({ url: 'https://reactype.heroku.com' })
329+
.get({ url: 'https://reactype.herokuapp.com' })
330330
.then(cookie => {
331331
console.log(cookie);
332332
event.reply('give_cookie', cookie);
@@ -339,12 +339,9 @@ ipcMain.on('set_cookie', event => {
339339
// again for production, document.cookie is not accessible so we need this listener on main to delete the cookie on logout
340340
ipcMain.on('delete_cookie', event => {
341341
session.defaultSession.cookies
342-
.remove('https://reactype.heroku.com', 'ssid')
342+
.remove('https://reactype.herokuapp.com', 'ssid')
343343
.then(removed => {
344344
console.log('Cookies deleted', removed);
345345
})
346346
.catch(err => console.log('Error deleting cookie:', err));
347347
});
348-
349-
// bypass ssl certification validation error
350-
// app.commandLine.appendSwitch('ignore-certificate-errors', 'true');

app/electron/preload.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
setCookie,
1212
getCookie,
1313
delCookie,
14-
reload
14+
github
1515
} = require('./preloadFunctions/cookies');
1616

1717
// Expose protected methods that allow the renderer process to use select node methods
@@ -33,5 +33,6 @@ contextBridge.exposeInMainWorld('api', {
3333
writeFile,
3434
setCookie,
3535
getCookie,
36-
delCookie
36+
delCookie,
37+
github
3738
});

app/electron/preloadFunctions/cookies.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ const delCookie = () => {
1414
return ipcRenderer.send('delete_cookie');
1515
};
1616

17-
module.exports = { setCookie, getCookie, delCookie };
17+
const github = () => {
18+
return ipcRenderer.send('github');
19+
};
20+
21+
module.exports = { setCookie, getCookie, delCookie, github };

app/src/components/login/SignIn.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
8080
const [invalidUser, setInvalidUser] = useState(false);
8181
const [invalidPass, setInvalidPass] = useState(false);
8282

83+
useEffect(() => {
84+
setInterval(() => {
85+
window.api.setCookie();
86+
window.api.getCookie(cookie => {
87+
if (cookie[0]) {
88+
window.localStorage.setItem('ssid', cookie[0].value);
89+
props.history.push('/');
90+
clearInterval();
91+
}
92+
});
93+
}, 2000);
94+
}, []);
95+
8396
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
8497
let inputVal = e.target.value;
8598
switch (e.target.name) {
@@ -203,25 +216,18 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
203216
Sign In
204217
</Button>
205218
{/* Hiding github oauth button as it's still buggy and not fully working */}
206-
{/* <Button
219+
<Button
207220
fullWidth
208221
variant="contained"
209222
color="default"
210223
className={classes.submit}
211-
href="https://reactype.heroku.com/github"
212224
onClick={() => {
213225
console.log('Inside onclick of github');
214-
setTimeout(() => {
215-
window.api.setCookie();
216-
window.api.getCookie(cookie => {
217-
window.localStorage.setItem('ssid', cookie[0].value);
218-
props.history.push('/');
219-
});
220-
}, 2000);
226+
window.api.github();
221227
}}
222228
>
223229
<GitHubIcon />
224-
</Button> */}
230+
</Button>
225231

226232
<Button
227233
fullWidth

0 commit comments

Comments
 (0)