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();
|
|
|
|
|
|
|
|
console.log(data);
|
2022-07-25 17:22:59 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<nav className='flex flex-row h-12 bg-gray-900 justify-end items-center p-4 gap-1 shadow mb-4'>
|
|
|
|
{status === 'loading' && <>...</>}
|
2022-07-25 17:31:20 +00:00
|
|
|
{status === 'unauthenticated' && (
|
2022-07-26 14:32:57 +00:00
|
|
|
<LinkButton
|
|
|
|
href={`/login?return=${encodeURIComponent(router.asPath)}`}
|
|
|
|
>
|
|
|
|
Log in
|
|
|
|
</LinkButton>
|
2022-07-25 17:31:20 +00:00
|
|
|
)}
|
|
|
|
{status === 'authenticated' && (
|
|
|
|
<>
|
|
|
|
<span>{data?.user?.name}</span>
|
|
|
|
<button onClick={() => signOut()}>(Log out)</button>
|
|
|
|
</>
|
|
|
|
)}
|
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
|
|
|
}
|