chore: initial suspense setup

This commit is contained in:
Sean Norwood 2022-04-03 00:27:33 +00:00
parent ad67cb00e2
commit cf9181919a

View File

@ -1,9 +1,28 @@
import type { NextPage } from "next"; import type { NextPage } from "next";
import { signIn, signOut, useSession } from "next-auth/react"; import { signIn, signOut, useSession } from "next-auth/react";
import dynamic from "next/dynamic";
import Head from "next/head"; import Head from "next/head";
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 Home: NextPage = () => {
const { data: session, status } = useSession(); const { data: session, status } = useSession();
const authData = {
session,
status,
};
console.log(status);
return ( return (
<> <>
@ -13,12 +32,10 @@ const Home: NextPage = () => {
<link rel="icon" href="/favicon/favicon.ico" /> <link rel="icon" href="/favicon/favicon.ico" />
</Head> </Head>
{console.log("Session", session)} <Suspense fallback={<h1>Loading</h1>}>
<DynamicHeader authData={authData} />
</Suspense>
<h1>Name: {session?.user?.name}</h1>
<h1>Status: {status}</h1>
<h1>Token: {session?.ta_token?.token}</h1>
<h1>User ID: {session?.ta_token?.user_id}</h1>
<div <div
style={{ style={{
display: "flex", display: "flex",
@ -26,8 +43,7 @@ const Home: NextPage = () => {
maxWidth: "100px", maxWidth: "100px",
}} }}
> >
<button onClick={() => signIn()}>Sign in</button> <SignInOutButton isSignedIn={!!session?.user} />
<button onClick={() => signOut()}>Sign Out</button>
</div> </div>
</> </>
); );