This commit is contained in:
counterweight 2025-03-06 00:46:51 +01:00
parent c4131c82aa
commit 3623ff11cb
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 21 additions and 11 deletions

View file

@ -1,5 +1,3 @@
const redirectIfMissingProfileDetailsMiddleware = require('./redirectIfMissingProfileDetailsMiddleware');
const sessionService = require('../services/sessionService');
const AttachPublicKeyMiddlewareProvider = require('./attachPublicKeyMiddleware');
const attachPublicKeyMiddleware = new AttachPublicKeyMiddlewareProvider(
@ -28,6 +26,13 @@ const redirectIfNotAuthorizedMiddleware = new RedirectIfNotAuthorizedMiddleware(
{ sessionService }
).provide();
const profileService = require('../services/profileService');
const RedirectIfMissingProfileDetailsMiddleware = require('./redirectIfMissingProfileDetailsMiddleware');
const redirectIfMissingProfileDetailsMiddleware =
new RedirectIfMissingProfileDetailsMiddleware({
profileService,
}).provide();
module.exports = {
redirectIfNotAuthorizedMiddleware,
attachPublicKeyMiddleware,

View file

@ -1,12 +1,17 @@
const profileService = require('../services/profileService');
class RedirectIfMissingProfileDetailsMiddleware {
constructor({ profileService }) {
this.profileService = profileService;
}
async function redirectIfMissingProfileDetailsMiddleware(req, res, next) {
provide() {
return async (req, res, next) => {
const publicKey = req.cookies.publicKey;
if (!(await profileService.areProfileDetailsComplete(publicKey))) {
if (!(await this.profileService.areProfileDetailsComplete(publicKey))) {
res.redirect('/createProfile');
}
next();
};
}
}
module.exports = redirectIfMissingProfileDetailsMiddleware;
module.exports = RedirectIfMissingProfileDetailsMiddleware;