Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tma-backend
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Denys Tito Urbano
tma-backend
Commits
e2d42648
Commit
e2d42648
authored
Aug 29, 2022
by
Denys Tito Urbano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Middlewares agregados
parent
4d2b4e61
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
+47
-0
index.js
middlewares/index.js
+8
-0
validate_errors.js
middlewares/validate_errors.js
+16
-0
validate_jwt.js
middlewares/validate_jwt.js
+23
-0
No files found.
middlewares/index.js
0 → 100644
View file @
e2d42648
const
{
validate_errors
}
=
require
(
'../middlewares/validate_errors'
);
const
{
validate_jwt
}
=
require
(
'../middlewares/validate_jwt'
);
module
.
exports
=
{
validate_errors
,
validate_jwt
};
\ No newline at end of file
middlewares/validate_errors.js
0 → 100644
View file @
e2d42648
const
{
validationResult
}
=
require
(
'express-validator'
);
const
validate_errors
=
(
req
,
res
,
next
)
=>
{
const
errors
=
validationResult
(
req
);
if
(
!
errors
.
isEmpty
())
{
return
res
.
status
(
400
).
json
({
status
:
false
,
errors
:
errors
.
array
()
});
}
next
();
};
module
.
exports
=
{
validate_errors
};
\ No newline at end of file
middlewares/validate_jwt.js
0 → 100644
View file @
e2d42648
const
{
verify
}
=
require
(
'jsonwebtoken'
);
const
validate_jwt
=
async
(
req
,
res
,
next
)
=>
{
try
{
const
token
=
req
.
header
(
'Authorization'
).
replace
(
'Bearer'
,
''
).
trim
();
if
(
!
token
)
{
res
.
status
(
401
).
json
({
message
:
'No hay un token en la petición'
});
}
const
{
documento
}
=
verify
(
token
,
process
.
env
.
SECRET_KEY
);
req
.
params
.
documento
=
documento
;
next
();
}
catch
(
error
)
{
res
.
status
(
401
).
json
({
message
:
'Token no válido'
});
}
};
module
.
exports
=
{
validate_jwt
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment