-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Neo4j session error (GetSessionAndUserError) #5849
Comments
Hi @vladutilie could you try with neo4j-driver 4.x ? It seems 5 was only rolled out a few months ago and the neo4j adapret is tested up to version 4. This way at least we will know how to proceeed, additional tests/amends for v5 or futher investigation elsewhere. |
Hi @EarthlingDavey! Thank you for taking the time to respond to me. I have tried both Thank you! |
Hey @vladutilie sorry i can't dedicate a bunch of time to help but I can give some pointers.
I have this adapter runing in production with pinned slightly old versions and jwt (not using unstable_getServerSession). I suspect the error you're seeing is because of some new feature or change (to this package or other dependancy) since the neo4j adapter was written. Sorry I can't assingn myself to fix this right now, my work load is huge. |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
@balazsorban44 @ndom91 Hi, I need some advice on my approaach to fix this, please. It looks 2 (or more) adapter functions are running at the same time. Looking at the bug report I think I've checked (the neo4j adapter)[https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-neo4j/src/index.ts] and all functions are async and have the correct await. I think that I can see 2 approaches to a fix:
Do you think my diagnosis is right? I can implement the neo4j-adapter change, plase advise. |
Yes, it's related to this. But a correction is that:
Taking the example from The session API docs const session = driver.session()
const titles = []
try {
// This will work note the await
const result1 = await session.executeRead(tx =>
tx.run('MATCH (p:Product) WHERE p.id = $id RETURN p.title', { id: 0 })
)
const result2 = await session.executeRead(tx =>
tx.run('MATCH (p:Product) WHERE p.id = $id RETURN p.title', { id: 0 })
)
// This might error because of not awaiting for a tx to complete before starting the next one.
const resultPromise3 = session.executeRead(tx =>
tx.run('MATCH (p:Product) WHERE p.id = $id RETURN p.title', { id: 0 })
)
const resultPromise4 = session.executeRead(tx =>
tx.run('MATCH (p:Product) WHERE p.id = $id RETURN p.title', { id: 0 })
)
const [result3, result4] = await Promise.all([resultPromise3, resultPromise4])
} finally {
await session.close()
} |
@EarthlingDavey Are you writing about the comment that I deleted? |
@indicozy yes, maybe you already knew, but I posted an example anyways. |
FYI this error does not pop up on Vercel functions, so it verifies the hypothesis |
This comment was marked as off-topic.
This comment was marked as off-topic.
Hi @w-dib thanks for your comment. But I'm almost certain that although you're seeing a similar/same error message - your issue is unrelated. The issue here is that next-auth is trying to do 2 simultanious database writes and the neo4j adapter was not written with this use case in mind. You should search through existing issues to see if one does exactly mach with yours. Else, please create a new issue, following the template :) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Hi @Reddsito. If you're using Prisma, you should search existing tickets. If no existing ticket matches your issue then create a new one. This issue is about neo4j, not Prisma. |
Adapter type
@next-auth/neo4j-adapter
Environment
System:
OS: macOS 13.0
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 317.06 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 18.12.1 - /usr/local/opt/node@18/bin/node
Yarn: 1.22.11 - /usr/local/bin/yarn
npm: 8.19.2 - /usr/local/opt/node@18/bin/npm
Browsers:
Chrome: 107.0.5304.110
Firefox: 101.0
Safari: 16.1
npmPackages:
next: 13.0.4 => 13.0.4
next-auth: ^4.16.4 => 4.16.4
react: 18.2.0 => 18.2.0
neo4j-driver: ^5.2.0
swr: ^1.3.0
typescript: 4.9.3
npmPackages:
@next-auth/neo4j-adapter: ^1.0.5 => 1.0.5
Reproduction URL
https://github.com/vladutilie/issue-next-auth-neo4j
Describe the issue
Hello,
Vlad here, a Next.js and awesome-packages-related fan, enthusiast 😎 and hopefully a contributor to this community.
Since I've started to use Neo4j as Adapter for my NextAuth implementation, I got this error in logs and the client cannot get API responses if the focus of the page is lost. I'm using SWR to call an API endpoint which is using the
unstable_getServerSession
function to check if the user is authenticated.Long story short
🍀 I start the server, I open the page (let's say I'm authenticated) and all data from my API (fetched with SWR) is in place. I browse my page and so on, and all is perfect.
🍎 The issue occurs when I click on another tab (or just I open a new one), browse there for some seconds, and then come back to my initial tab - this will trigger SWR to revalidate (re-fetch) the date. The SWR fetch fails because the
unstable_getServerSession
function returns null 🤷🏻♂️ and at the same time I get the following error.The error I got
The error I got in VS code logs is the following:
What I have tried?
I have tried to call
session.close()
innode_modules/@next-auth/neo4j-adapter/dist/utils.js
like below, hoping for an eventually fix, but it was in vain:The error I got after my try
Cannot begin a transaction on a closed session. 🤦♂️
So I came here for another perspective. 🎩
Of course, I'm willing to help, just let me know how 😇.
How to reproduce
$ yarn install
$ cp .env.example .env
.env
file (you will need a Neo4j database instance - I'm using Neo4j Desktop for local development but you can use an AuraDB or something similar as well)$ npm run dev
in terminal{"user":{"email":"you@email.com"},"expires":"2022-12-18T20:12:48.651Z"}
/api/hello
endpoint in this case){"message":"Not authenticated."}
in the pageExpected behavior
After the 9th step from reproduction, on the page you should see the same text you saw first, something like
{"user":{"email":"you@email.com"},"expires":"2022-12-18T20:12:48.651Z"}
and the logs should not have that error, so theunstable_getServerSession
function should return the authenticated user data.The text was updated successfully, but these errors were encountered: