new model model

This commit is contained in:
2020-04-09 22:22:54 -04:00
parent 1e3203408c
commit 255d6568fd
17 changed files with 576 additions and 430 deletions

View File

@ -1,19 +1,17 @@
'use strict';
const Users = require('../models/users');
const {Auth} = require('../models/auth');
async function auth(req, res, next){
if(req.header('auth-token')){
let user = await Users.checkToken({token: req.header('auth-token')});
try{
let user = await Auth.checkToken({token: req.header('auth-token')});
if(user.username){
req.user = user;
return next();
}
}catch(error){
next(error);
}
return res.status(401).json({
message: 'Login failed'
});
}
module.exports = {auth};