mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 11:56:01 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			54 lines
		
	
	
		
			1002 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1002 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
const migration = require('./migration');
 | 
						|
 | 
						|
async function checkAuth(req, res, next) {
 | 
						|
    if (!req.session.loggedIn) {
 | 
						|
        res.redirect("login");
 | 
						|
    }
 | 
						|
 | 
						|
    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.sendStatus(401);
 | 
						|
    }
 | 
						|
 | 
						|
    if (await migration.isDbUpToDate()) {
 | 
						|
        next();
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        res.sendStatus(409); // need better response than that
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
async function checkApiAuthWithoutMigration(req, res, next) {
 | 
						|
    if (!req.session.loggedIn) {
 | 
						|
        res.sendStatus(401);
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        next();
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
module.exports = {
 | 
						|
    checkAuth,
 | 
						|
    checkAuthWithoutMigration,
 | 
						|
    checkApiAuth,
 | 
						|
    checkApiAuthWithoutMigration
 | 
						|
}; |