Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Created March 2, 2022 22:45
Show Gist options
  • Save peteristhegreat/7bb0f3c398af41513da2ec94a54481d0 to your computer and use it in GitHub Desktop.
Save peteristhegreat/7bb0f3c398af41513da2ec94a54481d0 to your computer and use it in GitHub Desktop.
Nextjs ClientSide redirect with useEffect and useRouter (relying on Authentication) react-hooks
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