Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Commit 81e369c

Browse files
authored
Mobile first open hotfix (#610)
* Updated the index.tsx for first sign in bug. * Fixed the bug of the profile form not being present after the first sign in.
1 parent bacffd3 commit 81e369c

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

heatHMobile/__test__/interestFormService.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ jest.mock('@/services/apiClient', () => ({
1313
describe('interestFormService', () => {
1414
beforeEach(() => jest.clearAllMocks());
1515

16-
it('checkFirstLogin returns backend value on success', async () => {
17-
(apiClient.get as jest.Mock).mockResolvedValueOnce({ data: true });
16+
it('checkFirstLogin returns true if form is missing (backend returns false)', async () => {
17+
(apiClient.get as jest.Mock).mockResolvedValueOnce({ data: false });
1818
await expect(interestFormService.checkFirstLogin()).resolves.toBe(true);
1919
});
2020

21+
it('checkFirstLogin returns false if form exists (backend returns true)', async () => {
22+
(apiClient.get as jest.Mock).mockResolvedValueOnce({ data: true });
23+
await expect(interestFormService.checkFirstLogin()).resolves.toBe(false);
24+
});
25+
2126
it('checkFirstLogin returns false on 404/403', async () => {
2227
const err404 = { isAxiosError: true, response: { status: 404 } } as any;
2328
(axios.isAxiosError as any) = () => true;

heatHMobile/app/auth/sign-in.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ export default function SignInScreen() {
3434
try {
3535
await authService.login({ username: email, password: password });
3636

37-
// Check if this is the user's first login
37+
// Check if this is the user's first login (needs to fill profile)
3838
try {
39-
const isFirstLogged = await interestFormService.checkFirstLogin();
39+
// returns true if form NOT submitted (first login)
40+
const isFirstLogin = await interestFormService.checkFirstLogin();
4041

41-
if (isFirstLogged) {
42-
router.replace('/(tabs)' as any);
43-
} else {
42+
if (isFirstLogin) {
4443
router.replace('/first-login-profile' as any);
45-
44+
} else {
45+
router.replace('/(tabs)' as any);
4646
}
4747
} catch (firstLoginError) {
48+
// If check fails, default to tabs
4849
router.replace('/(tabs)' as any);
4950
}
5051
} catch (error: any) {

heatHMobile/app/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ export default function Index() {
1818
console.log('Token:', token ? 'Found' : 'Not found');
1919

2020
if (token) {
21-
// Check if this is the user's first login
21+
// Check if this is the user's first login (needs to fill profile)
2222
try {
23-
const isFirstLogged = await interestFormService.checkFirstLogin();
24-
if (isFirstLogged) {
25-
router.replace('/(tabs)' as any);
26-
} else {
23+
// returns true if form NOT submitted (first login)
24+
const isFirstLogin = await interestFormService.checkFirstLogin();
25+
26+
if (isFirstLogin) {
2727
router.replace('/first-login-profile' as any);
28+
} else {
29+
router.replace('/(tabs)' as any);
2830
}
2931
} catch (firstLoginError) {
32+
// If check fails, default to tabs
3033
router.replace('/(tabs)' as any);
3134
}
3235
} else {

heatHMobile/services/interestFormService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export const interestFormService = {
1717
try {
1818
const response = await apiClient.get('/interest-form/check-first-login');
1919
console.log('Check first login response:', response.data);
20-
return response.data;
20+
// Backend returns true if form EXISTS.
21+
// We want true if form is MISSING (is first login).
22+
return !response.data;
2123
} catch (err) {
2224
// If endpoint not found or form doesn't exist/forbidden, treat as not first login
2325
if (axios.isAxiosError(err) && (err.response?.status === 404 || err.response?.status === 403)) {

0 commit comments

Comments
 (0)