From f3945463b7c43111ed7fa1197c4cbed98a74fb31 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Wed, 26 Feb 2025 18:32:20 +0100 Subject: [PATCH] Sync app settings at login/registration instead of page load --- app/Http/Controllers/SinglePageController.php | 14 ++++- .../js/composables/appSettingsUpdater.js | 3 -- resources/js/layouts/Footer.vue | 2 +- resources/js/router/index.js | 51 ++++++++++--------- .../js/router/middlewares/syncAppSettings.js | 12 +++++ resources/js/stores/appSettings.js | 13 +++-- resources/js/stores/user.js | 2 + resources/js/views/auth/Login.vue | 8 +-- resources/js/views/auth/Register.vue | 1 + resources/js/views/twofaccounts/Accounts.vue | 4 +- resources/lang/en/errors.php | 1 + 11 files changed, 71 insertions(+), 40 deletions(-) create mode 100644 resources/js/router/middlewares/syncAppSettings.js diff --git a/app/Http/Controllers/SinglePageController.php b/app/Http/Controllers/SinglePageController.php index ef2c9b69..035f672a 100644 --- a/app/Http/Controllers/SinglePageController.php +++ b/app/Http/Controllers/SinglePageController.php @@ -19,7 +19,19 @@ public function index() { event(new ScanForNewReleaseCalled); - $settings = Settings::all()->toJson(); + // We only share necessary and acceptable values with the HTML front-end. + // But all the properties have to be pushed to init the appSetting store state correctly, + // so we set them to null, they will be fed later by the front-end + $appSettings = Settings::all(); + $publicSettings = $appSettings->only([ + 'disableRegistration', + 'enableSso', + 'useSsoOnly' + ]); + $settings = $appSettings->map(function (mixed $item, string $key) { + return null; + })->merge($publicSettings)->toJson(); + $proxyAuth = config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false; $proxyLogoutUrl = config('2fauth.config.proxyLogoutUrl') ? config('2fauth.config.proxyLogoutUrl') : false; $subdir = config('2fauth.config.appSubdirectory') ? '/' . config('2fauth.config.appSubdirectory') : ''; diff --git a/resources/js/composables/appSettingsUpdater.js b/resources/js/composables/appSettingsUpdater.js index 66381197..1e02471c 100644 --- a/resources/js/composables/appSettingsUpdater.js +++ b/resources/js/composables/appSettingsUpdater.js @@ -1,5 +1,4 @@ import appSettingService from '@/services/appSettingService' -import { useAppSettingsStore } from '@/stores/appSettings' import { useNotifyStore } from '@/stores/notify' /** @@ -9,13 +8,11 @@ import { useNotifyStore } from '@/stores/notify' */ export async function useAppSettingsUpdater(setting, value, returnValidationError = false) { - // const appSettings = useAppSettingsStore() let data = null let error = null await appSettingService.update(setting, value, { returnError: true }) .then(response => { - // appSettings[setting] = value data = value useNotifyStore().success({ type: 'is-success', text: trans('settings.forms.setting_saved') }) }) diff --git a/resources/js/layouts/Footer.vue b/resources/js/layouts/Footer.vue index abfc9fe0..5def7d0e 100644 --- a/resources/js/layouts/Footer.vue +++ b/resources/js/layouts/Footer.vue @@ -79,7 +79,7 @@