Skip to content

Commit 1eb28e1

Browse files
committed
feat: redirect to onboarding wizard by persisting state in user object
1 parent 763eef1 commit 1eb28e1

File tree

3 files changed

+82
-74
lines changed

3 files changed

+82
-74
lines changed

package.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"name": "@topcoder-platform/tc-auth-lib",
3-
"version": "1.0.2",
4-
"description": "Topcoder Authentication lib ",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8-
},
9-
"repository": {
10-
"type": "git",
11-
"url": "git+https://github.com/topcoder-platform/authlib.git"
12-
},
13-
"keywords": [
14-
"topcoder",
15-
"authentication"
16-
],
17-
"author": "Topcoder Team",
18-
"license": "ISC",
19-
"bugs": {
20-
"url": "https://github.com/topcoder-platform/authlib/issues"
21-
},
22-
"homepage": "https://github.com/topcoder-platform/authlib#readme",
23-
"dependencies": {
24-
"lodash": "^4.17.19"
25-
}
26-
}
2+
"name": "@topcoder-platform/tc-auth-lib",
3+
"version": "1.0.2",
4+
"description": "Topcoder Authentication lib ",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/topcoder-platform/authlib.git"
12+
},
13+
"keywords": [
14+
"topcoder",
15+
"authentication"
16+
],
17+
"author": "Topcoder Team",
18+
"license": "ISC",
19+
"bugs": {
20+
"url": "https://github.com/topcoder-platform/authlib/issues"
21+
},
22+
"homepage": "https://github.com/topcoder-platform/authlib#readme",
23+
"dependencies": {
24+
"lodash": "^4.17.19"
25+
}
26+
}

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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);
45

56
if (context.redirect) {
67
console.log("rule:onboarding-checklist:exiting due to context being a redirect");
@@ -20,7 +21,6 @@ function (user, context, callback) {
2021

2122
const createdAt = _.get(user, "created_at", null);
2223
const thresholdDate = moment(configuration.PROFILE_CREATION_DATE_THRESHOLD, "YYYY-MM-DD");
23-
console.log('rule:onboarding-checklist: PROFILE_CREATION_DATE_THRESHOLD', thresholdDate);
2424

2525
try {
2626
// For users created before thresholdDate, we don't want to check onboarding_checklist
@@ -79,7 +79,6 @@ function (user, context, callback) {
7979
global.AUTH0_CLAIM_NAMESPACE = "https://" + configuration.DOMAIN + "/";
8080
const axios = require('axios@0.19.2');
8181

82-
const redirectUrl = `https://platform.${configuration.DOMAIN}/onboard`;
8382
const options = {
8483
method: 'GET',
8584
url: `https://api.${configuration.DOMAIN}/v5/members/${handle}/traits?traitIds=onboarding_checklist`,
@@ -96,10 +95,8 @@ function (user, context, callback) {
9695

9796
if (data.length === 0) {
9897
// User doesn't have any traits with traitId onboarding_checklist and should be shown the onboarding wizard
99-
context.redirect = {
100-
url: redirectUrl
101-
};
102-
console.log('rule:onboarding-checklist:Setting redirectUrl', redirectUrl);
98+
user.show_onboarding_wizard = true;
99+
console.log('rule:onboarding-checklist:Setting show_onboarding_wizard to true', user);
103100
return callback(null, user, context);
104101
}
105102

@@ -130,10 +127,8 @@ function (user, context, callback) {
130127
}
131128

132129
// All checks failed - indicating user newly registered and needs to be shown the onboarding wizard
133-
context.redirect = {
134-
url: redirectUrl
135-
};
136-
console.log('rule:onboarding-checklist:Setting redirectUrl', redirectUrl);
130+
console.log('rule:onboarding-checklist: set show_onboarding_wizard', user);
131+
user.show_onboarding_wizard = true;
137132
return callback(null, user, context);
138133
} catch (e) {
139134
console.log("rule:onboarding-checklist:Error in fetching onboarding_checklist", e);

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const authSetup = function () {
4444
const mode = qs['mode'] || 'signIn';
4545
let returnAppUrl = handleSpecificReturnUrl(qs['retUrl'], 'retUrl');
4646
let appUrl = qs['appUrl'] || false;
47+
let onboardingWizardUrl = null;
4748

4849
if (utmSource &&
4950
(utmSource != 'undefined') &&
@@ -229,6 +230,12 @@ const authSetup = function () {
229230
return token ? !isTokenExpired(token) : false;
230231
};
231232

233+
const redirectToOnboardingWizard = function () {
234+
logger("redirect to onboarding wizard");
235+
const hostname = window.location.host.replace('www.', '');
236+
window.location = `https://platform.${hostname}/onboard`;
237+
}
238+
232239
const redirectToApp = function () {
233240
logger("redirect to app", appUrl);
234241
if (appUrl) {
@@ -256,53 +263,59 @@ const authSetup = function () {
256263
}
257264

258265
const storeToken = function () {
259-
auth0.getIdTokenClaims().then(function (claims) {
260-
idToken = claims.__raw;
261-
let userActive = false;
262-
Object.keys(claims).findIndex(function (key) {
263-
if (key.includes('active')) {
264-
userActive = claims[key];
265-
return true;
266-
}
267-
return false;
268-
});
269-
if (userActive) {
270-
let tcsso = '';
266+
auth0.getUser().then(function (user) {
267+
auth0.getIdTokenClaims().then(function (claims) {
268+
idToken = claims.__raw;
269+
let userActive = false;
271270
Object.keys(claims).findIndex(function (key) {
272-
if (key.includes(tcSSOCookie)) {
273-
tcsso = claims[key];
271+
if (key.includes('active')) {
272+
userActive = claims[key];
274273
return true;
275274
}
276275
return false;
277276
});
278-
logger('Storing token...', true);
279-
try {
280-
const exT = getCookieExpiry(idToken);
281-
if (exT) {
282-
setDomainCookie(tcJWTCookie, idToken, exT);
283-
setDomainCookie(v3JWTCookie, idToken, exT);
284-
setDomainCookie(tcSSOCookie, tcsso, exT);
285-
} else {
286-
setCookie(tcJWTCookie, idToken, cookieExpireIn);
287-
setCookie(v3JWTCookie, idToken, cookieExpireIn);
288-
setCookie(tcSSOCookie, tcsso, cookieExpireIn);
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);
289300
}
290-
} catch (e) {
291-
logger('Error occured in fecthing token expiry time', e.message);
292-
}
293301

294-
// session still active, but app calling login
295-
if (!appUrl && returnAppUrl) {
296-
appUrl = returnAppUrl
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();
310+
}
311+
} else {
312+
logger("User active ? ", userActive);
313+
host = registerSuccessUrl;
314+
logout();
297315
}
298-
redirectToApp();
299-
} else {
300-
logger("User active ? ", userActive);
301-
host = registerSuccessUrl;
302-
logout();
303-
}
304-
}).catch(function (e) {
305-
logger("Error in fetching token from auth0: ", e);
316+
}).catch(function (e) {
317+
logger("Error in fetching token from auth0: ", e);
318+
});
306319
});
307320
};
308321

0 commit comments

Comments
 (0)