trilium/services/auth.js

34 lines
639 B
JavaScript
Raw Normal View History

2017-10-22 09:10:33 +08:00
"use strict";
2017-10-26 10:39:21 +08:00
const migration = require('./migration');
async function checkAuth(req, res, next) {
2017-10-16 04:32:49 +08:00
if (!req.session.loggedIn) {
res.redirect("login");
2017-10-26 10:39:21 +08:00
}
if (await migration.isDbUpToDate()) {
2017-10-16 04:32:49 +08:00
next();
}
2017-10-26 10:39:21 +08:00
else {
res.redirect("migration");
}
2017-10-16 04:32:49 +08:00
}
2017-10-26 10:39:21 +08:00
async function checkApiAuth(req, res, next) {
if (!req.session.loggedIn && req.header("auth") !== "sync") {
2017-10-16 04:32:49 +08:00
res.sendStatus(401);
2017-10-26 10:39:21 +08:00
}
if (await migration.isDbUpToDate()) {
2017-10-16 04:32:49 +08:00
next();
}
2017-10-26 10:39:21 +08:00
else {
res.sendStatus(409); // need better response than that
}
2017-10-16 04:32:49 +08:00
}
module.exports = {
checkAuth,
checkApiAuth
};