mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
This commit adds the necessary functionality to confirm a user's account. It includes the addition of a new column in the user table to track whether an account is confirmed or not, and the implementation of JWT for confirmation tokens. This commit integrates the SparkPost API as well as React Email to send dynamic emails for whatever purpose. Upon user registration, a confirmation email will be sent to the user.
107 lines
3.2 KiB
TypeScript
107 lines
3.2 KiB
TypeScript
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
|
|
/* 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 { useContext, useEffect, useState } from 'react';
|
|
|
|
interface Page {
|
|
slug: string;
|
|
name: string;
|
|
}
|
|
const Navbar = () => {
|
|
const router = useRouter();
|
|
const [currentURL, setCurrentURL] = useState('/');
|
|
|
|
const { user } = useContext(UserContext);
|
|
|
|
useEffect(() => {
|
|
setCurrentURL(router.asPath);
|
|
}, [router.asPath]);
|
|
|
|
const authenticatedPages: readonly Page[] = [
|
|
{ slug: '/account', name: 'Account' },
|
|
{ slug: '/api/users/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 (
|
|
<nav className="navbar bg-primary text-primary-content">
|
|
<div className="flex-1">
|
|
<Link className="btn btn-ghost text-3xl normal-case" href="/">
|
|
<span className="cursor-pointer text-xl font-bold">The Biergarten App</span>
|
|
</Link>
|
|
</div>
|
|
<div className="hidden flex-none lg:block">
|
|
<ul className="menu menu-horizontal p-0">
|
|
{pages.map((page) => {
|
|
return (
|
|
<li key={page.slug}>
|
|
<Link tabIndex={0} href={page.slug}>
|
|
<span
|
|
className={`text-lg uppercase ${
|
|
currentURL === page.slug ? 'font-extrabold' : 'font-semibold'
|
|
} text-primary-content`}
|
|
>
|
|
{page.name}
|
|
</span>
|
|
</Link>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
</div>
|
|
<div className="flex-none lg:hidden">
|
|
<div className="dropdown dropdown-end">
|
|
<label tabIndex={0} className="btn btn-ghost btn-circle">
|
|
<span className="w-10 rounded-full">
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
fill="none"
|
|
viewBox="0 0 24 24"
|
|
className="inline-block h-5 w-5 stroke-white"
|
|
>
|
|
<path
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
strokeWidth="2"
|
|
d="M4 6h16M4 12h16M4 18h16"
|
|
/>
|
|
</svg>
|
|
</span>
|
|
</label>
|
|
<ul
|
|
tabIndex={0}
|
|
className="dropdown-content menu rounded-box menu-compact mt-3 w-48 bg-base-100 p-2 shadow"
|
|
>
|
|
{pages.map((page) => (
|
|
<li key={page.slug}>
|
|
<Link href={page.slug}>
|
|
<span className="select-none text-primary-content">{page.name}</span>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
);
|
|
};
|
|
export default Navbar;
|