Last active
December 28, 2021 15:44
-
-
Save skolhustick/9d8a9c0510c884a0c538a2b70c8c8ac1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { getSession, signOut, useSession } from 'next-auth/react' | |
| import Link from 'next/link' | |
| import React from 'react' | |
| const Homepage = () => { | |
| // Check if the user is authenticated from the client | |
| const { data: session, status } = useSession() | |
| if (status === 'loading') { | |
| return <>Loading...</> | |
| } | |
| if (status === 'authenticated') { | |
| return ( | |
| <> | |
| Signed in as {session.user.email} <br /> | |
| <button onClick={() => signOut()}>Sign out</button> | |
| </> | |
| ) | |
| } | |
| if (status === 'unauthenticated') { | |
| return ( | |
| <> | |
| Not signed in <br /> | |
| <Link href='/api/auth/signin'> | |
| <a>Login</a> | |
| </Link> | |
| </> | |
| ) | |
| } | |
| } | |
| export const getServerSideProps = async ctx => { | |
| // Check if the user is authenticated from the server | |
| const session = await getSession(ctx) | |
| console.log({ session }) | |
| return { | |
| props: { | |
| session | |
| } | |
| } | |
| } | |
| export default Homepage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment