2022-07-26 14:32:57 +00:00
|
|
|
import { signOut, useSession } from 'next-auth/react';
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { LinkButton } from './Button';
|
2022-07-25 17:22:59 +00:00
|
|
|
|
|
|
|
export default function NavBar() {
|
|
|
|
const { data, status } = useSession();
|
2022-07-26 14:32:57 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
2022-07-25 17:22:59 +00:00
|
|
|
return (
|
2022-07-27 14:43:34 +00:00
|
|
|
<nav>
|
2022-08-01 15:31:47 +00:00
|
|
|
<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>
|
|
|
|
|
2022-08-01 15:31:47 +00:00
|
|
|
<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' && (
|
|
|
|
<>
|
2022-08-01 15:31:47 +00:00
|
|
|
<span>{data?.user?.name}</span>{' '}
|
2022-07-27 14:43:34 +00:00
|
|
|
<button onClick={() => signOut()}>(Log out)</button>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
</ul>
|
2022-07-25 17:22:59 +00:00
|
|
|
</nav>
|
2022-07-25 17:31:20 +00:00
|
|
|
);
|
2022-07-25 17:22:59 +00:00
|
|
|
}
|