Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
85274e0
1
Parent(s): 6d7f53f
Restore localStorage org detection for iframe onboarding
Browse filesIframe users have no auth cookie, so backend polling can't check
org membership. Restores visibilitychange + localStorage tracking
for the iframe path while keeping backend polling for direct access.
frontend/src/components/WelcomeScreen/WelcomeScreen.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { useState, useCallback, type ReactNode } from 'react';
|
| 2 |
import {
|
| 3 |
Box,
|
| 4 |
Typography,
|
|
@@ -191,22 +191,48 @@ export default function WelcomeScreen() {
|
|
| 191 |
const inIframe = isInIframe();
|
| 192 |
const isAuthenticated = !!user?.authenticated;
|
| 193 |
const isDevUser = user?.username === 'dev';
|
| 194 |
-
const isOrgMember = !!user?.orgMember;
|
| 195 |
|
| 196 |
-
//
|
| 197 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
// ---- Actions ----
|
| 200 |
|
| 201 |
const handleJoinOrg = useCallback(() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
const popup = window.open(ORG_JOIN_URL, 'hf-org-join', 'noopener');
|
| 203 |
if (popup) {
|
| 204 |
popupRef.current = popup;
|
| 205 |
} else {
|
| 206 |
-
// Popup blocked — fall back to regular navigation
|
| 207 |
window.open(ORG_JOIN_URL, '_blank', 'noopener,noreferrer');
|
| 208 |
}
|
| 209 |
-
}, [popupRef]);
|
| 210 |
|
| 211 |
const handleStartSession = useCallback(async () => {
|
| 212 |
if (isCreating) return;
|
|
|
|
| 1 |
+
import { useState, useCallback, useEffect, useRef, type ReactNode } from 'react';
|
| 2 |
import {
|
| 3 |
Box,
|
| 4 |
Typography,
|
|
|
|
| 191 |
const inIframe = isInIframe();
|
| 192 |
const isAuthenticated = !!user?.authenticated;
|
| 193 |
const isDevUser = user?.username === 'dev';
|
|
|
|
| 194 |
|
| 195 |
+
// Iframe: localStorage-based org tracking (no auth token available)
|
| 196 |
+
const [iframeOrgJoined, setIframeOrgJoined] = useState(() => {
|
| 197 |
+
try { return localStorage.getItem('hf-agent-org-joined') === '1'; } catch { return false; }
|
| 198 |
+
});
|
| 199 |
+
const joinLinkOpened = useRef(false);
|
| 200 |
+
|
| 201 |
+
// Auto-advance when user returns from org join link (iframe only)
|
| 202 |
+
useEffect(() => {
|
| 203 |
+
if (!inIframe) return;
|
| 204 |
+
const handleVisibility = () => {
|
| 205 |
+
if (document.visibilityState !== 'visible' || !joinLinkOpened.current) return;
|
| 206 |
+
joinLinkOpened.current = false;
|
| 207 |
+
try { localStorage.setItem('hf-agent-org-joined', '1'); } catch { /* ignore */ }
|
| 208 |
+
setIframeOrgJoined(true);
|
| 209 |
+
};
|
| 210 |
+
document.addEventListener('visibilitychange', handleVisibility);
|
| 211 |
+
return () => document.removeEventListener('visibilitychange', handleVisibility);
|
| 212 |
+
}, [inIframe]);
|
| 213 |
+
|
| 214 |
+
const isOrgMember = inIframe ? iframeOrgJoined : !!user?.orgMember;
|
| 215 |
+
|
| 216 |
+
// Poll for org membership once authenticated (skipped in dev mode and iframe)
|
| 217 |
+
const popupRef = useOrgMembership(isAuthenticated && !isDevUser && !inIframe && !isOrgMember);
|
| 218 |
|
| 219 |
// ---- Actions ----
|
| 220 |
|
| 221 |
const handleJoinOrg = useCallback(() => {
|
| 222 |
+
if (inIframe) {
|
| 223 |
+
// Iframe: open link, track via visibilitychange + localStorage
|
| 224 |
+
joinLinkOpened.current = true;
|
| 225 |
+
window.open(ORG_JOIN_URL, '_blank', 'noopener,noreferrer');
|
| 226 |
+
return;
|
| 227 |
+
}
|
| 228 |
+
// Direct: open as popup, auto-close via polling
|
| 229 |
const popup = window.open(ORG_JOIN_URL, 'hf-org-join', 'noopener');
|
| 230 |
if (popup) {
|
| 231 |
popupRef.current = popup;
|
| 232 |
} else {
|
|
|
|
| 233 |
window.open(ORG_JOIN_URL, '_blank', 'noopener,noreferrer');
|
| 234 |
}
|
| 235 |
+
}, [popupRef, inIframe]);
|
| 236 |
|
| 237 |
const handleStartSession = useCallback(async () => {
|
| 238 |
if (isCreating) return;
|