Skip to content

Commit b0e3143

Browse files
author
sachin-maheshwari
authored
Merge pull request #305 from topcoder-platform/dev
Jira-Plat-700 provide token to discord app
2 parents 2684e04 + ee2fe28 commit b0e3143

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

.circleci/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ workflows:
7070
branches:
7171
only:
7272
- dev
73-
- hotfix/resendActivationEmail
74-
- feat/plat-320
7573

7674
# Production builds are exectuted only on tagged commits to the
7775
# master branch.

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ perl -pi -e "s/\{\{DOMAIN\}\}/$DOMAIN/g" $CONFFILENAME
66
perl -pi -e "s/\{\{AUTH0_CLIENT_ID\}\}/$AUTH0_CLIENT_ID/g" $CONFFILENAME
77
perl -pi -e "s/\{\{LOGGERMODE\}\}/$LOGGERMODE/g" $CONFFILENAME
88
perl -pi -e "s/\{\{AUTH0DOMAIN\}\}/$AUTH0DOMAIN/g" $CONFFILENAME
9+
perl -pi -e "s/\{\{DISCORD_URL_PATTERN\}\}/$DISCORD_URL_PATTERN/g" $CONFFILENAME
910

1011
SIGNUPFILENAME="./web-assets/js/signup.js"
1112
perl -pi -e "s/\{\{DOMAIN\}\}/$DOMAIN/g" $SIGNUPFILENAME

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const authSetup = function () {
4646
const mode = qs['mode'] || 'signIn';
4747
let returnAppUrl = handleSpecificReturnUrl(qs['retUrl'], 'retUrl');
4848
let appUrl = qs['appUrl'] || false;
49+
const discord_pattern = '{{DISCORD_URL_PATTERN}}';
4950

5051
if (utmSource &&
5152
(utmSource != 'undefined') &&
@@ -237,17 +238,17 @@ const authSetup = function () {
237238
}
238239

239240
const redirectToApp = function () {
240-
logger("redirect to app", appUrl);
241-
if (appUrl) {
242-
window.location = appUrl;
243-
}
241+
logger("redirect to app", appUrl);
242+
if (appUrl) {
243+
hookRedirect(appUrl);
244+
}
244245
};
245246

246247
const postLogin = function () {
247248
if (isLoggedIn() && returnAppUrl) {
248249
auth0.isAuthenticated().then(function (isAuthenticated) {
249250
if (isAuthenticated) {
250-
window.location = returnAppUrl;
251+
hookRedirect(returnAppUrl);
251252
} else {
252253
login(); // old session exist case
253254
}
@@ -703,6 +704,24 @@ const authSetup = function () {
703704
}
704705
};
705706

707+
function hookRedirect(redirect_url) {
708+
if (redirect_url && (redirect_url.indexOf(discord_pattern) > -1)) {
709+
try {
710+
var newUrl = new URL(redirect_url);
711+
newUrl.searchParams.append(
712+
"token",
713+
getCookie(v3JWTCookie)
714+
);
715+
window.location = newUrl.href;
716+
} catch (e) {
717+
logger("Error in redirecting to discord", e.message);
718+
window.location = redirect_url;
719+
}
720+
} else {
721+
window.location = redirect_url;
722+
}
723+
}
724+
706725
// execute
707726
init();
708727
};

0 commit comments

Comments
 (0)