feat(admin): add the admin users page and view as
Build, Test & Push Frontend / quality-check (push) Successful in 17s
Build, Test & Push Frontend / docker (push) Successful in 28s

This commit is contained in:
lobo committed 2026-09-27 12:18:10 +02:00
1 parent 46587dfb5c
commit afe00ceae9
14 files changed
+649 -8

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import {useEffect, useState} from 'react';
import {apiFetch} from '../utils/api.js';
import {sessionStamp} from '../utils/auth.js';
/**
* The stored role and the active role ("view as") of the logged-in user, or null while loading and on any error.
* Loads again after a new login or a role switch (see sessionStamp) on the next render.
*/
export default function useCurrentUser(enabled) {
const [user, setUser] = useState(null);
const stamp = sessionStamp();
useEffect(() => {
if (!enabled || !stamp) {
setUser(null);
return undefined;
}
let cancelled = false;
(async () => {
try {
const response = await apiFetch(`${import.meta.env.VITE_API_URL}/api/users/me?v=1`);
const data = response.ok ? await response.json() : null;
if (!cancelled) setUser(data && {role: data.role, activeRole: data.activeRole ?? data.role});
} catch {
if (!cancelled) setUser(null);
}
})();
return () => {
cancelled = true;
};
}, [enabled, stamp]);
return user;
}