Skip to content

Commit f0bc569

Browse files
committed
fix: read flag from claims
1 parent 1eb28e1 commit f0bc569

File tree

2 files changed

+60
-46
lines changed

2 files changed

+60
-46
lines changed

web-assets/auth0/dev-tenant/rules/onboardingChecklist.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function (user, context, callback) {
9595

9696
if (data.length === 0) {
9797
// User doesn't have any traits with traitId onboarding_checklist and should be shown the onboarding wizard
98-
user.show_onboarding_wizard = true;
98+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'show_onboarding_wizard'] = false;
9999
console.log('rule:onboarding-checklist:Setting show_onboarding_wizard to true', user);
100100
return callback(null, user, context);
101101
}
@@ -128,7 +128,7 @@ function (user, context, callback) {
128128

129129
// All checks failed - indicating user newly registered and needs to be shown the onboarding wizard
130130
console.log('rule:onboarding-checklist: set show_onboarding_wizard', user);
131-
user.show_onboarding_wizard = true;
131+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'show_onboarding_wizard'] = false;
132132
return callback(null, user, context);
133133
} catch (e) {
134134
console.log("rule:onboarding-checklist:Error in fetching onboarding_checklist", e);

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -263,59 +263,73 @@ const authSetup = function () {
263263
}
264264

265265
const storeToken = function () {
266-
auth0.getUser().then(function (user) {
267-
auth0.getIdTokenClaims().then(function (claims) {
268-
idToken = claims.__raw;
269-
let userActive = false;
266+
auth0.getIdTokenClaims().then(function (claims) {
267+
idToken = claims.__raw;
268+
269+
logger.info('Claims', JSON.stringify(claims));
270+
271+
let showOnboardingWizard = false;
272+
Object.keys(claims).forEach(key => {
273+
logger.info('Checking key', key);
274+
if (key.indexOf('show_onboarding_wizard') !== -1) {
275+
if (claims[key]) {
276+
showOnboardingWizard = true;
277+
}
278+
}
279+
});
280+
281+
logger.info('Show Onboarding Wizard', showOnboardingWizard);
282+
283+
let userActive = false;
284+
Object.keys(claims).findIndex(function (key) {
285+
if (key.includes('active')) {
286+
userActive = claims[key];
287+
return true;
288+
}
289+
return false;
290+
});
291+
if (userActive) {
292+
let tcsso = '';
270293
Object.keys(claims).findIndex(function (key) {
271-
if (key.includes('active')) {
272-
userActive = claims[key];
294+
if (key.includes(tcSSOCookie)) {
295+
tcsso = claims[key];
273296
return true;
274297
}
275298
return false;
276299
});
277-
if (userActive) {
278-
let tcsso = '';
279-
Object.keys(claims).findIndex(function (key) {
280-
if (key.includes(tcSSOCookie)) {
281-
tcsso = claims[key];
282-
return true;
283-
}
284-
return false;
285-
});
286-
logger('Storing token...', true);
287-
try {
288-
const exT = getCookieExpiry(idToken);
289-
if (exT) {
290-
setDomainCookie(tcJWTCookie, idToken, exT);
291-
setDomainCookie(v3JWTCookie, idToken, exT);
292-
setDomainCookie(tcSSOCookie, tcsso, exT);
293-
} else {
294-
setCookie(tcJWTCookie, idToken, cookieExpireIn);
295-
setCookie(v3JWTCookie, idToken, cookieExpireIn);
296-
setCookie(tcSSOCookie, tcsso, cookieExpireIn);
297-
}
298-
} catch (e) {
299-
logger('Error occured in fecthing token expiry time', e.message);
300+
logger('Storing token...', true);
301+
try {
302+
const exT = getCookieExpiry(idToken);
303+
if (exT) {
304+
setDomainCookie(tcJWTCookie, idToken, exT);
305+
setDomainCookie(v3JWTCookie, idToken, exT);
306+
setDomainCookie(tcSSOCookie, tcsso, exT);
307+
} else {
308+
setCookie(tcJWTCookie, idToken, cookieExpireIn);
309+
setCookie(v3JWTCookie, idToken, cookieExpireIn);
310+
setCookie(tcSSOCookie, tcsso, cookieExpireIn);
300311
}
312+
} catch (e) {
313+
logger('Error occured in fecthing token expiry time', e.message);
314+
}
301315

302-
if (user.show_onboarding_wizard) {
303-
redirectToOnboardingWizard();
304-
} else {
305-
// session still active, but app calling login
306-
if (!appUrl && returnAppUrl) {
307-
appUrl = returnAppUrl
308-
}
309-
redirectToApp();
316+
if (showOnboardingWizard) {
317+
logger.info('Take user to onboarding wizard');
318+
redirectToOnboardingWizard();
319+
} else {
320+
// session still active, but app calling login
321+
if (!appUrl && returnAppUrl) {
322+
appUrl = returnAppUrl
310323
}
311-
} else {
312-
logger("User active ? ", userActive);
313-
host = registerSuccessUrl;
314-
logout();
324+
redirectToApp();
315325
}
316-
}).catch(function (e) {
317-
logger("Error in fetching token from auth0: ", e);
318-
});
326+
} else {
327+
logger("User active ? ", userActive);
328+
host = registerSuccessUrl;
329+
logout();
330+
}
331+
}).catch(function (e) {
332+
logger("Error in fetching token from auth0: ", e);
319333
});
320334
};
321335

0 commit comments

Comments
 (0)