Skip to content

Commit d8e74f9

Browse files
author
Sachin Maheshwari
committed
logic changes
1 parent 7a89b98 commit d8e74f9

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

src/connector-wrapper.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {createFrame} = require('./iframe')
2-
const {getToken} = require ('./token')
2+
const {getToken, isTokenExpired} = require ('./token')
33

44
let iframe = null
55
let loading = null
@@ -36,28 +36,34 @@ const proxyCall = function() {
3636
}
3737

3838
function request() {
39-
return new Promise((resolve, reject) => {
40-
function receiveMessage(e) {
41-
console.log("Received at auth-lib:", e)
42-
const safeFormat = e.data.type === "SUCCESS" || e.data.type === "FAILURE"
43-
if (safeFormat) {
44-
window.removeEventListener('message', receiveMessage)
45-
if (e.data.type === "SUCCESS") {
46-
const token = getToken('v3jwt')
47-
token ? resolve({ token: token }) : reject("v3jwt cookie not found")
48-
}
49-
if (e.data.type === "FAILURE") {
50-
reject("unable to get refesh token")
39+
const token = getToken('v3jwt')
40+
if (token && !isTokenExpired(token, 65)) {
41+
return new Promise((resolve, reject) => {
42+
token ? resolve({ token: token }) : reject("v3jwt cookie not found")
43+
})
44+
} else {
45+
return new Promise((resolve, reject) => {
46+
function receiveMessage(e) {
47+
console.log("Received at auth-lib:", e)
48+
const safeFormat = e.data.type === "SUCCESS" || e.data.type === "FAILURE"
49+
if (safeFormat) {
50+
window.removeEventListener('message', receiveMessage)
51+
if (e.data.type === "SUCCESS") {
52+
token ? resolve({ token: token }) : reject("v3jwt cookie not found")
53+
}
54+
if (e.data.type === "FAILURE") {
55+
reject("unable to get refesh token")
56+
}
5157
}
5258
}
53-
}
5459

55-
window.addEventListener('message', receiveMessage)
60+
window.addEventListener('message', receiveMessage)
5661

57-
const payload = { type: "REFRESH_TOKEN" }
62+
const payload = { type: "REFRESH_TOKEN" }
5863

59-
iframe.contentWindow.postMessage(payload, url)
60-
})
64+
iframe.contentWindow.postMessage(payload, url)
65+
})
66+
}
6167
}
6268

6369
if (loading) {

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,18 +421,28 @@ const authSetup = function () {
421421
type: "SUCCESS"
422422
};
423423
if (e.data.type === "REFRESH_TOKEN") {
424-
auth0.isAuthenticated().then(function (isAuthenticated) {
425-
auth0.getTokenSilently().then(function (token) {
426-
storeToken();
427-
informIt(success, e);
424+
const token = getCookie(v3JWTCookie);
425+
if (token && !isTokenExpired(token, 65)) {
426+
informIt(success, e);
427+
} else if (auth0) {
428+
logger("inside auth0 block", "ok");
429+
auth0.isAuthenticated().then(function (isAuthenticated) {
430+
logger("inside auth0 block isAuthenticated", isAuthenticated);
431+
auth0.getTokenSilently().then(function (token) {
432+
logger("inside auth0 block getTokenSilently", token);
433+
storeToken();
434+
informIt(success, e);
435+
}).catch(function (err) {
436+
logger("receiveMessage: Error in refreshing through ifram token: ", err)
437+
informIt(failed, e);
438+
});
428439
}).catch(function (err) {
429-
logger("receiveMessage: Error in refreshing through ifram token: ", err)
440+
logger("receiveMessage: Error occured in checkng authentication", err);
430441
informIt(failed, e);
431442
});
432-
}).catch(function (err) {
433-
logger("receiveMessage: Error occured in checkng authentication", err);
443+
} else {
434444
informIt(failed, e);
435-
});
445+
}
436446
} else {
437447
informIt(failed, e);
438448
}

0 commit comments

Comments
 (0)