Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#411): added redirect to login/page.tsx to redirect users #437

12 changes: 12 additions & 0 deletions app/(main)/login/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,16 @@ describe('Login', () => {

mockUseAuthContext.isSignedIn = false;
});

test('redirects to /league/all when user navigates to /login', async () => {
ryandotfurrer marked this conversation as resolved.
Show resolved Hide resolved
mockUseAuthContext.isSignedIn = true;

render(<Login />);

await waitFor(() => {
expect(mockPush).toHaveBeenCalledWith('/league/all');
});

mockUseAuthContext.isSignedIn = false;
});
});
3 changes: 3 additions & 0 deletions app/(main)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

'use client';
import { JSX, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import Logo from '@/components/Logo/Logo';
import logo from '@/public/assets/logo-colored-outline.svg';
import { Input } from '@/components/Input/Input';
Expand Down Expand Up @@ -38,11 +39,13 @@ type LoginUserSchemaType = z.infer<typeof LoginUserSchema>;
* @returns {JSX.Element} The rendered login page.
*/
const Login = (): JSX.Element => {
const router = useRouter();
const { login, isSignedIn, getUser } = useAuthContext();

useEffect(() => {
if (isSignedIn) {
getUser();
router.push('/league/all');
}
}, [isSignedIn, getUser]);

Expand Down