mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-09-01 17:10:24 +08:00
fix: always re-fetch access code config when settings dialog opens (#816)
When ACCESS_CODE_LIST is configured on the server, the settings dialog was not showing the access code input field in two cases: 1. Stale localStorage cache: if a user had previously visited without ACCESS_CODE_LIST enabled, the cached value of accessCodeRequired=false would be used indefinitely, hiding the password input. 2. Race condition on first visit: the dialog could open triggered by an auth error before the async fetch to /api/config completed, showing a blank settings dialog with no access code field. Fix by re-fetching /api/config whenever the dialog opens (on open change) instead of only once on mount with a cache guard. The cached value in localStorage is still updated on success, keeping the fast initial render intact while ensuring the dialog always reflects the server configuration. Fixes #811 Co-authored-by: octo-patch <octo-patch@github.com>
This commit is contained in:
@@ -134,8 +134,11 @@ function SettingsContent({
|
||||
const [isApplyingProxy, setIsApplyingProxy] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
// Only fetch if not cached in localStorage
|
||||
if (getStoredAccessCodeRequired() !== null) return
|
||||
// Re-fetch config whenever the dialog opens to ensure we always show
|
||||
// the access code input if the server requires it. This fixes the case
|
||||
// where a stale localStorage cache (from before ACCESS_CODE_LIST was
|
||||
// configured) would hide the access code input.
|
||||
if (!open) return
|
||||
|
||||
fetch(getApiEndpoint("/api/config"))
|
||||
.then((res) => {
|
||||
@@ -151,10 +154,9 @@ function SettingsContent({
|
||||
setAccessCodeRequired(required)
|
||||
})
|
||||
.catch(() => {
|
||||
// Don't cache on error - allow retry on next mount
|
||||
setAccessCodeRequired(false)
|
||||
// Keep existing cached value on error
|
||||
})
|
||||
}, [])
|
||||
}, [open])
|
||||
|
||||
// Detect current language from pathname
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user