| @@ 388-418 (lines=31) @@ | ||
| 385 | checkToken: function(req, res, next) { |
|
| 386 | var token = req.headers['x-access-token']; |
|
| 387 | ||
| 388 | if (token) { |
|
| 389 | jwt.verify(token, jwtSecret, function(err, decoded) { |
|
| 390 | if (err) { |
|
| 391 | return res.status(500).json({ |
|
| 392 | errors: { |
|
| 393 | status: 500, |
|
| 394 | source: req.path, |
|
| 395 | title: "Failed authentication", |
|
| 396 | detail: err.message |
|
| 397 | } |
|
| 398 | }); |
|
| 399 | } |
|
| 400 | ||
| 401 | req.user = {}; |
|
| 402 | req.user.api_key = decoded.api_key; |
|
| 403 | req.user.email = decoded.email; |
|
| 404 | ||
| 405 | next(); |
|
| 406 | ||
| 407 | return undefined; |
|
| 408 | }); |
|
| 409 | } else { |
|
| 410 | return res.status(401).json({ |
|
| 411 | errors: { |
|
| 412 | status: 401, |
|
| 413 | source: req.path, |
|
| 414 | title: "No token", |
|
| 415 | detail: "No token provided in request headers" |
|
| 416 | } |
|
| 417 | }); |
|
| 418 | } |
|
| 419 | } |
|
| 420 | }; |
|
| 421 | ||
| @@ 252-280 (lines=29) @@ | ||
| 249 | function checkToken(req, res, next) { |
|
| 250 | var token = req.headers['x-access-token']; |
|
| 251 | ||
| 252 | if (token) { |
|
| 253 | jwt.verify(token, jwtSecret, function(err, decoded) { |
|
| 254 | if (err) { |
|
| 255 | return res.status(500).json({ |
|
| 256 | errors: { |
|
| 257 | status: 500, |
|
| 258 | source: req.path, |
|
| 259 | title: "Failed authentication", |
|
| 260 | detail: err.message |
|
| 261 | } |
|
| 262 | }); |
|
| 263 | } |
|
| 264 | ||
| 265 | req.user = {}; |
|
| 266 | req.user.api_key = decoded.api_key; |
|
| 267 | req.user.email = decoded.email; |
|
| 268 | ||
| 269 | next(); |
|
| 270 | }); |
|
| 271 | } else { |
|
| 272 | return res.status(401).json({ |
|
| 273 | errors: { |
|
| 274 | status: 401, |
|
| 275 | source: req.path, |
|
| 276 | title: "No token", |
|
| 277 | detail: "No token provided in request headers" |
|
| 278 | } |
|
| 279 | }); |
|
| 280 | } |
|
| 281 | } |
|
| 282 | ||
| 283 | return { |
|