No auth and req.user for cover images

This commit is contained in:
mikiher 2024-11-02 15:17:11 +02:00
parent 9e990d7927
commit 4224b8a486
2 changed files with 27 additions and 7 deletions

View file

@ -18,6 +18,26 @@ class Auth {
constructor() {
// Map of openId sessions indexed by oauth2 state-variable
this.openIdAuthSession = new Map()
this.ignorePattern = /\/api\/items\/[^/]+\/cover/
}
/**
* Checks if the request should not be authenticated.
* @param {import('express').Request} req
* @returns {boolean}
* @private
*/
authNotNeeded(req) {
return req.method === 'GET' && this.ignorePattern.test(req.originalUrl)
}
ifAuthNeeded(middleware) {
return (req, res, next) => {
if (this.authNotNeeded(req)) {
return next()
}
middleware(req, res, next)
}
}
/**