comicbox/components/NavBar.tsx

40 lines
1.3 KiB
TypeScript
Raw Normal View History

import { signOut, useSession } from 'next-auth/react';
import { useRouter } from 'next/router';
import { LinkButton } from './Button';
export default function NavBar() {
const { data, status } = useSession();
const router = useRouter();
return (
2022-07-27 14:43:34 +00:00
<nav>
<ul className='flex flex-row h-12 bg-gray-900 justify-start items-center p-4 gap-1 shadow mb-4 dots-between'>
<li className='no-dot'>
2022-07-27 14:43:34 +00:00
<LinkButton href='/'>Comicbox</LinkButton>
</li>
<li className='flex-1 no-dot' aria-hidden />
2022-07-27 14:43:34 +00:00
<li>
{status === 'loading' && <>...</>}
{status === 'unauthenticated' && (
<LinkButton
2022-07-27 21:10:23 +00:00
href={`/login?return=${encodeURIComponent(
router.asPath
)}`}
2022-07-27 14:43:34 +00:00
>
Log in
</LinkButton>
)}
{status === 'authenticated' && (
<>
<span>{data?.user?.name}</span>{' '}
2022-07-27 14:43:34 +00:00
<button onClick={() => signOut()}>(Log out)</button>
</>
)}
</li>
</ul>
</nav>
2022-07-25 17:31:20 +00:00
);
}