Last active
May 18, 2017 20:50
-
-
Save roberttod/e4e060c2087aa4a014999cea9f951e9d to your computer and use it in GitHub Desktop.
Tutorial: Node.js authentication
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 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