Refactor: change directory structure of hooks to organize by task

This commit is contained in:
Aaron William Po
2023-05-02 21:54:49 -04:00
parent 94d5d318ca
commit 283b944c6b
44 changed files with 38 additions and 34 deletions

View File

@@ -0,0 +1,22 @@
import UserContext from '@/contexts/userContext';
import { useRouter } from 'next/router';
import { useContext } from 'react';
/**
* Custom React hook that redirects the user to the home page if they are logged in. This
* hook is used to prevent logged in users from accessing the login and signup pages. Must
* be used under the UserContext provider.
*
* @returns {void}
*/
const useRedirectWhenLoggedIn = (): void => {
const { user } = useContext(UserContext);
const router = useRouter();
if (!user) {
return;
}
router.push('/');
};
export default useRedirectWhenLoggedIn;