Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Fix OAuth flicker: let apiFetch handle 401 redirect instead of pre-checking user
Browse files
frontend/src/components/WelcomeScreen/WelcomeScreen.tsx
CHANGED
|
@@ -9,30 +9,23 @@ import {
|
|
| 9 |
import { useSessionStore } from '@/store/sessionStore';
|
| 10 |
import { useAgentStore } from '@/store/agentStore';
|
| 11 |
import { apiFetch } from '@/utils/api';
|
| 12 |
-
import { triggerLogin } from '@/hooks/useAuth';
|
| 13 |
|
| 14 |
/** HF brand orange */
|
| 15 |
const HF_ORANGE = '#FF9D00';
|
| 16 |
|
| 17 |
export default function WelcomeScreen() {
|
| 18 |
const { createSession } = useSessionStore();
|
| 19 |
-
const { setPlan, setPanelContent
|
| 20 |
const [isCreating, setIsCreating] = useState(false);
|
| 21 |
const [error, setError] = useState<string | null>(null);
|
| 22 |
|
| 23 |
const handleStart = useCallback(async () => {
|
| 24 |
if (isCreating) return;
|
| 25 |
-
|
| 26 |
-
// If user is not authenticated, trigger OAuth login first
|
| 27 |
-
if (!user?.authenticated) {
|
| 28 |
-
triggerLogin();
|
| 29 |
-
return;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
setIsCreating(true);
|
| 33 |
setError(null);
|
| 34 |
|
| 35 |
try {
|
|
|
|
| 36 |
const response = await apiFetch('/api/session', { method: 'POST' });
|
| 37 |
if (response.status === 503) {
|
| 38 |
const data = await response.json();
|
|
@@ -48,11 +41,11 @@ export default function WelcomeScreen() {
|
|
| 48 |
setPlan([]);
|
| 49 |
setPanelContent(null);
|
| 50 |
} catch {
|
| 51 |
-
|
| 52 |
} finally {
|
| 53 |
setIsCreating(false);
|
| 54 |
}
|
| 55 |
-
}, [isCreating, createSession, setPlan, setPanelContent
|
| 56 |
|
| 57 |
return (
|
| 58 |
<Box
|
|
|
|
| 9 |
import { useSessionStore } from '@/store/sessionStore';
|
| 10 |
import { useAgentStore } from '@/store/agentStore';
|
| 11 |
import { apiFetch } from '@/utils/api';
|
|
|
|
| 12 |
|
| 13 |
/** HF brand orange */
|
| 14 |
const HF_ORANGE = '#FF9D00';
|
| 15 |
|
| 16 |
export default function WelcomeScreen() {
|
| 17 |
const { createSession } = useSessionStore();
|
| 18 |
+
const { setPlan, setPanelContent } = useAgentStore();
|
| 19 |
const [isCreating, setIsCreating] = useState(false);
|
| 20 |
const [error, setError] = useState<string | null>(null);
|
| 21 |
|
| 22 |
const handleStart = useCallback(async () => {
|
| 23 |
if (isCreating) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
setIsCreating(true);
|
| 25 |
setError(null);
|
| 26 |
|
| 27 |
try {
|
| 28 |
+
// apiFetch handles 401 → redirects to /auth/login automatically
|
| 29 |
const response = await apiFetch('/api/session', { method: 'POST' });
|
| 30 |
if (response.status === 503) {
|
| 31 |
const data = await response.json();
|
|
|
|
| 41 |
setPlan([]);
|
| 42 |
setPanelContent(null);
|
| 43 |
} catch {
|
| 44 |
+
// apiFetch throws on 401 redirect — don't show error in that case
|
| 45 |
} finally {
|
| 46 |
setIsCreating(false);
|
| 47 |
}
|
| 48 |
+
}, [isCreating, createSession, setPlan, setPanelContent]);
|
| 49 |
|
| 50 |
return (
|
| 51 |
<Box
|