KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
so I basically want to use sessions to store the users name and check to see if the user logged in or not. If not, the page will redirect to the login page. I am using Node.js,express,and couchDB. Here is how i set up my session so far var MemoryStore = require('connect').session.MemoryStore; app.use(express.cookieParser()); app.use(express.session({ secret: "keyboard cat", store: new MemoryStore({ reapInterval: 60000 * 10 }) })); To store something in the session, i use the following code right? req.session = {user:name); So the session variable seems to work on my login page. I successfully store the user's name into the session However, when I try to access the session variable on another page, it gives me the error Cannot read property 'user' of undefined all i'm doing is: if (req.session.user){ Why is this error happening? are sessions not global to the whole app? Or am I missing something entirely here. Thanks in advance!
Tags (comma-separated)
Save Edits
Cancel