Skip to content
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
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ workflows:
branches:
only:
- dev
- hotfix/resendActivationEmail
- feat/plat-320

# Production builds are exectuted only on tagged commits to the
# master branch.
Expand Down
29 changes: 24 additions & 5 deletions web-assets/js/setupAuth0WithRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const authSetup = function () {
const mode = qs['mode'] || 'signIn';
let returnAppUrl = handleSpecificReturnUrl(qs['retUrl'], 'retUrl');
let appUrl = qs['appUrl'] || false;
const discord_pattern = 'https://tc-topbot-1.herokuapp.com/';

if (utmSource &&
(utmSource != 'undefined') &&
Expand Down Expand Up @@ -237,17 +238,17 @@ const authSetup = function () {
}

const redirectToApp = function () {
logger("redirect to app", appUrl);
if (appUrl) {
window.location = appUrl;
}
logger("redirect to app", appUrl);
if (appUrl) {
hookRedirect(appUrl);
}
};

const postLogin = function () {
if (isLoggedIn() && returnAppUrl) {
auth0.isAuthenticated().then(function (isAuthenticated) {
if (isAuthenticated) {
window.location = returnAppUrl;
hookRedirect(returnAppUrl);
} else {
login(); // old session exist case
}
Expand Down Expand Up @@ -703,6 +704,24 @@ const authSetup = function () {
}
};

function hookRedirect(redirect_url) {
if (redirect_url && (redirect_url.indexOf(discord_pattern) > -1)) {
try {
var newUrl = new URL(redirect_url);
newUrl.searchParams.append(
"token",
getCookie(v3JWTCookie)
);
window.location = newUrl.href;
} catch (e) {
logger("Error in redirecting to discord", e.message);
window.location = redirect_url;
}
} else {
window.location = redirect_url;
}
}

// execute
init();
};