verymehari commited on
Commit
a5f4867
·
1 Parent(s): 1f8a1fb

Remove ml-agent-explorers org gate from Space copy

Browse files
backend/routes/auth.py CHANGED
@@ -10,7 +10,7 @@ import time
10
  from urllib.parse import urlencode
11
 
12
  import httpx
13
- from dependencies import AUTH_ENABLED, check_org_membership, get_current_user
14
  from fastapi import APIRouter, Depends, HTTPException, Request
15
  from fastapi.responses import RedirectResponse
16
 
@@ -70,9 +70,6 @@ async def oauth_login(request: Request) -> RedirectResponse:
70
  "scope": "openid profile read-repos write-repos contribute-repos manage-repos inference-api jobs write-discussions",
71
  "response_type": "code",
72
  "state": state,
73
- "orgIds": os.environ.get(
74
- "HF_OAUTH_ORG_ID", "698dbf55845d85df163175f1"
75
- ), # ml-agent-explorers
76
  }
77
  auth_url = f"{OPENID_PROVIDER_URL}/oauth/authorize?{urlencode(params)}"
78
 
@@ -171,18 +168,9 @@ async def get_me(user: dict = Depends(get_current_user)) -> dict:
171
  return user
172
 
173
 
174
- ORG_NAME = "ml-agent-explorers"
175
-
176
-
177
  @router.get("/org-membership")
178
  async def org_membership(
179
  request: Request, user: dict = Depends(get_current_user)
180
  ) -> dict:
181
- """Check if the authenticated user belongs to the ml-agent-explorers org."""
182
- if not AUTH_ENABLED:
183
- return {"is_member": True}
184
- token = request.cookies.get("hf_access_token") or ""
185
- if not token:
186
- return {"is_member": False}
187
- is_member = await check_org_membership(token, ORG_NAME)
188
- return {"is_member": is_member}
 
10
  from urllib.parse import urlencode
11
 
12
  import httpx
13
+ from dependencies import AUTH_ENABLED, get_current_user
14
  from fastapi import APIRouter, Depends, HTTPException, Request
15
  from fastapi.responses import RedirectResponse
16
 
 
70
  "scope": "openid profile read-repos write-repos contribute-repos manage-repos inference-api jobs write-discussions",
71
  "response_type": "code",
72
  "state": state,
 
 
 
73
  }
74
  auth_url = f"{OPENID_PROVIDER_URL}/oauth/authorize?{urlencode(params)}"
75
 
 
168
  return user
169
 
170
 
 
 
 
171
  @router.get("/org-membership")
172
  async def org_membership(
173
  request: Request, user: dict = Depends(get_current_user)
174
  ) -> dict:
175
+ """Compatibility endpoint kept for older frontend code paths."""
176
+ return {"is_member": True}
 
 
 
 
 
 
frontend/src/components/WelcomeScreen/WelcomeScreen.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useState, useCallback, useEffect, useRef, type ReactNode } from 'react';
2
  import {
3
  Box,
4
  Typography,
@@ -8,18 +8,14 @@ import {
8
  } from '@mui/material';
9
  import CheckCircleIcon from '@mui/icons-material/CheckCircle';
10
  import OpenInNewIcon from '@mui/icons-material/OpenInNew';
11
- import GroupAddIcon from '@mui/icons-material/GroupAdd';
12
  import LoginIcon from '@mui/icons-material/Login';
13
  import RocketLaunchIcon from '@mui/icons-material/RocketLaunch';
14
  import { useSessionStore } from '@/store/sessionStore';
15
  import { useAgentStore } from '@/store/agentStore';
16
  import { apiFetch } from '@/utils/api';
17
  import { isInIframe, triggerLogin } from '@/hooks/useAuth';
18
- import { useOrgMembership } from '@/hooks/useOrgMembership';
19
 
20
  const HF_ORANGE = '#FF9D00';
21
- const ORG_JOIN_URL =
22
- 'https://huggingface.co/organizations/ml-agent-explorers/share/GzPMJUivoFPlfkvFtIqEouZKSytatKQSZT';
23
 
24
  // ---------------------------------------------------------------------------
25
  // ChecklistStep sub-component
@@ -192,48 +188,6 @@ export default function WelcomeScreen() {
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;
239
  setIsCreating(true);
@@ -268,8 +222,7 @@ export default function WelcomeScreen() {
268
  // ---- Step status helpers ----
269
 
270
  const signInStatus: StepStatus = isAuthenticated ? 'completed' : 'active';
271
- const joinOrgStatus: StepStatus = isOrgMember ? 'completed' : isAuthenticated ? 'active' : 'locked';
272
- const startStatus: StepStatus = isAuthenticated && isOrgMember ? 'active' : 'locked';
273
 
274
  // Space URL for iframe "Open ML Intern" step
275
  const spaceHost =
@@ -361,19 +314,9 @@ export default function WelcomeScreen() {
361
  <>
362
  <ChecklistStep
363
  stepNumber={1}
364
- title="Join ML Agent Explorers"
365
- description="Get free access to GPUs, inference APIs, and Hub resources."
366
- status={isOrgMember ? 'completed' : 'active'}
367
- actionLabel="Join Organization"
368
- actionIcon={<GroupAddIcon sx={{ fontSize: 16 }} />}
369
- onAction={handleJoinOrg}
370
- />
371
- <ChecklistStep
372
- stepNumber={2}
373
  title="Open ML Intern"
374
- description="Open the agent in a full browser tab to get started."
375
- status={isOrgMember ? 'active' : 'locked'}
376
- lockedReason="Join the organization first."
377
  actionLabel="Open ML Intern"
378
  actionIcon={<OpenInNewIcon sx={{ fontSize: 16 }} />}
379
  actionHref={spaceHost}
@@ -381,7 +324,7 @@ export default function WelcomeScreen() {
381
  />
382
  </>
383
  ) : (
384
- /* Direct access: 3 steps */
385
  <>
386
  <ChecklistStep
387
  stepNumber={1}
@@ -394,20 +337,10 @@ export default function WelcomeScreen() {
394
  />
395
  <ChecklistStep
396
  stepNumber={2}
397
- title="Join ML Agent Explorers"
398
- description="Get free access to GPUs, inference APIs, and Hub resources."
399
- status={joinOrgStatus}
400
- lockedReason="Sign in first to continue."
401
- actionLabel="Join Organization"
402
- actionIcon={<GroupAddIcon sx={{ fontSize: 16 }} />}
403
- onAction={handleJoinOrg}
404
- />
405
- <ChecklistStep
406
- stepNumber={3}
407
  title="Start Session"
408
  description="Launch an AI agent session for ML engineering."
409
  status={startStatus}
410
- lockedReason="Complete the steps above to continue."
411
  actionLabel="Start Session"
412
  actionIcon={<RocketLaunchIcon sx={{ fontSize: 16 }} />}
413
  onAction={handleStartSession}
@@ -418,16 +351,6 @@ export default function WelcomeScreen() {
418
  )}
419
  </Box>
420
 
421
- {/* Polling hint when waiting for org join */}
422
- {isAuthenticated && !isOrgMember && !isDevUser && !inIframe && (
423
- <Typography
424
- variant="caption"
425
- sx={{ mt: 2, color: 'var(--muted-text)', fontSize: '0.75rem', textAlign: 'center' }}
426
- >
427
- This page updates automatically when you join the organization.
428
- </Typography>
429
- )}
430
-
431
  {/* Error */}
432
  {error && (
433
  <Alert
 
1
+ import { useState, useCallback, type ReactNode } from 'react';
2
  import {
3
  Box,
4
  Typography,
 
8
  } from '@mui/material';
9
  import CheckCircleIcon from '@mui/icons-material/CheckCircle';
10
  import OpenInNewIcon from '@mui/icons-material/OpenInNew';
 
11
  import LoginIcon from '@mui/icons-material/Login';
12
  import RocketLaunchIcon from '@mui/icons-material/RocketLaunch';
13
  import { useSessionStore } from '@/store/sessionStore';
14
  import { useAgentStore } from '@/store/agentStore';
15
  import { apiFetch } from '@/utils/api';
16
  import { isInIframe, triggerLogin } from '@/hooks/useAuth';
 
17
 
18
  const HF_ORANGE = '#FF9D00';
 
 
19
 
20
  // ---------------------------------------------------------------------------
21
  // ChecklistStep sub-component
 
188
  const isAuthenticated = !!user?.authenticated;
189
  const isDevUser = user?.username === 'dev';
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  const handleStartSession = useCallback(async () => {
192
  if (isCreating) return;
193
  setIsCreating(true);
 
222
  // ---- Step status helpers ----
223
 
224
  const signInStatus: StepStatus = isAuthenticated ? 'completed' : 'active';
225
+ const startStatus: StepStatus = isAuthenticated ? 'active' : 'locked';
 
226
 
227
  // Space URL for iframe "Open ML Intern" step
228
  const spaceHost =
 
314
  <>
315
  <ChecklistStep
316
  stepNumber={1}
 
 
 
 
 
 
 
 
 
317
  title="Open ML Intern"
318
+ description="Open your copy in a full browser tab to get started."
319
+ status="active"
 
320
  actionLabel="Open ML Intern"
321
  actionIcon={<OpenInNewIcon sx={{ fontSize: 16 }} />}
322
  actionHref={spaceHost}
 
324
  />
325
  </>
326
  ) : (
327
+ /* Direct access: 2 steps */
328
  <>
329
  <ChecklistStep
330
  stepNumber={1}
 
337
  />
338
  <ChecklistStep
339
  stepNumber={2}
 
 
 
 
 
 
 
 
 
 
340
  title="Start Session"
341
  description="Launch an AI agent session for ML engineering."
342
  status={startStatus}
343
+ lockedReason="Sign in first to continue."
344
  actionLabel="Start Session"
345
  actionIcon={<RocketLaunchIcon sx={{ fontSize: 16 }} />}
346
  onAction={handleStartSession}
 
351
  )}
352
  </Box>
353
 
 
 
 
 
 
 
 
 
 
 
354
  {/* Error */}
355
  {error && (
356
  <Alert