Skip to content

Instantly share code, notes, and snippets.

@Nilanth
Created December 31, 2021 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilanth/9b1fca7a90ad45e0ccbf3ba6edee23a6 to your computer and use it in GitHub Desktop.
Save Nilanth/9b1fca7a90ad45e0ccbf3ba6edee23a6 to your computer and use it in GitHub Desktop.
import {useSession, signIn, signOut} from "next-auth/react"
import {useEffect, useState} from "react";
import Layout from "../components/Layout";
import Button from "../components/Button";
import Followers from "../components/Followers";
import Image from "next/image";
export default function Home() {
const [loader, setLoader] = useState(false);
function oauthSignOut() {
if (!loader) {
setLoader(!loader);
signOut();
}
}
if (status === 'loading') return <Layout> Loading... </Layout>;
function oauthSignIn() {
if (!loader) {
setLoader(!loader);
signIn('twitter');
}
}
if (session) {
return (
<Layout>
<Followers session={session}/>
<div className="flex flex-wrap items-center justify-around max-w-4xl py-6 sm:w-full 2xl:py-12">
<Button label="Logout" onClick={() => oauthSignOut()} loader={loader}>Sign out</Button>
</div>
</Layout>
)
}
return (
<Layout>
<div className="mb-10">
<Image
src="/cover-logo.png"
alt="Picture of the author"
width={800}
height={300}
/>
</div>
<Button label="Login with Twitter" onClick={() => oauthSignIn()} loader={loader}>
Sign in
</Button>
</Layout>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment