storing contact details works
This commit is contained in:
parent
00fc6bb258
commit
6b52d06b3e
10 changed files with 138 additions and 15 deletions
13
src/middlewares/attachPublicKeyMiddleware.js
Normal file
13
src/middlewares/attachPublicKeyMiddleware.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const sessionService = require('../services/sessionService');
|
||||
|
||||
async function attachPublicKeyMiddleware(req, res, next) {
|
||||
|
||||
const publicKey = await sessionService.getPublicKeyRelatedToSession(
|
||||
req.cookies.sessionUuid
|
||||
)
|
||||
req.cookies.publicKey = publicKey;
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = attachPublicKeyMiddleware;
|
||||
13
src/middlewares/rejectIfNotAuthorizedMiddleware.js
Normal file
13
src/middlewares/rejectIfNotAuthorizedMiddleware.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const sessionService = require('../services/sessionService');
|
||||
|
||||
async function rejectIfNotAuthorizedMiddleware(req, res, next) {
|
||||
if (!(await sessionService.isSessionAuthorized(req.cookies.sessionUuid))) {
|
||||
return res.status(403).json({
|
||||
success: false,
|
||||
message: 'Your session is not authorized.'
|
||||
})
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = rejectIfNotAuthorizedMiddleware;
|
||||
|
|
@ -13,25 +13,19 @@ async function createSessionMiddleware(req, res, next) {
|
|||
|
||||
const sessionUuid = req.cookies.sessionUuid;
|
||||
|
||||
console.log("Running cookie middleware")
|
||||
|
||||
if (!sessionUuid) {
|
||||
console.log("Found no cookie")
|
||||
const newSession = await setAndPersistNewSession(res);
|
||||
req.cookies.sessionUuid = newSession.uuid;
|
||||
|
||||
}
|
||||
|
||||
if (sessionUuid) {
|
||||
console.log(`Found a cookie ${sessionUuid}`)
|
||||
if (!(await sessionService.isSessionValid(sessionUuid))) {
|
||||
console.log("But it's not valid")
|
||||
const newSession = await setAndPersistNewSession(res);
|
||||
req.cookies.sessionUuid = newSession.uuid;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Moving on...")
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue