9/18/2023 0 Comments Session node![]() ![]() Suppose we have code that looks like this in a session.js: app. nnect('m very new to learning Node and Express, and I'm still trying to wrap my head around the code flow with express. ![]() ![]() const mongoose = require('mongoose') Ĭonst passportLocalMongoose = require('passport-local-mongoose') Setting up user schema with MongoDBĬreate a new file in the root directory named userDetails.js. The req.logout() is a passport method that logs out the user. We are also passing the title of the pages through the title variable. Otherwise, itâll redirect to the login route. Inside the POST route, the thenticate middleware authenticates the user with local strategy, and, if the user succeeds in logging in, itâll redirect to the secret route. The connectEnsureLogin.ensureLoggedIn() middleware in the secret route ensures that the user is prohibited from entering the page without logging in. First, we have added the necessary packages. Install the dev dependency using npm i -D nodemon, then change the scripts section of the package.json file with these two lines: "scripts": )Īs you can see from the above code, we have three GET routes and one POST route. Npm i express mongoose ejs express-ejs-layouts dotenv connect-ensure-login passport passport-local-mongoose express-session
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |