Skip to content

Instantly share code, notes, and snippets.

@nomoney4me
Last active January 9, 2019 15:15
Show Gist options
  • Select an option

  • Save nomoney4me/66d57fb972abe9858778322e9169797b to your computer and use it in GitHub Desktop.

Select an option

Save nomoney4me/66d57fb972abe9858778322e9169797b to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
const session = require('express-session');
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { secure: true }
}))
app.post('/login', (req, res) => {
//check against whatever database you want and return a value (ie. userid, username)
let username = req.body.username;
req.session.user = username;
})
app.get('/private', (req, res) => {
//check req.session.user and do whatever else you want
})
app.listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment