Feature: System settings in DB - configurable backend URLs and API key

This commit is contained in:
cynfo3000
2026-03-04 23:57:14 +01:00
parent a64ee3b944
commit 5b503e6dba
11 changed files with 274 additions and 24 deletions
+4
View File
@@ -1,5 +1,6 @@
import { create } from 'zustand'
import api from '../api/client'
import { useSettingsStore } from './settings'
export const useAuthStore = create((set) => ({
user: null,
@@ -9,6 +10,8 @@ export const useAuthStore = create((set) => ({
login: async (username, password) => {
const data = await api.login(username, password)
set({ user: data.user, isAuthenticated: true })
// Load system settings after login
useSettingsStore.getState().fetchSettings()
return data
},
@@ -25,6 +28,7 @@ export const useAuthStore = create((set) => ({
try {
const data = await api.me()
set({ user: data.user || data, isAuthenticated: true, loading: false })
useSettingsStore.getState().fetchSettings()
} catch {
api.logout()
set({ user: null, isAuthenticated: false, loading: false })
+30
View File
@@ -0,0 +1,30 @@
import { create } from 'zustand'
import api from '../api/client'
export const useSettingsStore = create((set, get) => ({
settings: {},
loaded: false,
fetchSettings: async () => {
try {
const resp = await api.getSettings()
set({ settings: resp.data || {}, loaded: true })
} catch {
// ignore - settings not available before login
}
},
getSetting: (key, fallback = '') => {
return get().settings[key] || fallback
},
getBackendHost: () => {
const url = get().settings.backend_url_internal || ''
try {
return new URL(url).hostname
} catch {
// fallback: strip protocol and port manually
return url.replace(/^https?:\/\//, '').replace(/:\d+$/, '')
}
},
}))