From 964e078c3ff2f511999597d51e4531267410be6e Mon Sep 17 00:00:00 2001 From: simeng-li Date: Mon, 3 Apr 2023 17:41:22 +0800 Subject: [PATCH] refactor(ui): replace plain search string concatenate (#3663) replace plain search string concatenate with URLSearchParams instances --- .../ui/src/hooks/use-social-callback-handler.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/ui/src/hooks/use-social-callback-handler.ts b/packages/ui/src/hooks/use-social-callback-handler.ts index c0f3006be..47ab95b84 100644 --- a/packages/ui/src/hooks/use-social-callback-handler.ts +++ b/packages/ui/src/hooks/use-social-callback-handler.ts @@ -8,16 +8,14 @@ const useSocialCallbackHandler = () => { const socialCallbackHandler = useCallback( (connectorId: string) => { - // Get search string to evaluate - const searchString = window.location.search; + // Get search parameter to evaluate + const searchParams = new URLSearchParams(window.location.search); + // Get hash parameter to evaluate + const hashParams = new URLSearchParams(window.location.hash.slice(1)); - // Get hash string to evaluate - const hashString = window.location.hash; - - // Define evaluated search string - const search = `${searchString || '?'}${ - searchString && hashString ? '&' : '' - }${hashString.slice(1)}`; + // Join search and hash parameters + const joinedSearchParams = new URLSearchParams([...searchParams, ...hashParams]); + const search = joinedSearchParams.toString() ? `?${joinedSearchParams.toString()}` : ''; // Get native callback link from storage const callbackLink = getCallbackLinkFromStorage(connectorId);