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