diff --git a/src/account/accountProfileUtils.js b/src/account/accountProfileUtils.js index 3b72d6230..16bfc97be 100644 --- a/src/account/accountProfileUtils.js +++ b/src/account/accountProfileUtils.js @@ -20,9 +20,9 @@ import { useNavigate } from 'react-router-dom'; import { getToken } from 'terraso-client-shared/account/auth'; import { useSelector } from 'terrasoApi/store'; -const getCreatedWithService = async () => { +const getIsFirstLogin = async () => { const token = await getToken(); - return token === undefined ? undefined : jwtDecode(token).createdWithService; + return token === undefined ? undefined : jwtDecode(token).isFirstLogin; }; const getStoredCompletedProfile = email => { @@ -52,16 +52,16 @@ export const profileCompleted = email => { export const useCompleteProfile = () => { const navigate = useNavigate(); const { data: user } = useSelector(state => state.account.currentUser); - const [createdWithService, setCreatedWithService] = useState(); + const [isFirstLogin, setIsFirstLogin] = useState(); useEffect(() => { - getCreatedWithService().then(createdWithService => { - setCreatedWithService(createdWithService); + getIsFirstLogin().then(isFirstLogin => { + setIsFirstLogin(isFirstLogin); }); }, []); useEffect(() => { - if (!createdWithService || !user?.email) { + if (!isFirstLogin || !user?.email) { return; } @@ -71,5 +71,5 @@ export const useCompleteProfile = () => { } navigate('/account/profile/completeProfile'); - }, [createdWithService, user?.email, navigate]); + }, [isFirstLogin, user?.email, navigate]); }; diff --git a/src/account/components/RequireAuth.test.js b/src/account/components/RequireAuth.test.js index 3cf8a0a33..ab2856eb8 100644 --- a/src/account/components/RequireAuth.test.js +++ b/src/account/components/RequireAuth.test.js @@ -40,9 +40,9 @@ jest.mock('react-router-dom', () => ({ Navigate: props =>
To: {props.to}
, })); -// Payload: { "createdWithService": "google" } -const CREATED_WITH_SERVICE_TOKEN = - 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkV2l0aFNlcnZpY2UiOiJnb29nbGUifQ.aznynzRP1qRh-GVKPM_Xhi7ZhG7XuM7R6SIXNd7rfCo2bgnXJen3btm4VnpcVDalnCQPpp8e-1f7t8qlTLZu0Q'; +// Payload: { "isFirstLogin": true } +const IS_FIRST_LOGIN_TOKEN = + 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc0ZpcnN0TG9naW4iOnRydWV9.Z5WctUFTDZuFDAr0QiczFKIIx8qWzWJ38kiIHnGSiUQ29z7VQqGz9F5mfFfrt48sRob-fyw5sWxIxm3qbcxrEQ'; beforeEach(() => { global.fetch = jest.fn(); @@ -197,7 +197,7 @@ test('Auth: test fetch user', async () => { test('Auth: Test redirect complete profile', async () => { const navigate = jest.fn(); useNavigate.mockReturnValue(navigate); - getToken.mockResolvedValue(CREATED_WITH_SERVICE_TOKEN); + getToken.mockResolvedValue(IS_FIRST_LOGIN_TOKEN); await render(
@@ -219,7 +219,7 @@ test('Auth: Test redirect complete profile', async () => { test('Auth: Avoid redirect if profile complete already displayed for user', async () => { const navigate = jest.fn(); useNavigate.mockReturnValue(navigate); - getToken.mockResolvedValue(CREATED_WITH_SERVICE_TOKEN); + getToken.mockResolvedValue(IS_FIRST_LOGIN_TOKEN); localStorage.setItem( 'completedProfileDisplayed',