Skip to content

Commit 1b20953

Browse files
committed
feat: redirect to return all after onboarding is completed
1 parent 54d831f commit 1b20953

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,25 @@ function (user, context, callback) {
105105

106106
if (data.length === 0) {
107107
// User doesn't have any traits with traitId onboarding_checklist and should be shown the onboarding wizard
108-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'show_onboarding_wizard'] = true;
109-
console.log('rule:onboarding-checklist:Setting show_onboarding_wizard to true');
108+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'onboarding_wizard'] = 'show';
109+
console.log('rule:onboarding-checklist:Setting onboarding_wizard to show');
110110
return callback(null, user, context);
111111
}
112112

113113
const onboardingChecklistTrait = data.filter((item) => item.traitId === 'onboarding_checklist')[0].traits;
114+
let override = 'show';
114115

115116
for (let checklistTrait of onboardingChecklistTrait.data) {
116-
if (
117-
checklistTrait.onboarding_wizard != null &&
118-
(checklistTrait.onboarding_wizard.status != null || // any valid status indicates user has already seen onboarding wizard and needn't be shown again.
119-
checklistTrait.onboarding_wizard.skip) // for certain signup routes skip is set to true, and thus onboarding wizard needn't be shown
120-
) {
117+
if (checklistTrait.onboarding_wizard != null) {
118+
if ( /* checklistTrait.onboarding_wizard.status != null || */ // any valid status indicates user has already seen onboarding wizard and needn't be shown again.
119+
checklistTrait.onboarding_wizard.skip ||// for certain signup routes skip is set to true, and thus onboarding wizard needn't be shown
120+
checklistTrait.onboarding_wizard.override === 'skip')
121+
{
121122
return callback(null, user, context);
123+
} else if (checklistTrait.onboarding_wizard.override === 'retUrl') {
124+
override = 'retUrl';
122125
}
126+
}
123127
}
124128

125129
const profileCompletedData = onboardingChecklistTrait.data.length > 0 ? onboardingChecklistTrait.data[0].profile_completed : null;
@@ -137,8 +141,12 @@ function (user, context, callback) {
137141
}
138142

139143
// All checks failed - indicating user newly registered and needs to be shown the onboarding wizard
140-
console.log('rule:onboarding-checklist: set show_onboarding_wizard');
141-
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'show_onboarding_wizard'] = true;
144+
console.log('rule:onboarding-checklist: set onboarding_wizard ' + override);
145+
146+
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'onboarding_wizard'] = override;
147+
148+
149+
142150
return callback(null, user, context);
143151
} catch (e) {
144152
console.log("rule:onboarding-checklist:Error in fetching onboarding_checklist", e);

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ const authSetup = function () {
271271
let showOnboardingWizard = false;
272272
Object.keys(claims).forEach(key => {
273273
logger('Checking key', key);
274-
if (key.indexOf('show_onboarding_wizard') !== -1) {
275-
if (claims[key]) {
276-
showOnboardingWizard = true;
274+
if (key.indexOf('onboarding_wizard') !== -1) {
275+
if (claims[key] === 'show' || claims[key] === 'override') {
276+
showOnboardingWizard = claims[key];
277277
}
278278
}
279279
});
@@ -314,9 +314,14 @@ const authSetup = function () {
314314
}
315315

316316
if (showOnboardingWizard) {
317-
logger('Take user to onboarding wizard');
317+
logger('Take user to onboarding wizard', showOnboardingWizard);
318+
if (showOnboardingWizard === 'retUrl') {
319+
logger('Need to persist appUrl', returnAppUrl)
320+
setCookie('returnAfterOnboard', returnAppUrl) // TODO: use localStorage instead?
321+
}
318322
redirectToOnboardingWizard();
319-
} else {
323+
}
324+
else {
320325
// session still active, but app calling login
321326
if (!appUrl && returnAppUrl) {
322327
appUrl = returnAppUrl

0 commit comments

Comments
 (0)