0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-29 17:42:38 +00:00

Shift JWT generation to app.js

This commit is contained in:
G.Ambatte
2022-04-13 12:40:16 +12:00
parent 0023e87d54
commit 1bdd08f878
2 changed files with 29 additions and 9 deletions

View File

@@ -259,6 +259,23 @@ app.get('/print/:id', asyncHandler(async (req, res, next)=>{
return next();
}));
const localEnvironments = config.get('local_environments');
// Login
app.post('/login', (req, res)=>{
// Local only
if(!localEnvironments.includes(config.get('node_env'))){
return;
}
const username = req.body.username;
if(!username) return;
const payload = jwt.encode({ username: username, issued: new Date }, config.get('secret'));
return res.json(payload);
});
//Render the page
const templateFn = require('./../client/template.js');
app.use((req, res)=>{
@@ -268,10 +285,8 @@ app.use((req, res)=>{
environment : config.get('node_env')
};
// Add local only items to configuration object
const localEnvironments = config.get('local_environments');
if(localEnvironments.includes(configuration.environment)){
configuration.local = true;
configuration.secret = config.get('secret');
};
const props = {
version : require('./../package.json').version,