From c094b0358b15afec43a690000ffe0406848a294d Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 3 Oct 2023 11:51:12 -0500 Subject: [PATCH] fix: Encode referrer to handle complex paths --- src/account/components/AccountLogin.js | 12 +++++++++--- src/navigation/navigationUtils.js | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/account/components/AccountLogin.js b/src/account/components/AccountLogin.js index 60edd99ab5..e021dcd57e 100644 --- a/src/account/components/AccountLogin.js +++ b/src/account/components/AccountLogin.js @@ -17,7 +17,7 @@ import React from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; -import { useSearchParams } from 'react-router-dom'; +import { Navigate, useSearchParams } from 'react-router-dom'; import { fetchAuthURLs } from 'terraso-client-shared/account/accountSlice'; import { useFetchData } from 'terraso-client-shared/store/utils'; import AppleIcon from '@mui/icons-material/Apple'; @@ -44,14 +44,16 @@ const GoogleIcon = props => { return ; }; -const appendReferrer = (url, referrer) => - referrer ? `${url}&state=${referrer}` : url; +const appendReferrer = (url, referrer) => { + return referrer ? `${url}&state=/account?referrer=${referrer}` : url; +}; const AccountForm = () => { const { t } = useTranslation(); const { trackEvent } = useAnalytics(); const [searchParams] = useSearchParams(); const { fetching, urls } = useSelector(state => state.account.login); + const hasToken = useSelector(state => state.account.hasToken); const referrer = searchParams.get('referrer'); useDocumentTitle(t('account.login_document_title')); @@ -63,6 +65,10 @@ const AccountForm = () => { return ; } + if (hasToken) { + return ; + } + return ( { const referrer = [path.substring(1), queryParams] .filter(part => part) .join(''); - return referrer; + if (!referrer) { + return null; + } + return btoa(`/${referrer}`); };