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?
loading
to betrue
aftersignIn()
is being called. I wanted to use it to show a spinner on the login-submit-button whilesignIn()
did its thing. But I had to learn thatsignIn()
(and alsosingOut()
) does not have any effect onloading
. Probably I'm having a major misunderstanding. Maybe someone can clear the fog for me .. – Fume