Skip to content

Commit 51e355f

Browse files
author
sachin-maheshwari
authored
Merge pull request #302 from topcoder-platform/dev
Plat-320, onboarding rule changes
2 parents 9fb883c + ef12302 commit 51e355f

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
function (user, context, callback) {
22
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) {
33
console.log("rule:onboarding-checklist:enter");
4-
console.log("rule:onboarding-checklist:context.request", context.request);
5-
6-
if (context.redirect) {
4+
5+
if (context.redirect) {
76
console.log("rule:onboarding-checklist:exiting due to context being a redirect");
87
return callback(null, user, context);
98
}
@@ -22,16 +21,11 @@ function (user, context, callback) {
2221
return callback(null, user, context);
2322
}
2423

25-
let handle = _.get(user, "handle", null);
26-
const provider = _.get(user, "identities[0].provider", null);
27-
if (isSocial || (!handle && provider === "auth0")) {
28-
handle = _.get(user, "nickname", null);
29-
}
30-
31-
console.log("rule:onboarding-checklist: fetch onboarding_checklist for email/handle: ", user.email, handle, provider);
24+
const handle = context.idToken[global.AUTH0_CLAIM_NAMESPACE + 'handle'];
25+
console.log("rule:onboarding-checklist: fetch onboarding_checklist for email/handle: ", user.email, handle);
3226

33-
// TODO: Properly fetch handle for social logins
34-
if (handle == null || isSocial) {
27+
if (handle == null) {
28+
console.log("rule:onboarding-checklist: exiting due to handle being null.");
3529
return callback(null, user, context);
3630
}
3731

@@ -111,24 +105,28 @@ function (user, context, callback) {
111105

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

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

121116
for (let checklistTrait of onboardingChecklistTrait.data) {
122-
if (
123-
checklistTrait.onboarding_wizard != null &&
124-
(checklistTrait.onboarding_wizard.status != null || // any valid status indicates user has already seen onboarding wizard and needn't be shown again.
125-
checklistTrait.onboarding_wizard.skip) // for certain signup routes skip is set to true, and thus onboarding wizard needn't be shown
126-
) {
117+
if (checklistTrait.onboarding_wizard != null) {
118+
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
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+
{
127122
return callback(null, user, context);
123+
} else if (checklistTrait.onboarding_wizard.override === 'useRetUrl') {
124+
override = 'useRetUrl';
128125
}
126+
}
129127
}
130-
131-
const profileCompletedData = onboardingChecklistTrait.data[0].profile_completed;
128+
129+
const profileCompletedData = onboardingChecklistTrait.data.length > 0 ? onboardingChecklistTrait.data[0].profile_completed : null;
132130

133131
if (profileCompletedData) {
134132
if (profileCompletedData.status === "completed") {
@@ -143,8 +141,12 @@ function (user, context, callback) {
143141
}
144142

145143
// All checks failed - indicating user newly registered and needs to be shown the onboarding wizard
146-
console.log('rule:onboarding-checklist: set show_onboarding_wizard', user);
147-
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+
148150
return callback(null, user, context);
149151
} catch (e) {
150152
console.log("rule:onboarding-checklist:Error in fetching onboarding_checklist", e);

0 commit comments

Comments
 (0)