Last active
January 9, 2019 15:15
-
-
Save nomoney4me/66d57fb972abe9858778322e9169797b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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