Skip to content

Commit

Permalink
Merge pull request #29 from pazdera/electron-xauth
Browse files Browse the repository at this point in the history
Disable cross auth in electron where we have the benefit of shared local storage
  • Loading branch information
pazdera authored Mar 21, 2017
2 parents c9e68a9 + a8e64ef commit e6257bc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/core/auth.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
var token = null,
session = null,
isKW,
isElectron,
auth,
xdAuth;

module.exports = function (config) {
config = config ? config : require('../config');
isKW = config.WORLD_URL.indexOf(location.origin.replace(/(http:|https:)/, '')) !== -1;
isElectron = navigator.userAgent.indexOf("Electron") > -1;

apiService = require('./kano-api')(config);
xdAuth = require('./xd-auth')(config);
Expand All @@ -23,7 +25,7 @@ module.exports = function (config) {
} else {
localStorage.setItem('KW_TOKEN', token);
}
if (!disableCross && !isKW) {
if (!disableCross && !isKW && !isElectron) {
xdAuth.setToken(token);
}
},
Expand All @@ -39,7 +41,7 @@ module.exports = function (config) {
logout: function (reload) {
reload = typeof reload === 'undefined' ? true : reload;
auth.setToken(null);
if (!isKW) {
if (!isKW && !isElectron) {
xdAuth.crossLogout(function (err) {
if (reload) {
location.reload();
Expand Down Expand Up @@ -68,8 +70,8 @@ module.exports = function (config) {
});
}

// The current website is KW, we read directly the locaStorage
if (isKW) {
// The current website is either KW or running inside Electron, we read directly the locaStorage
if (isKW || isElectron) {
p = onToken(token || localStorage.getItem('KW_TOKEN'));
}
// Otherwise, contact KW to get the toekn throught the iframe
Expand Down

0 comments on commit e6257bc

Please sign in to comment.