can I use connect-mongodb-session package inside a next js application ?
Unanswered
i_lost_to_loba_kreygasm posted this in #help-forum
How can I use this package inside a next js app to provide session using mongodb ?
https://www.npmjs.com/package/connect-mongodb-session
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?
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
@i_lost_to_loba_kreygasm How can I use this package inside a next js app to provide session using mongodb ?
https://www.npmjs.com/package/connect-mongodb-session
this package is for express. have you tried next-auth with mongodb adapter?
@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 ?@i_lost_to_loba_kreygasm pages/api/auth/[...nextauth].js
so I make a file like this and paste it ?
yes if you are using page router
app/api/auth/[...nextauth]/route.tsif you are using app router
@i_lost_to_loba_kreygasm ok so this what it looks like ,what next ?
setup next-auth with this guide
https://authjs.dev/guides/upgrade-to-v5
https://authjs.dev/guides/upgrade-to-v5