diff --git a/error_log_api/index.js b/error_log_api/index.js
index 7dda828..b27b49e 100644
--- a/error_log_api/index.js
+++ b/error_log_api/index.js
@@ -58,7 +58,7 @@ function verifyAdmin(req, res, next) {
try {
const payload = jwt.verify(auth.slice(7), JWT_SECRET);
- if (!payload?.isAdmin) {
+ if (!payload?.user.isAdmin) {
return res.status(403).json({ error: toFriendlyError(403) });
}
diff --git a/monitoring_ui/src/App.jsx b/monitoring_ui/src/App.jsx
index da7118b..94c9b0b 100644
--- a/monitoring_ui/src/App.jsx
+++ b/monitoring_ui/src/App.jsx
@@ -57,7 +57,12 @@ const healthPaths = {
errors: "/health",
};
const testerRoutes = [
- { service: "auth", method: "POST", path: "/login", label: "Login (userCode + password)" },
+ {
+ service: "auth",
+ method: "POST",
+ path: "/login",
+ label: "Login (userCode + password)",
+ },
{ service: "auth", method: "GET", path: "/me", label: "Current session" },
{
service: "employee",
@@ -108,8 +113,8 @@ function App() {
const [token, setToken] = useState(
() => localStorage.getItem("transit-monitor-token") || "",
);
- const [user, setUser] = useState(
- () => JSON.parse(localStorage.getItem("transit-monitor-user") || "null"),
+ const [user, setUser] = useState(() =>
+ JSON.parse(localStorage.getItem("transit-monitor-user") || "null"),
);
const [health, setHealth] = useState({});
const [history, setHistory] = useState({});
@@ -129,35 +134,38 @@ function App() {
const [loginLoading, setLoginLoading] = useState(false);
const [loginError, setLoginError] = useState("");
- const login = useCallback(async (userCode, password) => {
- const url = urls.auth;
- if (!url) {
- setLoginError("Auth API URL not configured");
- return;
- }
- setLoginLoading(true);
- setLoginError("");
- try {
- const response = await fetch(`${url}/login`, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ userCode, password }),
- });
- const data = await response.json();
- if (!response.ok) {
- throw new Error(data.error || `HTTP ${response.status}`);
+ const login = useCallback(
+ async (userCode, password) => {
+ const url = urls.auth;
+ if (!url) {
+ setLoginError("Auth API URL not configured");
+ return;
}
- setToken(data.token);
- setUser(data.user);
- localStorage.setItem("transit-monitor-token", data.token);
- localStorage.setItem("transit-monitor-user", JSON.stringify(data.user));
+ setLoginLoading(true);
setLoginError("");
- } catch (error) {
- setLoginError(error.message);
- } finally {
- setLoginLoading(false);
- }
- }, [urls.auth]);
+ try {
+ const response = await fetch(`${url}/login`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ userCode, password }),
+ });
+ const data = await response.json();
+ if (!response.ok) {
+ throw new Error(data.error || `HTTP ${response.status}`);
+ }
+ setToken(data.token);
+ setUser(data.user);
+ localStorage.setItem("transit-monitor-token", data.token);
+ localStorage.setItem("transit-monitor-user", JSON.stringify(data.user));
+ setLoginError("");
+ } catch (error) {
+ setLoginError(error.message);
+ } finally {
+ setLoginLoading(false);
+ }
+ },
+ [urls.auth],
+ );
const logout = useCallback(() => {
setToken("");
@@ -590,7 +598,9 @@ function Docs() {
{route}{route}
+