Created
March 2, 2022 22:45
-
-
Save peteristhegreat/7bb0f3c398af41513da2ec94a54481d0 to your computer and use it in GitHub Desktop.
Nextjs ClientSide redirect with useEffect and useRouter (relying on Authentication) react-hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
import Spinner from 'components/icons/Spinner'; | |
import { useRequireAuth } from 'hooks/useRequireAuth'; | |
import Router from 'next/router'; | |
const MyTeamIndexPage = () => { | |
const { user } = useRequireAuth(); | |
// const [isLoading, setIsLoading] = useState(true); | |
useEffect(() => { | |
console.log(user); | |
if (user && user?.teamId) { | |
Router.push(`/team/${user.teamId}`); | |
} | |
}, [user]); | |
return ( | |
<div className="flex justify-center min-h-screen bg-gray-100"> | |
<Spinner width="30" className="m-auto mt-6 animate-spin" /> | |
</div> | |
); | |
}; | |
export default MyTeamIndexPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment