Next.js Discord

Discord Forum

useSession seems to cause the component to re-mount when page leaves focus

Answered
Lionhead posted this in #help-forum
Open in Discord
LionheadOP
Whenever I leave tab or minimize browser, it is re-mounting the component with a new session.
I do not have other session state changers apart from defining it as:
const { data: session, status } = useSession();

See component code and nextauth here:
https://pastebin.com/D4hGUZNX


Would anyone be able to tell why does it change sessions whenever page defocuses? Kinda makes no sense to me :crySparkle:
Answered by Spectacled bear
You can pass false to refetchOnWindowFocus in <SessionProvider> options
Docs: https://next-auth.js.org/getting-started/client#options
View full answer

3 Replies

Spectacled bear
You can pass false to refetchOnWindowFocus in <SessionProvider> options
Docs: https://next-auth.js.org/getting-started/client#options
Answer
LionheadOP
Thank you 🙏
Spectacled bear
If your issue is fixed, please mark it resolved.