fix(setup): add frontend guard to redirect when setup not needed
Add a useEffect in SetupWizard that checks GET /api/setup/status on mount. If needsSetup === false, redirect to /admin immediately instead of showing the wizard. Shows a "Checking setup status..." loading state while the check is in flight. Fixes GRO-254 Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useBranding } from "../BrandingContext.js";
|
import { useBranding } from "../BrandingContext.js";
|
||||||
|
|
||||||
@@ -17,6 +17,21 @@ export function SetupWizard() {
|
|||||||
const [businessName, setBusinessName] = useState("");
|
const [businessName, setBusinessName] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
const [guardLoading, setGuardLoading] = useState(true);
|
||||||
|
|
||||||
|
// Guard: redirect if setup is not needed
|
||||||
|
useEffect(() => {
|
||||||
|
fetch("/api/setup/status")
|
||||||
|
.then((r) => r.json())
|
||||||
|
.then((data) => {
|
||||||
|
if (data.needsSetup === false) {
|
||||||
|
navigate("/admin", { replace: true });
|
||||||
|
} else {
|
||||||
|
setGuardLoading(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => setGuardLoading(false));
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
const current = STEPS[step];
|
const current = STEPS[step];
|
||||||
const isLast = step === STEPS.length - 1;
|
const isLast = step === STEPS.length - 1;
|
||||||
@@ -61,6 +76,21 @@ export function SetupWizard() {
|
|||||||
if (step > 0) setStep((s) => s - 1);
|
if (step > 0) setStep((s) => s - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (guardLoading) {
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
minHeight: "100vh",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
background: "#f0f2f5",
|
||||||
|
fontFamily: "system-ui, sans-serif",
|
||||||
|
}}>
|
||||||
|
<p style={{ color: "#6b7280" }}>Checking setup status…</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
minHeight: "100vh",
|
minHeight: "100vh",
|
||||||
|
|||||||
Reference in New Issue
Block a user