mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
Merge pull request #1668 from TriliumNext/fix_redirectBareDomainError_on_initial_start
fix(auth): avoid "Error: Option 'redirectBareDomain' doesn't exist" on new installations
This commit is contained in:
commit
3df666b03e
@ -39,8 +39,12 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {
|
||||
res.redirect('login');
|
||||
return;
|
||||
} else if (!req.session.loggedIn && !noAuthentication) {
|
||||
const redirectToShare = options.getOptionBool("redirectBareDomain");
|
||||
if (redirectToShare) {
|
||||
|
||||
// cannot use options.getOptionBool currently => it will throw an error on new installations
|
||||
// TriliumNextTODO: look into potentially creating an getOptionBoolOrNull instead
|
||||
const hasRedirectBareDomain = options.getOptionOrNull("redirectBareDomain") === "true";
|
||||
|
||||
if (hasRedirectBareDomain) {
|
||||
// Check if any note has the #shareRoot label
|
||||
const shareRootNotes = attributes.getNotesWithLabel("shareRoot");
|
||||
if (shareRootNotes.length === 0) {
|
||||
@ -48,12 +52,14 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
res.redirect(redirectToShare ? "share" : "login");
|
||||
res.redirect(hasRedirectBareDomain ? "share" : "login");
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for electron things which need network stuff
|
||||
// currently, we're doing that for file upload because handling form data seems to be difficult
|
||||
function checkApiAuthOrElectron(req: Request, res: Response, next: NextFunction) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user