alpha release
update v0.8.0
This commit is contained in:
32
dist/src/middlewares/authCheckJWT.js
vendored
Normal file
32
dist/src/middlewares/authCheckJWT.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import Debug from 'debug';
|
||||
import jwt from 'jsonwebtoken';
|
||||
const debug = Debug('twtkpr:authCheckJWT');
|
||||
/**
|
||||
* Checks for a valid JWT, and returns a boolean indicating the result
|
||||
*
|
||||
* @param req
|
||||
* @returns
|
||||
*/
|
||||
export default async function authCheckJWT(req, config) {
|
||||
debug('beginning');
|
||||
const token = req.header('Authorization')?.split(' ')[1];
|
||||
if (!token) {
|
||||
debug('no token');
|
||||
return false;
|
||||
}
|
||||
debug('token present');
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.accessSecret);
|
||||
debug({ decoded });
|
||||
if (!decoded.id)
|
||||
return false;
|
||||
req.username = decoded.id;
|
||||
}
|
||||
catch {
|
||||
debug('invalid token');
|
||||
return false;
|
||||
}
|
||||
debug('token good');
|
||||
return true;
|
||||
}
|
||||
//# sourceMappingURL=authCheckJWT.js.map
|
||||
Reference in New Issue
Block a user