import Layout from '@/components/ui/Layout'; import Spinner from '@/components/ui/Spinner'; import withPageAuthRequired from '@/getServerSideProps/withPageAuthRequired'; import UserContext from '@/contexts/userContext'; import { GetServerSideProps, NextPage } from 'next'; import { useContext } from 'react'; const ProtectedPage: NextPage = () => { const { user, isLoading } = useContext(UserContext); const currentTime = new Date().getHours(); const isMorning = currentTime > 4 && currentTime < 12; const isAfternoon = currentTime > 12 && currentTime < 18; const isEvening = currentTime > 18 && currentTime < 24 || currentTime <4 return (
{isLoading && } {user && ( <>

Good {isMorning && 'morning'} {isAfternoon && 'afternoon'} {isEvening && 'evening'} {`, ${user?.firstName}!`}

Welcome to the Biergarten App!

)}
); }; export const getServerSideProps: GetServerSideProps = withPageAuthRequired(); export default ProtectedPage;