Skip to content

Instantly share code, notes, and snippets.

@officialrajdeepsingh
Last active August 22, 2022 08:06
Show Gist options
  • Select an option

  • Save officialrajdeepsingh/619a49cd5263f7542552e387b94b43f3 to your computer and use it in GitHub Desktop.

Select an option

Save officialrajdeepsingh/619a49cd5263f7542552e387b94b43f3 to your computer and use it in GitHub Desktop.
// 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