tubearchivist-frontend/tubearchivist/www/src/pages/index.tsx

53 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { NextPage } from "next";
import { signIn, signOut, useSession } from "next-auth/react";
2022-04-03 00:27:33 +00:00
import dynamic from "next/dynamic";
import Head from "next/head";
2022-04-03 00:27:33 +00:00
import { Suspense } from "react";
const DynamicHeader = dynamic(() => import("../components/Header"), {
suspense: true,
});
const SignInOutButton = ({ isSignedIn }: { isSignedIn: boolean }) => {
if (isSignedIn) {
return <button onClick={() => signOut()}>Sign Out</button>;
}
return <button onClick={() => signIn()}>Sign in</button>;
};
const Home: NextPage = () => {
const { data: session, status } = useSession();
2022-04-03 00:27:33 +00:00
const authData = {
session,
status,
};
console.log(status);
return (
<>
<Head>
<title>Tube Archivist</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon/favicon.ico" />
</Head>
2022-04-03 00:27:33 +00:00
<Suspense fallback={<h1>Loading</h1>}>
<DynamicHeader authData={authData} />
</Suspense>
<div
style={{
display: "flex",
flexDirection: "column",
maxWidth: "100px",
}}
>
2022-04-03 00:27:33 +00:00
<SignInOutButton isSignedIn={!!session?.user} />
</div>
</>
);
};
export default Home;