From 45cc10a0096154ad6516857df5e63c6d7d33eaa0 Mon Sep 17 00:00:00 2001 From: Aaron William Po Date: Thu, 9 Feb 2023 23:58:03 -0500 Subject: [PATCH 01/13] Update next-connect, begin work on cloud img upload --- .gitignore | 5 +- components/ui/Navbar.tsx | 26 +- config/cloudinary/index.ts | 27 + ...ConnectConfig.ts => NextConnectOptions.ts} | 15 +- .../middleware/getCurrentUser.ts | 6 +- .../middleware/validateRequest.ts | 2 +- package-lock.json | 1420 ++++++++++++++++- package.json | 6 +- pages/api/beers/[id]/comments.ts | 16 +- pages/api/beers/[id]/images/index.ts | 77 + pages/api/beers/[id]/like/index.ts | 16 +- pages/api/beers/[id]/like/is-liked.ts | 22 +- pages/api/beers/create.ts | 16 +- pages/api/users/current.ts | 13 +- pages/api/users/login.ts | 39 +- pages/api/users/logout.ts | 13 +- pages/api/users/register.ts | 18 +- 17 files changed, 1616 insertions(+), 121 deletions(-) create mode 100644 config/cloudinary/index.ts rename config/nextConnect/{NextConnectConfig.ts => NextConnectOptions.ts} (58%) rename config/{auth => nextConnect}/middleware/getCurrentUser.ts (82%) rename config/{zod => nextConnect}/middleware/validateRequest.ts (98%) create mode 100644 pages/api/beers/[id]/images/index.ts diff --git a/.gitignore b/.gitignore index a9fd027..26a5e38 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,7 @@ yarn-error.log* next-env.d.ts # http requests -*.http \ No newline at end of file +*.http + +# uploaded images +public/uploads diff --git a/components/ui/Navbar.tsx b/components/ui/Navbar.tsx index c712b61..150d54c 100644 --- a/components/ui/Navbar.tsx +++ b/components/ui/Navbar.tsx @@ -2,9 +2,10 @@ /* eslint-disable jsx-a11y/label-has-associated-control */ /* eslint-disable jsx-a11y/label-has-for */ +import UserContext from '@/contexts/userContext'; import Link from 'next/link'; import { useRouter } from 'next/router'; -import { useEffect, useState } from 'react'; +import { useContext, useEffect, useState } from 'react'; interface Page { slug: string; @@ -14,19 +15,36 @@ const Navbar = () => { const router = useRouter(); const [currentURL, setCurrentURL] = useState('/'); + const { user } = useContext(UserContext); + useEffect(() => { setCurrentURL(router.asPath); }, [router.asPath]); - const pages: Page[] = [ + const authenticatedPages: readonly Page[] = [ + { slug: '/account', name: 'Account' }, + { slug: '/logout', name: 'Logout' }, + ]; + + const unauthenticatedPages: readonly Page[] = [ + { slug: '/login', name: 'Login' }, + { slug: '/register', name: 'Register' }, + ]; + + const otherPages: readonly Page[] = [ { slug: '/beers', name: 'Beers' }, { slug: '/breweries', name: 'Breweries' }, ]; + const pages: readonly Page[] = [ + ...otherPages, + ...(user ? authenticatedPages : unauthenticatedPages), + ]; + return (