I'm writing a Next.js project, and implementing authentication using GitHub and next-auth
. In the examples of next-auth
, there's a call to useSession()
, which returns two objects: session
and loading
. However, none of the examples that I've seen actually use the loading
object.
import React from 'react'
import {
useSession,
signin,
signout
} from 'next-auth/client'
export default () => {
const [ session, loading ] = useSession()
return <p>
{!session && <>
Not signed in <br/>
<button onClick={signin}>Sign in</button>
</>}
{session && <>
Signed in as {session.user.email} <br/>
<button onClick={signout}>Sign out</button>
</>}
</p>
}
Question: What is the purpose of loading
, and how is it used in practice?