Skip to content

Commit

Permalink
fix: Changed createdWithService to isFirstLogin
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Mar 12, 2024
1 parent 8f97c82 commit 48924ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/account/accountProfileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
}

Expand All @@ -71,5 +71,5 @@ export const useCompleteProfile = () => {
}

navigate('/account/profile/completeProfile');
}, [createdWithService, user?.email, navigate]);
}, [isFirstLogin, user?.email, navigate]);
};
10 changes: 5 additions & 5 deletions src/account/components/RequireAuth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jest.mock('react-router-dom', () => ({
Navigate: props => <div>To: {props.to}</div>,
}));

// 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();
Expand Down Expand Up @@ -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(
<RequireAuth>
<div />
Expand All @@ -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',
Expand Down

0 comments on commit 48924ee

Please sign in to comment.