diff --git a/components/BeerIndex/BeerIndexPaginationBar.tsx b/components/BeerIndex/BeerIndexPaginationBar.tsx new file mode 100644 index 0000000..c90217c --- /dev/null +++ b/components/BeerIndex/BeerIndexPaginationBar.tsx @@ -0,0 +1,34 @@ +import Link from 'next/link'; + +import { FC } from 'react'; + +interface PaginationProps { + pageNum: number; + pageCount: number; +} + +const BeerIndexPaginationBar: FC = ({ pageCount, pageNum }) => { + return ( +
+ + « + + + + » + +
+ ); +}; + +export default BeerIndexPaginationBar; diff --git a/components/BeerIndex/Pagination.tsx b/components/BeerIndex/Pagination.tsx deleted file mode 100644 index dc18fb8..0000000 --- a/components/BeerIndex/Pagination.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { useRouter } from 'next/router'; -import { FC } from 'react'; - -interface PaginationProps { - pageNum: number; - pageCount: number; -} - -const Pagination: FC = ({ pageCount, pageNum }) => { - const router = useRouter(); - - return ( -
- - - -
- ); -}; - -export default Pagination; diff --git a/components/ui/forms/FormPageLayout.tsx b/components/ui/forms/FormPageLayout.tsx index fddea6c..4fef0c1 100644 --- a/components/ui/forms/FormPageLayout.tsx +++ b/components/ui/forms/FormPageLayout.tsx @@ -22,7 +22,7 @@ const FormPageLayout: FC = ({
- +
diff --git a/config/auth/cookie.ts b/config/auth/cookie.ts index 464b8a2..50ac928 100644 --- a/config/auth/cookie.ts +++ b/config/auth/cookie.ts @@ -8,7 +8,7 @@ export const MAX_AGE = 60 * 60 * 8; // 8 hours export function setTokenCookie(res: NextApiResponse, token: string) { const cookie = serialize(TOKEN_NAME, token, { maxAge: MAX_AGE, - httpOnly: true, + httpOnly: false, secure: process.env.NODE_ENV === 'production', path: '/', sameSite: 'lax', diff --git a/hooks/useUser.ts b/hooks/useUser.ts index 14bdc2f..0d59f34 100644 --- a/hooks/useUser.ts +++ b/hooks/useUser.ts @@ -3,15 +3,18 @@ import APIResponseValidationSchema from '@/validation/APIResponseValidationSchem import useSWR from 'swr'; const useUser = () => { - // check cookies for user const { data: user, error, isLoading, } = useSWR('/api/users/current', async (url) => { + if (!document.cookie.includes('token')) { + throw new Error('No token cookie found'); + } const response = await fetch(url); if (!response.ok) { + document.cookie = 'token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; throw new Error(response.statusText); } @@ -23,6 +26,7 @@ const useUser = () => { } const parsedPayload = GetUserSchema.safeParse(parsed.data.payload); + console.log(parsedPayload); if (!parsedPayload.success) { throw new Error(parsedPayload.error.message); } diff --git a/pages/api/users/register.ts b/pages/api/users/register.ts index baaef64..ffe3f41 100644 --- a/pages/api/users/register.ts +++ b/pages/api/users/register.ts @@ -17,12 +17,6 @@ interface RegisterUserRequest extends NextApiRequest { body: z.infer; } -const { BASE_URL } = process.env; - -if (!BASE_URL) { - throw new ServerError('BASE_URL env variable is not set.', 500); -} - const registerUser = async (req: RegisterUserRequest, res: NextApiResponse) => { const [usernameTaken, emailTaken] = await Promise.all([ findUserByUsername(req.body.username), diff --git a/pages/beers/index.tsx b/pages/beers/index.tsx index aee56cd..a2cbd45 100644 --- a/pages/beers/index.tsx +++ b/pages/beers/index.tsx @@ -4,7 +4,7 @@ import getAllBeerPosts from '@/services/BeerPost/getAllBeerPosts'; import { useRouter } from 'next/router'; import DBClient from '@/prisma/DBClient'; import Layout from '@/components/ui/Layout'; -import Pagination from '@/components/BeerIndex/Pagination'; +import BeerIndexPaginationBar from '@/components/BeerIndex/BeerIndexPaginationBar'; import BeerCard from '@/components/BeerIndex/BeerCard'; import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult'; import Head from 'next/head'; @@ -26,16 +26,24 @@ const BeerPage: NextPage = ({ initialBeerPosts, pageCount }) => {
-
+
+
+
+

The Biergarten Index

+

+ Page {pageNum} of {pageCount} +

+
+
{initialBeerPosts.map((post) => { return ; })}
- +
-
+
);