@@ -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