Skip to content

Commit eae5e66

Browse files
author
Sachin Maheshwari
committed
redirect with token once user is already logged in
1 parent 9a4ded1 commit eae5e66

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,29 +240,15 @@ const authSetup = function () {
240240
const redirectToApp = function () {
241241
logger("redirect to app", appUrl);
242242
if (appUrl) {
243-
if (appUrl.indexOf(discord_pattern) > -1) {
244-
try {
245-
var newUrl = new URL(appUrl);
246-
newUrl.searchParams.append(
247-
"token",
248-
getCookie(v3JWTCookie)
249-
);
250-
window.location = newUrl.href;
251-
} catch (e) {
252-
logger("Error in redirect to discord", e.message);
253-
window.location = appUrl;
254-
}
255-
} else {
256-
window.location = appUrl;
257-
}
243+
hookRedirect(appUrl);
258244
}
259245
};
260246

261247
const postLogin = function () {
262248
if (isLoggedIn() && returnAppUrl) {
263249
auth0.isAuthenticated().then(function (isAuthenticated) {
264250
if (isAuthenticated) {
265-
window.location = returnAppUrl;
251+
hookRedirect(returnAppUrl);
266252
} else {
267253
login(); // old session exist case
268254
}
@@ -718,6 +704,24 @@ const authSetup = function () {
718704
}
719705
};
720706

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+
721725
// execute
722726
init();
723727
};

0 commit comments

Comments
 (0)