Created
November 4, 2019 09:48
-
-
Save louicoder/1d99e64fcb32b5a3f1dbda633a938a44 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 app = require('express')(), | |
env = require('dotenv').config(), | |
JWT = require('jsonwebtoken'), | |
bodyParser = require('body-parser'); | |
// support parsing of application/json type post data | |
app.use(bodyParser.json()); | |
//support parsing of application/x-www-form-urlencoded post data | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.post('/token', (req, res) => { | |
const payload = { | |
userType: req.body.userType || '' | |
}; | |
// console.log('env', env.parsed.AUTHY_SECRET); // This can be any in any environmental variable for yonja | |
const Token = JWT.sign(payload, env.parsed.AUTHY_SECRET, { | |
algorithm: 'HS256', | |
expiresIn: '24h', | |
subject: 'authy_verification' | |
}); | |
return res.json({ Token }); | |
}); | |
app.listen(env.parsed.PORT || 3000, function () { | |
console.log('Server is running at 3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create env file and add AUTHY_SECRET and its value like
[AUTHY_SECRET=xxxxxxxxxxxxxx]
and another key PORT like[PORT=3000]
.