@@ -63,8 +63,8 @@ async function createWindow() {
63
63
// icon: path.join(__dirname, '../src/public/icons/png/256x256.png'),
64
64
webPreferences : {
65
65
zoomFactor : 0.7 ,
66
- // enable devtools
67
- devTools : true ,
66
+ // enable devtools when in development mode
67
+ devTools : isDev ,
68
68
// crucial security feature - blocks rendering process from having access to node moduels
69
69
nodeIntegration : false ,
70
70
// web workers will not have access to node
@@ -220,8 +220,8 @@ app.on('web-contents-created', (event, contents) => {
220
220
const parsedUrl = new URL ( navigationUrl ) ;
221
221
const validOrigins = [
222
222
selfHost ,
223
- 'http://localhost:8081 ' ,
224
- 'http ://reactype.heroku .com' ,
223
+ 'http://localhost:5000 ' ,
224
+ 'https ://reactype.herokuapp .com' ,
225
225
'https://github.com/'
226
226
] ;
227
227
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
@@ -241,9 +241,8 @@ app.on('web-contents-created', (event, contents) => {
241
241
//console.log('parsedUrl.origin is', parsedUrl.origin);
242
242
const validOrigins = [
243
243
selfHost ,
244
- 'http://localhost:8081' ,
245
244
'http://localhost:5000' ,
246
- 'http ://reactype.heroku .com' ,
245
+ 'https ://reactype.herokuapp .com' ,
247
246
'https://github.com' ,
248
247
'app://rse/'
249
248
] ;
@@ -329,10 +328,16 @@ ipcMain.on('choose_app_dir', event => {
329
328
. catch ( err => console . log ( 'ERROR on "choose_app_dir" event: ' , err ) ) ;
330
329
} ) ;
331
330
331
+ // define serverURL for cookie and auth purposes based on environment
332
+ let serverUrl = 'https://reactype.herokuapp.com' ;
333
+ if ( isDev ) {
334
+ serverUrl = 'http://localhost:5000' ;
335
+ }
336
+
332
337
// 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
333
338
ipcMain . on ( 'set_cookie' , event => {
334
339
session . defaultSession . cookies
335
- . get ( { url : 'https://reactype.heroku.com' } )
340
+ . get ( { url : serverUrl } )
336
341
. then ( cookie => {
337
342
console . log ( cookie ) ;
338
343
event . reply ( 'give_cookie' , cookie ) ;
@@ -345,12 +350,47 @@ ipcMain.on('set_cookie', event => {
345
350
// again for production, document.cookie is not accessible so we need this listener on main to delete the cookie on logout
346
351
ipcMain . on ( 'delete_cookie' , event => {
347
352
session . defaultSession . cookies
348
- . remove ( 'https://reactype.heroku.com' , 'ssid' )
353
+ . remove ( serverUrl , 'ssid' )
349
354
. then ( removed => {
350
355
console . log ( 'Cookies deleted' , removed ) ;
351
356
} )
352
357
. catch ( err => console . log ( 'Error deleting cookie:' , err ) ) ;
353
358
} ) ;
354
359
355
- // bypass ssl certification validation error
356
- // app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
360
+ // opens new window for github oauth when button on signin page is clicked
361
+ ipcMain . on ( 'github' , event => {
362
+ // create new browserwindow object with size, title, security options
363
+ const github = new BrowserWindow ( {
364
+ width : 800 ,
365
+ height : 600 ,
366
+ title : 'Github Oauth' ,
367
+ webPreferences : {
368
+ nodeIntegration : false ,
369
+ nodeIntegrationInWorker : false ,
370
+ nodeIntegrationInSubFrames : false ,
371
+ contextIsolation : true ,
372
+ enableRemoteModule : false ,
373
+ zoomFactor : 1.0
374
+ }
375
+ } ) ;
376
+ // redirects to relevant server endpoint
377
+ github . loadURL ( `${ serverUrl } /github` ) ;
378
+ // show window
379
+ github . show ( ) ;
380
+ // if final callback is reached and we get a redirect from server back to our app, close oauth window
381
+ github . webContents . on ( 'will-redirect' , ( e , callbackUrl ) => {
382
+ let redirectUrl = 'app://rse/' ;
383
+ if ( isDev ) {
384
+ redirectUrl = 'http://localhost:8080/' ;
385
+ }
386
+ if ( callbackUrl === redirectUrl ) {
387
+ dialog . showMessageBox ( {
388
+ type : 'info' ,
389
+ title : 'ReacType' ,
390
+ icon : resolve ( 'app/src/public/icons/png/256x256.png' ) ,
391
+ message : 'Github Oauth Successful!'
392
+ } ) ;
393
+ github . close ( ) ;
394
+ }
395
+ } ) ;
396
+ } ) ;
0 commit comments