Skip to content

Commit d3a605d

Browse files
committed
if we're redirecting with an error, clear all other query params
1 parent 2cf6e0d commit d3a605d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

api/src/OAuthHandler.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)