Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(auth): simplify hasRedirectBareDomain
Panagiotis Papadopoulos1979affa8a62
diff --git a/src/services/auth.ts b/src/services/auth.tsindex 38eb198233..d1d951fc0c 100644--- a/src/services/auth.ts+++ b/src/services/auth.ts@@ -40,9 +40,11 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {return;} else if (!req.session.loggedIn && !noAuthentication) {- const redirectToShare = hasRedirectBareDomain();+ // 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 (redirectToShare) {+ if (hasRedirectBareDomain) {// Check if any note has the #shareRoot labelconst shareRootNotes = attributes.getNotesWithLabel("shareRoot");if (shareRootNotes.length === 0) {@@ -50,23 +52,13 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {return;}}- res.redirect(redirectToShare ? "share" : "login");+ res.redirect(hasRedirectBareDomain ? "share" : "login");} else {next();}}-// avoid receiving an error, on a new installation, when the DB is not initialized yet-// => getOptionBool uses getOption, which throws an error if the option name is not found-// TriliumNextTODO: potentially refactor getOptionBool instead-function hasRedirectBareDomain() {- try {- return options.getOptionBool("redirectBareDomain");- } catch(e) {- return false;- }-}// for electron things which need network stuff// currently, we're doing that for file upload because handling form data seems to be difficult