Last active
August 22, 2022 08:06
-
-
Save officialrajdeepsingh/619a49cd5263f7542552e387b94b43f3 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
| // pages/index.js | |
| import Login from '../components/login'; | |
| import { useSession, getProviders } from "next-auth/react" | |
| // rest import here | |
| export default function Home({ posts, totalPostCount, providers }) { | |
| // get session from next-auth | |
| const { data: session, status } = useSession() | |
| // check status is looding or not | |
| if (status === "loading") { | |
| return <h2> Looding component</h2> | |
| } else if (!session) { | |
| // if session is not avilable the render login page | |
| return <Login providers={providers} /> | |
| } else if (session) { | |
| // main component | |
| return <Main /> | |
| ) | |
| } | |
| } | |
| // nextjs getStaticProps help fatch data in build time | |
| export async function getStaticProps() { | |
| // get provider from next-auth | |
| const providers = await getProviders() | |
| // rest code ... | |
| return { | |
| props: { | |
| providers, | |
| ..... | |
| }, | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment