Tell us what’s happening:
My code throws me an error and I couldn’t pass the part of ‘Database connection should be present’. There are some things I guess that may cause the error. However, I still couldn’t figure out the problem and solve it. I would appreciate any help. Thanks!
express-session deprecated req.secret; provide secret option server.js:18:9
TypeError: Cannot read property 'split' of null
at parseSrvConnectionString (/home/runner/boilerplate-advancednode/node_modules/mongodb/lib/core/uri_parser.js:44:23)
at parseConnectionString (/home/runner/boilerplate-advancednode/node_modules/mongodb/lib/core/uri_parser.js:587:12)
(1) MONGO_URL
I couldn’t add or find .env file, so I used Secrets (Environment variables) to create const mySecret in connection.js file.
- key: MONGO_URL
- value: ‘mongodb+srv://[ID]:[PW]@cluster0.6hk0t.mongodb.net/myFirstDatabase?retryWrites=true&w=majority’
const mySecret = process.env['MONGO_URL']
async function main(callback) {
const URI = mySecret;
...
(2) TypeError: Cannot read property ‘split’ of null
I tried to change null to “” in the following code.
- Reference link: Javascript: ncaught TypeError: Cannot read property 'split' of null - Stack Overflow
passport.serializeUser((user, done) => {
done(null, user._id);
});
passport.deserializeUser( (id, done) => {
myDataBase.findOne({ _id: new ObjectID(id) }, (err, doc) => {
done("", doc);
});
});
(3) Error: secret option required for sessions
I guess it tells an error on here, but I am not sure what needs to be done.
app.use(session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
cookie: { secure: false }
}));
Your code so far
Here is the link to my replit.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36
Challenge: Implement the Serialization of a Passport User
Link to the challenge: