wu981526092 Claude Opus 4.5 commited on
Commit
cceb270
Β·
1 Parent(s): 61546e3

Fix: Login button debugging and YouTube iframe lazy-loading for HF Spaces

Browse files

- Add console logging to AuthModal and AuthContext for debugging
- Implement click-to-load pattern for YouTube video to avoid nested iframe issues
- Add /auth proxy route to Vite dev server for local development

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

frontend/src/components/auth/AuthModal.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React from "react";
2
  import {
3
  Dialog,
4
  DialogContent,
@@ -17,13 +17,25 @@ interface AuthModalProps {
17
 
18
  export function AuthModal({ open, onOpenChange }: AuthModalProps) {
19
  const { login, authState } = useAuth();
 
 
 
 
 
 
 
 
 
20
 
21
  const handleLogin = async () => {
 
22
  try {
 
23
  await login();
 
24
  // Don't close modal here, it will close after successful auth
25
  } catch (error) {
26
- console.error("Login failed:", error);
27
  }
28
  };
29
 
@@ -117,17 +129,29 @@ export function AuthModal({ open, onOpenChange }: AuthModalProps) {
117
 
118
  {/* Right side - Demo Content */}
119
  <div className="bg-secondary/20 p-8 lg:p-12 space-y-6">
120
- {/* Demo Video */}
121
  <Card className="bg-background/50 backdrop-blur-sm border-border/50">
122
  <CardContent className="p-0">
123
- <div className="relative aspect-video rounded-lg overflow-hidden">
124
- <iframe
125
- src="https://www.youtube.com/embed/btrS9pfDYJY?si=dDX4tIs-oS2O2d2p"
126
- title="AgentGraph: Interactive Analysis Platform Demo"
127
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
128
- allowFullScreen
129
- className="w-full h-full"
130
- />
 
 
 
 
 
 
 
 
 
 
 
 
131
  </div>
132
  <div className="p-4">
133
  <div className="flex items-center space-x-2 text-sm text-muted-foreground">
 
1
+ import React, { useState } from "react";
2
  import {
3
  Dialog,
4
  DialogContent,
 
17
 
18
  export function AuthModal({ open, onOpenChange }: AuthModalProps) {
19
  const { login, authState } = useAuth();
20
+ const [showVideo, setShowVideo] = useState(false);
21
+
22
+ // Debug: Log auth state when modal renders
23
+ console.log("πŸ” AuthModal render - authState:", {
24
+ isLoading: authState.isLoading,
25
+ isAuthenticated: authState.isAuthenticated,
26
+ error: authState.error,
27
+ buttonDisabled: authState.isLoading,
28
+ });
29
 
30
  const handleLogin = async () => {
31
+ console.log("πŸ–±οΈ Login button clicked!");
32
  try {
33
+ console.log("πŸ”„ Calling login()...");
34
  await login();
35
+ console.log("βœ… login() completed");
36
  // Don't close modal here, it will close after successful auth
37
  } catch (error) {
38
+ console.error("❌ Login failed:", error);
39
  }
40
  };
41
 
 
129
 
130
  {/* Right side - Demo Content */}
131
  <div className="bg-secondary/20 p-8 lg:p-12 space-y-6">
132
+ {/* Demo Video - Click to load to avoid iframe issues in HF Spaces */}
133
  <Card className="bg-background/50 backdrop-blur-sm border-border/50">
134
  <CardContent className="p-0">
135
+ <div className="relative aspect-video rounded-lg overflow-hidden bg-muted">
136
+ {showVideo ? (
137
+ <iframe
138
+ src="https://www.youtube.com/embed/btrS9pfDYJY?si=dDX4tIs-oS2O2d2p&autoplay=1"
139
+ title="AgentGraph: Interactive Analysis Platform Demo"
140
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
141
+ allowFullScreen
142
+ className="w-full h-full"
143
+ />
144
+ ) : (
145
+ <button
146
+ onClick={() => setShowVideo(true)}
147
+ className="w-full h-full flex flex-col items-center justify-center gap-4 hover:bg-muted/80 transition-colors cursor-pointer"
148
+ >
149
+ <div className="w-16 h-16 rounded-full bg-primary/90 flex items-center justify-center shadow-lg">
150
+ <Play className="w-8 h-8 text-white ml-1" />
151
+ </div>
152
+ <span className="text-sm text-muted-foreground">Click to play demo video</span>
153
+ </button>
154
+ )}
155
  </div>
156
  <div className="p-4">
157
  <div className="flex items-center space-x-2 text-sm text-muted-foreground">
frontend/src/context/AuthContext.tsx CHANGED
@@ -231,8 +231,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
231
  };
232
 
233
  const login = async () => {
 
234
  try {
235
  dispatch({ type: "AUTH_START" });
 
236
 
237
  // Check if we're in HF Spaces environment
238
  const isHFSpaces =
@@ -241,13 +243,22 @@ export function AuthProvider({ children }: { children: ReactNode }) {
241
  window.location.hostname.includes("huggingface.co") ||
242
  document.querySelector('meta[name="hf:space"]') !== null;
243
 
 
 
 
 
 
 
244
  if (isHFSpaces) {
245
  // In HF Spaces, get OAuth config from backend API
246
  console.log("πŸ” Getting OAuth config from backend");
247
 
248
  try {
 
249
  const response = await fetch("/auth/oauth-config");
 
250
  const oauthConfig = await response.json();
 
251
 
252
  if (!oauthConfig.oauth_enabled) {
253
  throw new Error("OAuth not enabled or configured on backend");
@@ -277,17 +288,18 @@ export function AuthProvider({ children }: { children: ReactNode }) {
277
  `state=${state}&` +
278
  `prompt=consent`;
279
 
280
- console.log("πŸ”„ Redirecting to HF OAuth with client_id");
281
  window.location.href = oauthUrl;
282
  } catch (configError) {
283
  console.error(
284
- "Failed to get OAuth config from backend:",
285
  configError
286
  );
287
  throw new Error("OAuth configuration not available from backend");
288
  }
289
  } else {
290
  // For local development, show a message or redirect to HF
 
291
  dispatch({
292
  type: "AUTH_ERROR",
293
  payload:
@@ -295,7 +307,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
295
  });
296
  }
297
  } catch (error) {
298
- console.error("Login failed:", error);
299
  dispatch({
300
  type: "AUTH_ERROR",
301
  payload: "Failed to initiate login",
 
231
  };
232
 
233
  const login = async () => {
234
+ console.log("πŸš€ login() function called");
235
  try {
236
  dispatch({ type: "AUTH_START" });
237
+ console.log("πŸ“€ Dispatched AUTH_START");
238
 
239
  // Check if we're in HF Spaces environment
240
  const isHFSpaces =
 
243
  window.location.hostname.includes("huggingface.co") ||
244
  document.querySelector('meta[name="hf:space"]') !== null;
245
 
246
+ console.log("πŸ” HF Spaces detection in login():", {
247
+ isHFSpaces,
248
+ hostname: window.location.hostname,
249
+ hasHuggingface: !!window.huggingface,
250
+ });
251
+
252
  if (isHFSpaces) {
253
  // In HF Spaces, get OAuth config from backend API
254
  console.log("πŸ” Getting OAuth config from backend");
255
 
256
  try {
257
+ console.log("πŸ“‘ Fetching /auth/oauth-config...");
258
  const response = await fetch("/auth/oauth-config");
259
+ console.log("πŸ“‘ Fetch response status:", response.status);
260
  const oauthConfig = await response.json();
261
+ console.log("πŸ“‘ OAuth config response:", oauthConfig);
262
 
263
  if (!oauthConfig.oauth_enabled) {
264
  throw new Error("OAuth not enabled or configured on backend");
 
288
  `state=${state}&` +
289
  `prompt=consent`;
290
 
291
+ console.log("πŸ”„ Redirecting to HF OAuth:", oauthUrl.substring(0, 100) + "...");
292
  window.location.href = oauthUrl;
293
  } catch (configError) {
294
  console.error(
295
+ "❌ Failed to get OAuth config from backend:",
296
  configError
297
  );
298
  throw new Error("OAuth configuration not available from backend");
299
  }
300
  } else {
301
  // For local development, show a message or redirect to HF
302
+ console.log("⚠️ Not in HF Spaces, dispatching AUTH_ERROR");
303
  dispatch({
304
  type: "AUTH_ERROR",
305
  payload:
 
307
  });
308
  }
309
  } catch (error) {
310
+ console.error("❌ Login failed:", error);
311
  dispatch({
312
  type: "AUTH_ERROR",
313
  payload: "Failed to initiate login",
frontend/vite.config.ts CHANGED
@@ -46,6 +46,20 @@ export default defineConfig({
46
  },
47
  timeout: 60000,
48
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  },
50
  },
51
  });
 
46
  },
47
  timeout: 60000,
48
  },
49
+ "/auth": {
50
+ target: process.env.VITE_API_URL || "http://127.0.0.1:5280",
51
+ changeOrigin: true,
52
+ secure: false,
53
+ configure: (proxy, _options) => {
54
+ proxy.on("error", (err, req, res) => {
55
+ console.log("auth proxy error", err);
56
+ });
57
+ proxy.on("proxyReq", (proxyReq, req, _res) => {
58
+ console.log("Proxying auth to backend:", req.method, req.url);
59
+ });
60
+ },
61
+ timeout: 60000,
62
+ },
63
  },
64
  },
65
  });