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:
Elian Doran 2025-04-10 20:52:54 +03:00 committed by GitHub
commit 3df666b03e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,8 +39,12 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {
res.redirect('login'); res.redirect('login');
return; return;
} else if (!req.session.loggedIn && !noAuthentication) { } 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 // Check if any note has the #shareRoot label
const shareRootNotes = attributes.getNotesWithLabel("shareRoot"); const shareRootNotes = attributes.getNotesWithLabel("shareRoot");
if (shareRootNotes.length === 0) { if (shareRootNotes.length === 0) {
@ -48,12 +52,14 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {
return; return;
} }
} }
res.redirect(redirectToShare ? "share" : "login"); res.redirect(hasRedirectBareDomain ? "share" : "login");
} else { } else {
next(); next();
} }
} }
// for electron things which need network stuff // for electron things which need network stuff
// currently, we're doing that for file upload because handling form data seems to be difficult // currently, we're doing that for file upload because handling form data seems to be difficult
function checkApiAuthOrElectron(req: Request, res: Response, next: NextFunction) { function checkApiAuthOrElectron(req: Request, res: Response, next: NextFunction) {