-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(adapter-mongodb): Improve MongoDB connection handling for serverless environments #9459
fix(adapter-mongodb): Improve MongoDB connection handling for serverless environments #9459
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
@simonecervini is attempting to deploy a commit to the authjs Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the perfect usecase for the new using
keyword in TypeScript! Would you like to give it a try?
@balazsorban44 I've already tried it, but there are some issues with prettier when you do something like this: await using db = await getConnection(); This was fixed with prettier/prettier#15321, so we need to upgrade prettier first. |
Prettier bumped! 👍 |
Thank you @balazsorban44! I refactored the code to use It looks like EDIT: I can confirm this, with this diff all the tests pass diff --git a/packages/adapter-mongodb/package.json b/packages/adapter-mongodb/package.json
index 93a3e71b..928a6a8f 100644
--- a/packages/adapter-mongodb/package.json
+++ b/packages/adapter-mongodb/package.json
@@ -45,7 +45,8 @@
"mongodb": "^6"
},
"devDependencies": {
- "mongodb": "^6.0.0"
+ "mongodb": "^6.0.0",
+ "@hazae41/symbol-dispose-polyfill": "latest"
},
"jest": {
"preset": "utils/adapter"
diff --git a/packages/adapter-mongodb/tests/custom.test.ts b/packages/adapter-mongodb/tests/custom.test.ts
index acfe357f..46341b63 100644
--- a/packages/adapter-mongodb/tests/custom.test.ts
+++ b/packages/adapter-mongodb/tests/custom.test.ts
@@ -1,3 +1,5 @@
+import "@hazae41/symbol-dispose-polyfill"
+
import { runBasicTests } from "utils/adapter"
import { defaultCollections, format, MongoDBAdapter, _id } from "../src"
import { MongoClient } from "mongodb"
diff --git a/packages/adapter-mongodb/tests/index.test.ts b/packages/adapter-mongodb/tests/index.test.ts
index 0dc84820..36882b99 100644
--- a/packages/adapter-mongodb/tests/index.test.ts
+++ b/packages/adapter-mongodb/tests/index.test.ts
@@ -1,3 +1,4 @@
+import "@hazae41/symbol-dispose-polyfill"
import { runBasicTests } from "utils/adapter"
import { defaultCollections, format, MongoDBAdapter, _id } from "../src"
import { MongoClient } from "mongodb" Actually, the one-liner polyfill |
I'm getting this error with this version of the adapter: [auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror I have this issue with the published version too anyway though. Is it not a better idea to create the client with the MONGODB_URI ENV instead of passing in a Promise? |
b6cef2f
to
3a0d0df
Compare
Can you give this antoher shot? Specifically check out the new test that was added here if you want to see an implementation example 🙏 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9459 +/- ##
==========================================
- Coverage 40.85% 38.80% -2.06%
==========================================
Files 176 176
Lines 27893 27914 +21
Branches 1242 1224 -18
==========================================
- Hits 11397 10831 -566
- Misses 16496 17083 +587 ☔ View full report in Codecov by Sentry. |
@simonecervini can you move the Also I'm having trouble with the a few of the tests. First, that Anyway, after we clear that up I think it'll be good to go! |
It was probably related to #9818 It should be fixed now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
☕️ Reasoning
This PR, opened as requested by @ndom91, revises and builds on the work from #8753.
It integrates the new changes into the existing MongoDB adapter.
🧢 Checklist
🎫 Affected issues
Fixes: #8411
📌 Resources