Skip to content

Commit

Permalink
con validacion de token para cargar link's y eliminarlos
Browse files Browse the repository at this point in the history
  • Loading branch information
ottino committed Sep 22, 2020
1 parent 1ab0e06 commit 35fea3d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ process.env.URLDB = urlDB;
// 60 minutos
// 24 horas
// 30 dias
process.env.CADUCIDAD_TOKEN = 60 * 60 * 24 * 30;
process.env.CADUCIDAD_TOKEN = 60 * 60 * 24 * 700;

// ================================
// SEED de autenticacion (semilla)
Expand Down
20 changes: 18 additions & 2 deletions middlewares/autenticacion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ let verificarToken = ( req, res, next ) => {

let body = req['body'];
let token = body['token'];
console.log({token});

console.log( 'token', body );
jwt.verify( token , process.env.SEED , (err, decoded) => {

next();

if ( err ) {

return res.status(401).json({
ok:false,
err: {
error: err,
message: 'Token no válido'
}
});

}

req.usuario = decoded.usuario;

next();
});
}

module.exports = {
Expand Down
40 changes: 13 additions & 27 deletions routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,42 +87,28 @@ app.post('/login', (req, res) => {

});

app.get('/', verificarToken , (req, res)=>{

let desde = req.query.desde || 0;
desde = Number(desde);

let limite = req.query.limite || 5;
limite = Number(limite);
app.get('/', (req, res)=>{

Link.find({ /*estado: true*/ }, 'fecha link')
.skip(desde)
.limit(limite)
.exec( (err, links) => {

if ( err ) {
return res.status(400).json({
ok: false,
err
});
}

Link.count({ /*estado: true*/ }, (err, conteo)=> {


res.json({
ok:true,
links,
cantidad: conteo
});
if ( err ) {
return res.status(400).json({
ok: false,
err
});
}

});
res.json({
ok:true,
links
});

});
});

});

app.delete('/link/:id', function (req,res) {
app.delete('/link/:id', verificarToken , function (req,res) {

let id = req.params.id;

Expand Down

0 comments on commit 35fea3d

Please sign in to comment.