Last active
April 7, 2022 13:15
-
-
Save polluterofminds/14c7dc4e905fcdb8a9c169499e70d69b to your computer and use it in GitHub Desktop.
Members Only Step 9
This file contains 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 React, { useState, useEffect } from 'react' | |
import { signOut, useSession } from "next-auth/react" | |
import Link from 'next/link'; | |
const Gallery = () => { | |
const { data: session, status } = useSession() | |
const [loading, setLoading] = useState(true); | |
const [address, setAddress] = useState(""); | |
const [index, setIndex] = useState([]); | |
useEffect(() => { | |
if(session && session.user && session.user.name && address !== session.user.name) { | |
setAddress(session.user.name); | |
loadFiles(); | |
} | |
}, [session]); | |
const loadFiles = async () => { | |
const res = await fetch(`/api/media`); | |
const data = await res.json(); | |
console.log(data); | |
setIndex(data.imageIndex); | |
setLoading(false); | |
}; | |
if(loading) { | |
<div> | |
<h1>Loading...</h1> | |
</div> | |
} else { | |
return ( | |
<div> | |
{ | |
!session ? | |
<div> | |
<h1>You need to sign in</h1> | |
<Link href="/">Sign in</Link> | |
</div> : | |
<div> | |
Gallery | |
</div> | |
} | |
</div> | |
) | |
} | |
} | |
export default Gallery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment