mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	fix(auth): avoid "Error: Option 'redirectBareDomain' doesn't exist" on new installations
fixes #1667
This commit is contained in:
		| @@ -39,7 +39,9 @@ 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"); |  | ||||||
|  |         const redirectToShare = hasRedirectBareDomain(); | ||||||
|  |  | ||||||
|         if (redirectToShare) { |         if (redirectToShare) { | ||||||
|             // 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"); | ||||||
| @@ -54,6 +56,18 @@ function checkAuth(req: Request, res: Response, next: NextFunction) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // 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 | // 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) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user