File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -714,13 +714,27 @@ export class OAuthHandler<
714714 queryParams : Record < string , string > = { }
715715 ) {
716716 // If this exists, it should be a redirect back to the app
717- const redirectBackUrl = this . _getStateParam ( ) || process . env . FE_URL
717+ const redirectBackUrl = this . _getStateParam ( ) || process . env . FE_URL || ''
718718
719+ // Create a URL object from the redirect back URL
720+ const url = new URL ( redirectBackUrl )
721+
722+ // Check if 'oAuthError' is in queryParams
723+ if ( 'oAuthError' in queryParams ) {
724+ // Clear any existing search parameters
725+ url . search = ''
726+ }
727+
728+ // Create a URLSearchParams object from the new query parameters
719729 const queryString = new URLSearchParams ( queryParams ) . toString ( )
730+
731+ // If url already has query parameters, append with '&' else append with '?'
732+ url . search += ( url . search ? '&' : '?' ) + queryString
733+
720734 return [
721735 body ,
722736 {
723- location : ` ${ redirectBackUrl } ${ queryString && '?' } ${ queryString } ` ,
737+ location : url . toString ( ) ,
724738 ...headers ,
725739 } ,
726740 {
You can’t perform that action at this time.
0 commit comments