Skip to content

feat: forward retUrl to onboard app for specific regSource's #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ workflows:
only:
- dev
- hotfix/resendActivationEmail
- feat/plat-320

# Production builds are exectuted only on tagged commits to the
# master branch.
Expand Down
28 changes: 18 additions & 10 deletions web-assets/auth0/dev-tenant/rules/onboardingChecklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,27 @@ function (user, context, callback) {

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

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

for (let checklistTrait of onboardingChecklistTrait.data) {
if (
checklistTrait.onboarding_wizard != null &&
(checklistTrait.onboarding_wizard.status != null || // any valid status indicates user has already seen onboarding wizard and needn't be shown again.
checklistTrait.onboarding_wizard.skip) // for certain signup routes skip is set to true, and thus onboarding wizard needn't be shown
) {
if (checklistTrait.onboarding_wizard != null) {
if ( checklistTrait.onboarding_wizard.status !== 'pending_at_user' || // any non pending_at_user status indicates OB was either seen or completed and can be skipped
checklistTrait.onboarding_wizard.skip ||// for certain signup routes skip is set to true, and thus onboarding wizard needn't be shown
checklistTrait.onboarding_wizard.override === 'skip')
{
return callback(null, user, context);
} else if (checklistTrait.onboarding_wizard.override === 'useRetUrl') {
override = 'useRetUrl';
}
}
}

const profileCompletedData = onboardingChecklistTrait.data.length > 0 ? onboardingChecklistTrait.data[0].profile_completed : null;

if (profileCompletedData) {
Expand All @@ -137,8 +141,12 @@ function (user, context, callback) {
}

// All checks failed - indicating user newly registered and needs to be shown the onboarding wizard
console.log('rule:onboarding-checklist: set show_onboarding_wizard');
context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'show_onboarding_wizard'] = true;
console.log('rule:onboarding-checklist: set onboarding_wizard ' + override);

context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'onboarding_wizard'] = override;



return callback(null, user, context);
} catch (e) {
console.log("rule:onboarding-checklist:Error in fetching onboarding_checklist", e);
Expand Down
18 changes: 11 additions & 7 deletions web-assets/js/setupAuth0WithRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const authSetup = function () {

const redirectToOnboardingWizard = function () {
logger("redirect to onboarding wizard");
window.location = onboardingWizardUrl;
window.location = onboardingWizardUrl
}

const redirectToApp = function () {
Expand Down Expand Up @@ -271,9 +271,9 @@ const authSetup = function () {
let showOnboardingWizard = false;
Object.keys(claims).forEach(key => {
logger('Checking key', key);
if (key.indexOf('show_onboarding_wizard') !== -1) {
if (claims[key]) {
showOnboardingWizard = true;
if (key.indexOf('onboarding_wizard') !== -1) {
if (claims[key] === 'show' || claims[key] === 'useRetUrl') {
showOnboardingWizard = claims[key];
}
}
});
Expand Down Expand Up @@ -314,9 +314,13 @@ const authSetup = function () {
}

if (showOnboardingWizard) {
logger('Take user to onboarding wizard');
redirectToOnboardingWizard();
} else {
logger('Take user to onboarding wizard', showOnboardingWizard);
if (showOnboardingWizard === 'useRetUrl') {
setCookie('returnAfterOnboard', qs['appUrl'] || qs['retUrl'])
}
redirectToOnboardingWizard(returnAppUrl);
}
else {
// session still active, but app calling login
if (!appUrl && returnAppUrl) {
appUrl = returnAppUrl
Expand Down