Skip to content

Commit 5d1dc6b

Browse files
author
Emmanouil Konstantinidis
committed
Handle both callbacks
1 parent 719d61b commit 5d1dc6b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/js/components/login.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ var Login = React.createClass({
3535
var authUrl = githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scope;
3636
authWindow.loadUrl(authUrl);
3737

38+
authWindow.webContents.on('will-navigate', function (event, url) {
39+
handleCallback(url);
40+
});
41+
3842
authWindow.webContents.on('did-get-redirect-request', function (event, oldUrl, newUrl) {
43+
handleCallback(newUrl);
44+
});
3945

40-
var raw_code = /code=([^&]*)/.exec(newUrl) || null;
46+
function handleCallback (url) {
47+
var raw_code = /code=([^&]*)/.exec(url) || null;
4148
var code = (raw_code && raw_code.length > 1) ? raw_code[1] : null;
42-
var error = /\?error=(.+)$/.exec(newUrl);
49+
var error = /\?error=(.+)$/.exec(url);
4350

4451
if (code || error) {
4552
// Close the browser if code found or error
@@ -53,8 +60,7 @@ var Login = React.createClass({
5360
alert('Oops! Something went wrong and we couldn\'t' +
5461
'log you in using Github. Please try again.');
5562
}
56-
57-
});
63+
}
5864

5965
// If "Done" button is pressed, hide "Loading"
6066
authWindow.on('close', function () {

0 commit comments

Comments
 (0)