Skip to content

Instantly share code, notes, and snippets.

@roberttod
Last active May 18, 2017 20:50
Show Gist options
  • Save roberttod/e4e060c2087aa4a014999cea9f951e9d to your computer and use it in GitHub Desktop.
Save roberttod/e4e060c2087aa4a014999cea9f951e9d to your computer and use it in GitHub Desktop.
Tutorial: Node.js authentication
const express = require('express')
const bodyParser = require('body-parser')
const store = require('./store')
const app = express()
app.use(express.static('public'))
app.use(bodyParser.json())
app.post('/createUser', (req, res) => {
store
.createUser({
username: req.body.username,
password: req.body.password
})
.then(() => res.sendStatus(200))
})
app.post('/login', (req, res) => {
store
.authenticate({
username: req.body.username,
password: req.body.password
})
.then(({ success }) => {
if (success) res.sendStatus(200)
else res.sendStatus(401)
})
})
app.listen(7555, () => {
console.log('Server running on http://localhost:7555')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment