This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
hymenobacterdotinfo/server/mocks/authenticate.js
2015-03-26 10:43:36 -08:00

30 lines
813 B
JavaScript

module.exports = function(app) {
var express = require('express');
var jwt = require('jsonwebtoken');
var authenticateRouter = express.Router();
authenticateRouter.post('/', function(req, res) {
// wait for a bit to simulate cold boot of heroku api
var ms = 3000 + new Date().getTime();
while (new Date() < ms){}
if (req.body.username === 'test' && req.body.password === 'test') {
var token = jwt.sign({
'name': 'Test User',
'role': 'admin'
}, 'secret',
{
expiresInMinutes: 60,
issuer: 'bactdb',
subject: 'Test User',
});
res.send({
'token': token
});
} else {
res.status(401).send({'error':'Invalid username or password'});
}
});
app.use('/api/authenticate', authenticateRouter);
};