Skip to content

Commit 5983e2a

Browse files
author
Sachin Maheshwari
committed
refresh iframe
1 parent a992169 commit 5983e2a

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ const authSetup = function () {
6969
? 'localstorage'
7070
: 'memory',
7171
useRefreshTokens: useRefreshTokens
72-
}).then(_init);
72+
}).then(_init).catch(function (e) {
73+
logger("Error occurred in initializing auth0 object: ", e);
74+
window.location.reload();
75+
});
7376
window.addEventListener("message", receiveMessage, false);
7477
};
7578

@@ -218,7 +221,7 @@ const authSetup = function () {
218221
}
219222

220223
const isLoggedIn = function () {
221-
var token = getCookie(tcJWTCookie);
224+
var token = getCookie(v3JWTCookie);
222225
return token ? !isTokenExpired(token) : false;
223226
};
224227

@@ -468,38 +471,27 @@ const authSetup = function () {
468471
});
469472
};
470473

474+
const getToken = function (aObj) {
475+
aObj.getTokenSilently({ timeoutInSeconds: 60 }).then(function (token) {
476+
storeRefreshedToken(aObj);
477+
}).catch(function (err) {
478+
logger("receiveMessage: Error in refreshing token through iframe:", err)
479+
informIt(failed);
480+
});
481+
482+
};
483+
471484
// main execution start here
472485
if (token && !isTokenExpired(token)) {
473486
informIt(success);
487+
} else if (!token) {
488+
informIt(failed);
474489
} else {
475-
createAuth0Client({
476-
domain: domain,
477-
client_id: clientId,
478-
cacheLocation: useLocalStorage
479-
? 'localstorage'
480-
: 'memory',
481-
useRefreshTokens: useRefreshTokens
482-
}).then(function (aObj) {
483-
aObj.isAuthenticated().then(function (isAuthenticated) {
484-
if (isAuthenticated) {
485-
aObj.getTokenSilently().then(function (token) {
486-
storeRefreshedToken(aObj);
487-
}).catch(function (err) {
488-
logger("receiveMessage: Error in refreshing token through iframe:", err)
489-
informIt(failed);
490-
});
491-
} else {
492-
logger("authenticated ?", isAuthenticated);
493-
informIt(failed);
494-
}
495-
}).catch(function (err) {
496-
logger("receiveMessage: Error occured in checkng authentication", err);
497-
informIt(failed);
498-
});
499-
}).catch(function (err) {
500-
logger("receiveMessage: Error occured in initializing auth0", err);
490+
if (auth0) {
491+
getToken(auth0);
492+
} else {
501493
informIt(failed);
502-
});
494+
}
503495
}
504496
} catch (e) {
505497
logger("error occured in iframe handler:", e.message);

0 commit comments

Comments
 (0)