New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getSessionAndUser
called 2x per page load when adapter
is specified
#4605
Comments
getSessionAndUser
called 2x per page load when adapter
is specified
I can't access the reproduction URL, could you share it?
export async function getServerSideProps(ctx) {
return {
props: {
session: await getSession(ctx)
}
}
} Hope it helps! |
Updated the visibility of the repo. Also, I think I inadvertently made the issue worse -- in my attempts to strip out any adding that piece does eliminate the second server call, however there are still two calls to the adapter on initial load, so just wanted to make sure that was expected behavior. thanks for the help!
|
hmm, if there are no callbacks during the initial load, I expect only one adapter call from one API call. Here is the relevant code:
I tried but couldn't reproduce this behavior using your example or our internal development app. 🤔 Can you confirm that this is still happening? |
Oh, weird! Yeah, still happening. In fact, even in a signed-out state, I'm seeing two
and when logged in, I see the duplicate calls:
FWIW, I'm using I just updated the repo slightly to clean up a few extra bits to make it as straightforward of a repo as possible. |
using the repo you provided, If I replace |
I tried to do that (see updated repro without any calls to
That's great to know! Will do that going forward. I noticed that when I made that change, I was getting
Let me try to dig in more here! |
Thanks, @timfee, it's super weird because I can reproduce this behavior on your repo but not other repos... 🤔 I honestly don't know what caused this. It makes sense if |
I believe this might be expected. Once in
And again when we fetch the initial
|
Thanks for the clarification! In my POC, I was trying to be extremely judicious about reads / writes to my database, and it seemed a bit off that there were two (duplicated) |
If you pass a next-auth/packages/next-auth/src/react/index.tsx Lines 307 to 326 in e203801
|
@balazsorban44: this doesn't work, see my repro that still generates 2x calls:
|
@balazsorban44 actually, the
|
Environment
Reproduction URL
https://github.com/timfee/nextauth-dupe-calls
Describe the issue
I enabled verbose logging in the config file:
After attaching an adapter (in this case, Prisma), I notice two
adapter_getSessionAndUser
log events per page load. I only have a<SessionProvider>
context in_app.tsx
and auseSession
inindex.tsx
.Even if you change the index.tsx to remove the call to
useSession
, it still generates double the query.Is this WAI, or are there any ways to de-dupe the request? I followed the SessionProvider pattern, which the docs say should avoid checking the session twice on pages that support both server and client side rendering.
Thanks!
How to reproduce
Clone the repro URL and populate the
.env
files to a Postgres instance.Expected behavior
I would expect (perhaps mistakenly :)) that there wouldn't be double SELECTs per page load.
The text was updated successfully, but these errors were encountered: