refactor first middleware
This commit is contained in:
parent
d34e62070a
commit
3c5aa812ab
2 changed files with 23 additions and 12 deletions
|
|
@ -1,14 +1,20 @@
|
|||
const sessionService = require('../services/sessionService');
|
||||
|
||||
async function attachPublicKeyMiddleware(req, res, next) {
|
||||
const publicKey = await sessionService.getPublicKeyRelatedToSession(
|
||||
req.cookies.sessionUuid
|
||||
);
|
||||
|
||||
if (publicKey) {
|
||||
req.cookies.publicKey = publicKey;
|
||||
class AttachPublicKeyMiddlewareProvider {
|
||||
constructor(sessionService) {
|
||||
this.sessionService = sessionService;
|
||||
}
|
||||
|
||||
provide() {
|
||||
return async (req, res, next) => {
|
||||
const publicKey = await this.sessionService.getPublicKeyRelatedToSession(
|
||||
req.cookies.sessionUuid
|
||||
);
|
||||
|
||||
if (publicKey) {
|
||||
req.cookies.publicKey = publicKey;
|
||||
}
|
||||
next();
|
||||
};
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = attachPublicKeyMiddleware;
|
||||
module.exports = AttachPublicKeyMiddlewareProvider;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue