Skip to content

Commit

Permalink
fix(#411): added redirect to login/page.tsx to redirect users (#437)
Browse files Browse the repository at this point in the history
- Added `useRouter` to the login page so users get redirected to
`/league/all` if they are already signed in and navigate to `/login`.
- Added unit test for the `route.push` function as well.
  • Loading branch information
vazquezea96 authored and Clue355 committed Jul 26, 2024
1 parent a002a5f commit ec5f1c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/(main)/login/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ describe('Login', () => {

mockUseAuthContext.isSignedIn = false;
});
});

test('redirects to /league/all when user navigates to /login', async () => {
mockUseAuthContext.isSignedIn = true;

render(<Login />);

expect(mockPush).toHaveBeenCalledWith('/league/all');
});
});
1 change: 1 addition & 0 deletions app/(main)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Login = (): React.JSX.Element => {
useEffect(() => {
if (isSignedIn) {
getUser();
router.push('/league/all');
}
}, [isSignedIn, getUser]);

Expand Down

0 comments on commit ec5f1c9

Please sign in to comment.