comicbox/components/NavBar.tsx
Ashhhleyyy b51c7bded3
feat: improve login flow
* Uses @next-auth/prisma-adapter to persist sessions and users
* Move to direct Discord/GitHub oauth for regular users
2022-07-26 15:34:30 +01:00

29 lines
928 B
TypeScript

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