mirror of
https://github.com/zadam/trilium.git
synced 2024-11-11 09:46:25 +08:00
52 lines
No EOL
1 KiB
JavaScript
52 lines
No EOL
1 KiB
JavaScript
"use strict";
|
|
|
|
const migration = require('./migration');
|
|
|
|
async function checkAuth(req, res, next) {
|
|
if (!req.session.loggedIn) {
|
|
res.redirect("login");
|
|
}
|
|
else if (await migration.isDbUpToDate()) {
|
|
next();
|
|
}
|
|
else {
|
|
res.redirect("migration");
|
|
}
|
|
}
|
|
|
|
async function checkAuthWithoutMigration(req, res, next) {
|
|
if (!req.session.loggedIn) {
|
|
res.redirect("login");
|
|
}
|
|
else {
|
|
next();
|
|
}
|
|
}
|
|
|
|
async function checkApiAuth(req, res, next) {
|
|
if (!req.session.loggedIn) {
|
|
res.status(401).send({});
|
|
}
|
|
else if (await migration.isDbUpToDate()) {
|
|
next();
|
|
}
|
|
else {
|
|
res.status(409).send({}); // need better response than that
|
|
}
|
|
}
|
|
|
|
async function checkApiAuthWithoutMigration(req, res, next) {
|
|
if (!req.session.loggedIn) {
|
|
res.status(401).send({});
|
|
}
|
|
else {
|
|
next();
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
checkAuth,
|
|
checkAuthWithoutMigration,
|
|
checkApiAuth,
|
|
checkApiAuthWithoutMigration
|
|
}; |