Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VILLASweb-backend-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ACS
Public
VILLASframework
VILLASweb-backend-node
Commits
78a7b057
Commit
78a7b057
authored
7 years ago
by
Markus Grigull
Browse files
Options
Downloads
Patches
Plain Diff
Validate token user
parent
77837adb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
auth.js
+12
-3
12 additions, 3 deletions
auth.js
with
12 additions
and
3 deletions
auth.js
+
12
−
3
View file @
78a7b057
...
...
@@ -25,6 +25,8 @@ var jwt = require('jsonwebtoken');
var
config
=
require
(
'
./config
'
)[
process
.
env
.
NODE_ENV
||
'
development
'
];
var
roles
=
require
(
'
./roles
'
);
var
User
=
require
(
'
./models/user
'
);
module
.
exports
=
{
validateToken
:
function
(
req
,
res
,
next
)
{
// check for token
...
...
@@ -38,9 +40,16 @@ module.exports = {
return
res
.
status
(
403
).
send
({
success
:
false
,
message
:
'
Authentication failed
'
});
}
// save to request in other routes
req
.
decoded
=
decoded
;
next
();
// check if decoded user is valid
User
.
findOne
({
_id
:
decoded
.
_id
},
function
(
err
,
user
)
{
if
(
err
)
{
return
res
.
status
(
403
).
send
({
success
:
false
,
message
:
'
Authentication failed
'
});
}
// save to request in other routes
req
.
decoded
=
decoded
;
next
();
});
});
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment