In docs of connect-mongo
I read only about it set up, nothing more. How to define sessions? How to read?
const mongoose = require("mongoose");
mongoose.Promise = Promise;
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
mongoose.connect('mongodb://localhost/MYDATABASE');
app.use(session({
secret: "SOME_SECRET_KEY",
store: new MongoStore({ mongooseConnection: mongoose.connection })
}));
Okay, I set up. If I have
app.get("/login", function(req, res){
// If user authorized
// I want to define a session.user = req.body.user
// And then I want to read this value in other my site pages
});
How I can define user login and some other data to session?
How I can read this values?
Where this session will store in MongoDB? Or I need to define not only way to MYDATABASE and to MYDATABASE/sessionstore ?
Must I to generate secret or this must be a one defined string?
Reading from and writing to the session is done through the req.session
object: req.session.userId = req.body.userId
The session data will be stored in a collection called sessions
by
default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With