Update login to redirect to current user page

This commit is contained in:
Aaron William Po
2023-04-05 22:24:02 -04:00
parent 7db7b8264f
commit c8a8c70127
4 changed files with 26 additions and 23 deletions

View File

@@ -7,21 +7,29 @@ import { GetServerSideProps, NextPage } from 'next';
import { useContext } from 'react';
const ProtectedPage: NextPage = () => {
const { user, error, isLoading } = useContext(UserContext);
const { user, isLoading } = useContext(UserContext);
const currentTime = new Date().getHours();
const isMorning = currentTime > 5 && currentTime < 12;
const isAfternoon = currentTime > 12 && currentTime < 18;
const isEvening = currentTime > 18 && currentTime < 24;
return (
<Layout>
<div className="flex h-full flex-col items-center justify-center">
<h1 className="text-7xl font-bold text-white">Hello!</h1>
<>
{isLoading && <Spinner />}
{error && <p>Something went wrong.</p>}
{user && (
<div>
<p>{user.username}</p>
</div>
)}
</>
<div className="flex h-full flex-col items-center justify-center space-y-3">
{isLoading && <Spinner size="xl" />}
{user && (
<>
<h1 className="text-7xl font-bold">
Good {isMorning && 'morning'}
{isAfternoon && 'afternoon'}
{isEvening && 'evening'}
{`, ${user?.firstName}!`}
</h1>
<h2 className="text-4xl font-bold">Welcome to the Biergarten App!</h2>
</>
)}
</div>
</Layout>
);