MCPcopy
hub / github.com/dwyl/learn-json-web-tokens / validate

Function validate

example/lib/helpers.js:116–141  ·  view source on GitHub ↗
(req, res, callback)

Source from the content-addressed store, hash-verified

114}
115
116function validate(req, res, callback) {
117 var token = req.headers.authorization;
118 var decoded = verify(token);
119 if(!decoded || !decoded.auth) {
120 authFail(res);
121 return callback(res);
122
123 } else {
124 // check if a key exists, else import word list:
125 db.get(decoded.auth, function (err, record) {
126 var r;
127 try {
128 r = JSON.parse(record);
129 } catch (e) {
130 r = { valid : false };
131 }
132 if (err || !r.valid) {
133 authFail(res);
134 return callback(res);
135 } else {
136 privado(res, token);
137 return callback(res);
138 }
139 });
140 }
141}
142
143function exit(res) {
144 res.writeHead(404, {'content-type': 'text/plain'});

Callers

nothing calls this directly

Calls 3

verifyFunction · 0.85
authFailFunction · 0.85
privadoFunction · 0.85

Tested by

no test coverage detected