MCPcopy Create free account
hub / github.com/azat-co/practicalnode / auth

Function auth

code/ch6/jwt-example/server.js:13–22  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

11]
12const users = []
13const auth = (req, res, next) => {
14 if (req.headers && req.headers.auth && req.headers.auth.split(' ')[0] === 'JWT') {
15 jwt.verify(req.headers.auth.split(' ')[1], SECRET, (error, decoded) => {
16 if (error) return res.status(401).send()
17 req.user = decoded
18 console.log('authenticated as ', decoded.username)
19 next()
20 })
21 } else return res.status(401).send()
22}
23
24app.get('/courses', (req, res) => {
25 res.send(courses)

Callers

nothing calls this directly

Calls 1

nextFunction · 0.50

Tested by

no test coverage detected