fix login redirect loop: skip settings check when unauthenticated, only redirect 401 when token present
All checks were successful
Build and Push / build (push) Successful in 1m12s

This commit is contained in:
KansaiGaijin
2026-07-30 13:54:14 +12:00
parent 9dd2439766
commit d25682397d
2 changed files with 9 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react'; import { useState, useEffect, useCallback } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom'; import { Routes, Route, Navigate } from 'react-router-dom';
import { AuthProvider, useAuth } from './contexts/AuthContext'; import { AuthProvider, useAuth } from './contexts/AuthContext';
import Login from './pages/Login'; import Login from './pages/Login';
@@ -20,18 +20,22 @@ function AppInner() {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [isConfigured, setIsConfigured] = useState(false); const [isConfigured, setIsConfigured] = useState(false);
const checkSettings = () => { const checkSettings = useCallback(() => {
api.getSettings() api.getSettings()
.then(data => { .then(data => {
setIsConfigured(!!(data && data.onboarding_completed)); setIsConfigured(!!(data && data.onboarding_completed));
}) })
.catch(() => setIsConfigured(false)) .catch(() => setIsConfigured(false))
.finally(() => setLoading(false)); .finally(() => setLoading(false));
}; }, []);
useEffect(() => { useEffect(() => {
if (!user) {
setLoading(false);
return;
}
checkSettings(); checkSettings();
}, []); }, [user, checkSettings]);
if (authLoading || loading) { if (authLoading || loading) {
return <div className="min-h-screen bg-deep-900 text-white flex items-center justify-center">Loading...</div>; return <div className="min-h-screen bg-deep-900 text-white flex items-center justify-center">Loading...</div>;

View File

@@ -11,7 +11,7 @@ window.fetch = function (input: RequestInfo | URL, init?: RequestInit): Promise<
} }
} }
return origFetch.call(window, input, init).then((res) => { return origFetch.call(window, input, init).then((res) => {
if (res.status === 401 && url.startsWith("/api/") && !url.startsWith("/api/auth/login") && !url.startsWith("/api/auth/me")) { if (res.status === 401 && url.startsWith("/api/") && !url.startsWith("/api/auth/login") && !url.startsWith("/api/auth/me") && localStorage.getItem("token")) {
localStorage.removeItem("token"); localStorage.removeItem("token");
window.location.href = "/login"; window.location.href = "/login";
} }