diff --git a/src/public/app/widgets/type_widgets/options/other/share_settings.ts b/src/public/app/widgets/type_widgets/options/other/share_settings.ts index d90840948..d7743c63c 100644 --- a/src/public/app/widgets/type_widgets/options/other/share_settings.ts +++ b/src/public/app/widgets/type_widgets/options/other/share_settings.ts @@ -1,6 +1,7 @@ import OptionsWidget from "../options_widget.js"; import options from "../../../../services/options.js"; import { t } from "../../../../services/i18n.js"; +import type { OptionMap, OptionNames } from "../../../../../../services/options_interface.js"; const TPL = `
@@ -27,9 +28,12 @@ export default class ShareSettingsOptions extends OptionsWidget { doRender() { this.$widget = $(TPL); this.contentSized(); + + // Add change handlers for both checkboxes + this.$widget.find('input[type="checkbox"]').on('change', () => this.save()); } - async optionsLoaded(options: Record) { + async optionsLoaded(options: OptionMap) { this.$widget.find('input[name="redirectBareDomain"]').prop('checked', options.redirectBareDomain === 'true'); @@ -39,9 +43,9 @@ export default class ShareSettingsOptions extends OptionsWidget { async save() { const redirectBareDomain = this.$widget.find('input[name="redirectBareDomain"]').prop('checked'); - await this.updateOption('redirectBareDomain', redirectBareDomain.toString()); + await this.updateOption<'redirectBareDomain'>('redirectBareDomain', redirectBareDomain.toString()); const showLoginInShareTheme = this.$widget.find('input[name="showLoginInShareTheme"]').prop('checked'); - await this.updateOption('showLoginInShareTheme', showLoginInShareTheme.toString()); + await this.updateOption<'showLoginInShareTheme'>('showLoginInShareTheme', showLoginInShareTheme.toString()); } } diff --git a/src/routes/api/options.ts b/src/routes/api/options.ts index 14cb7ec42..85272ea62 100644 --- a/src/routes/api/options.ts +++ b/src/routes/api/options.ts @@ -72,7 +72,9 @@ const ALLOWED_OPTIONS = new Set([ "textNoteEditorMultilineToolbar", "layoutOrientation", "backgroundEffects", - "allowedHtmlTags" // Allow configuring HTML import tags + "allowedHtmlTags", + "redirectBareDomain", + "showLoginInShareTheme" ]); function getOptions() { diff --git a/src/services/auth.ts b/src/services/auth.ts index d89fad633..5ba56e426 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -7,6 +7,7 @@ import { isElectron } from "./utils.js"; import passwordEncryptionService from "./encryption/password_encryption.js"; import config from "./config.js"; import passwordService from "./encryption/password.js"; +import options from "./options.js"; import type { NextFunction, Request, Response } from "express"; const noAuthentication = config.General && config.General.noAuthentication === true; @@ -15,7 +16,8 @@ function checkAuth(req: Request, res: Response, next: NextFunction) { if (!sqlInit.isDbInitialized()) { res.redirect("setup"); } else if (!req.session.loggedIn && !isElectron && !noAuthentication) { - res.redirect("share"); + const redirectToShare = options.getOption('redirectBareDomain') === 'true'; + res.redirect(redirectToShare ? "share" : "login"); } else { next(); }