Closed donsn closed 7 months ago
How are you initializing the adapter? The MongoDB adapter has been tested against both mongodb
and mongoose
so I doubt it's a bug
@pilcrowOnPaper then I use the database connection anywhere it's needed
Like what are you passing to the adapter?
Passing the mongoose collection like this
What version of mongoose are you using?
Here's the version I'm using
"mongodb": "^6.3.0", "mongoose": "^8.1.0",
Might be a v8 issue, will test it out
I can't see to recreate the issue. Tested with MongoDB v6 and Mongoose v8. I'd need a basic reproduction.
I can't see to recreate the issue. Tested with MongoDB v6 and Mongoose v8. I'd need a basic reproduction.
@pilcrowOnPaper This happens when you call validateSession with the SessionID
We have tests for all adapter methods, including getSessionAndUser()
, and I'm not getting any error in both Mongoose v6 and v8.
I can't see to recreate the issue. Tested with MongoDB v6 and Mongoose v8. I'd need a basic reproduction.
I'm able to reproduce this with the same package versions and with an example. It seems to happen on first load (with a session cookie set) after restarting the app and clears after reloading the page. I haven't come across this error in any other scenarios.
Blank project and this works fine:
import mongoose from "mongoose";
await mongoose.connect(url);
const result = await mongoose.connection.collection("users").aggregate().toArray();
console.log(result);
I can't see to recreate the issue. Tested with MongoDB v6 and Mongoose v8. I'd need a basic reproduction.
I'm able to reproduce this with the same package versions and with an example. It seems to happen on first load (with a session cookie set) after restarting the app and clears after reloading the page. I haven't come across this error in any other scenarios.
Yes. It happens with a session cookie set
I'm trying to create an isolated scenario to find the root cause
Can't reproduce it:
import { Lucia, generateId } from "lucia";
import { MongodbAdapter } from "@lucia-auth/adapter-mongodb";
import mongoose from "mongoose";
const adapter = new MongodbAdapter(
mongoose.connection.collection("sessions"),
mongoose.connection.collection("users")
);
const lucia = new Lucia(adapter);
await mongoose.connect(process.env.MONGODB_URL);
const userId = generateId(15)
await mongoose.connection.collection("users").insertOne({
_id: userId as any,
username: "pilcrow"
})
const session = await lucia.createSession(userId, {});
const validatedSession = await lucia.validateSession(session.id);
What framework are you using?
I found my issue... I wasn't awaiting the connection. I think I removed it as it was throwing an ES target error that I couldn't resolve. Didn't realise with Nuxt you have to define the ES target for the Nitro server separately, solution.
@pilcrowOnPaper I did a sample here: https://github.com/donsn/lucia-auth-test
Yeah probably an issue with Mongoose. That said, I can't seem to recreate the issue in a simple project. I can't even use createConnection()
for some reason
Yeah probably an issue with Mongoose. That said, I can't seem to recreate the issue in a simple project. I can't even use
createConnection()
for some reason
Thank you
Package
@lucia-auth/adapter-mongodb
Describe the bug
The default integration with Lucia v3 is broken when you try to connect using MongoDB and Mongoose
Migrated fully as explained on the documentation, this doesn't work at the moment
It breaks at getSessionAndUser when you try to validate sessions