Next.js Discord

Discord Forum

can I use connect-mongodb-session package inside a next js application ?

Unanswered
i_lost_to_loba_kreygasm posted this in #help-forum
Open in Discord
How can I use this package inside a next js app to provide session using mongodb ?
https://www.npmjs.com/package/connect-mongodb-session

27 Replies

var store = new MongoDBStore({
  uri: 'mongodb://127.0.0.1:27017/connect_mongodb_session_test',
  collection: 'mySessions'
});
You can use this in any server file?
I don't know about app.use()
but you can do this since next.js is technicall a server
@averydelusionalperson I don't know about app.use()
this has me confused too , is it possible to do app.use() ?
I don't think so
but, may I ask, what is use of this mongodbstore?
its for session management using mongdoDB 🙂
session as in doing db requests?
i think this should answer your question
hmm
wait ,is req.cookies possible in next js ?
where do you need cookies?
U can get that in server action or api route
middleware too
@averydelusionalperson where do you need cookies?
for session, like I would read the cookies and then get the cookie id and search for it in MongoDb
like in sessions collections
@Ray this package is for express. have you tried next-auth with mongodb adapter?
can you describe more ? or what I need to research on ?
@Ray https://authjs.dev/reference/adapter/mongodb
pages/api/auth/[...nextauth].js
so I make a file like this and paste it ?
app/api/auth/[...nextauth]/route.ts
if you are using app router
@Ray yes if you are using page router
ok so this what it looks like ,what next ?