fix: correct generate endpoint return type, migration server_default SQL, and auth loading propagation

This commit is contained in:
2026-02-28 21:22:11 +01:00
parent 1de7974921
commit 488c385de3
3 changed files with 23 additions and 21 deletions

View File

@@ -10,20 +10,22 @@ export interface User {
// Simple module-level state (no external lib needed)
let currentUser: User | null = null
let isLoading = true
let fetchPromise: Promise<void> | null = null
const listeners = new Set<() => void>()
export function useAuth() {
const [user, setUser] = useState<User | null>(currentUser)
const [loading, setLoading] = useState(currentUser === null)
const [loading, setLoading] = useState(isLoading)
useEffect(() => {
const update = () => setUser(currentUser)
const update = () => { setUser(currentUser); setLoading(isLoading) }
listeners.add(update)
if (currentUser === null) {
authApi.me()
.then((res) => { currentUser = res.data; listeners.forEach((l) => l()) })
.catch(() => { currentUser = null; listeners.forEach((l) => l()) })
.finally(() => setLoading(false))
if (!fetchPromise) {
fetchPromise = authApi.me()
.then((res) => { currentUser = res.data })
.catch(() => { currentUser = null })
.finally(() => { isLoading = false; listeners.forEach((l) => l()) })
}
return () => { listeners.delete(update) }
}, [])