Last active
August 28, 2019 17:29
-
-
Save muhammadzaky15/f5bf0b062ef1b9e5aec6c77efd84d91c to your computer and use it in GitHub Desktop.
This file contains 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 passport = require('passport'); | |
const jwt = require('jsonwebtoken'); | |
const app = express(); | |
app.use( bodyParser.urlencoded({ extended : false }) ); | |
const router = express.Router(); | |
//handling untuk route /login | |
router.post('/login', async (req, res) => { | |
//data dummy (ganti dengan data dari database) | |
const body = { email : 'email@gmail.com' }; | |
//Logic Login (ganti dengan logic kalian sendiri) | |
if(req.body.email === body.email){ | |
//generate jwt menggunakan secret key 'node-js-indonesi' | |
const token = jwt.sign({ user : body },'node-js-indonesia'); | |
//response hasil generate token | |
return res.json({ token }); | |
} | |
return res.json({ | |
error: { | |
message: 'email salah' | |
} | |
}) | |
}); | |
app.use('/', router); | |
app.listen(4000, () => { | |
console.log('Server started') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment