More refactoring
This commit is contained in:
parent
c2726898e5
commit
6505aa2f5e
4 changed files with 177 additions and 129 deletions
19
src/web/middleware/authorize.js
Normal file
19
src/web/middleware/authorize.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
const STATIC_RESOURCE = /\..+$/;
|
||||
|
||||
export default function initialize(app, session) {
|
||||
app.use((req, res, next) => {
|
||||
if (STATIC_RESOURCE.test(req.path)) {
|
||||
return next();
|
||||
} else if (!req.signedCookies || !req.signedCookies.auth) {
|
||||
return nuext();
|
||||
} else {
|
||||
session.verifySession(req.signedCookies.auth, (err, account) => {
|
||||
if (!err) {
|
||||
req.user = res.user = account;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue