Skip to content

Commit a0f0d41

Browse files
author
sachin-maheshwari
authored
Merge pull request #278 from rakibansary/feat/onboard-wizard
fix: read flag from claims
2 parents fc83ca7 + e58f564 commit a0f0d41

File tree

2 files changed

+60
-47
lines changed

2 files changed

+60
-47
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 & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -263,60 +263,73 @@ const authSetup = function () {
263263
}
264264

265265
const storeToken = function () {
266-
auth0.getUser().then(function (user) {
267-
auth0.getIdTokenClaims().then(function (claims) {
268-
logger("claims...", claims);
269-
idToken = claims.__raw;
270-
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 = '';
271293
Object.keys(claims).findIndex(function (key) {
272-
if (key.includes('active')) {
273-
userActive = claims[key];
294+
if (key.includes(tcSSOCookie)) {
295+
tcsso = claims[key];
274296
return true;
275297
}
276298
return false;
277299
});
278-
if (userActive) {
279-
let tcsso = '';
280-
Object.keys(claims).findIndex(function (key) {
281-
if (key.includes(tcSSOCookie)) {
282-
tcsso = claims[key];
283-
return true;
284-
}
285-
return false;
286-
});
287-
logger('Storing token...', true);
288-
try {
289-
const exT = getCookieExpiry(idToken);
290-
if (exT) {
291-
setDomainCookie(tcJWTCookie, idToken, exT);
292-
setDomainCookie(v3JWTCookie, idToken, exT);
293-
setDomainCookie(tcSSOCookie, tcsso, exT);
294-
} else {
295-
setCookie(tcJWTCookie, idToken, cookieExpireIn);
296-
setCookie(v3JWTCookie, idToken, cookieExpireIn);
297-
setCookie(tcSSOCookie, tcsso, cookieExpireIn);
298-
}
299-
} catch (e) {
300-
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);
301311
}
312+
} catch (e) {
313+
logger('Error occured in fecthing token expiry time', e.message);
314+
}
302315

303-
if (user.show_onboarding_wizard) {
304-
redirectToOnboardingWizard();
305-
} else {
306-
// session still active, but app calling login
307-
if (!appUrl && returnAppUrl) {
308-
appUrl = returnAppUrl
309-
}
310-
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
311323
}
312-
} else {
313-
logger("User active ? ", userActive);
314-
host = registerSuccessUrl;
315-
logout();
324+
redirectToApp();
316325
}
317-
}).catch(function (e) {
318-
logger("Error in fetching token from auth0: ", e);
319-
});
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);
320333
});
321334
};
322335

0 commit comments

Comments
 (0)