JoaquinVanschoren commited on
Commit
5a09c4a
·
1 Parent(s): 9b78e46

login fix

Browse files
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -19,20 +19,16 @@ def _safe_json_schema_to_python_type(schema, defs=None):
19
  return _orig_json_schema_to_python_type(schema, defs)
20
  _gc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
21
 
22
- # Gradio's LoginButton navigates the iframe with window.location.assign, which causes
23
- # cross-origin cookie issues in Safari and infinite redirect loops in incognito mode.
24
- # Patching the JS to navigate window.top (the top-level tab) instead fixes both.
25
- import json as _json
26
  import gradio.components.login_button as _login_btn_mod
27
  _login_btn_mod._js_handle_redirect = """
28
  (buttonValue) => {
29
  const path = buttonValue === BUTTON_DEFAULT_VALUE ? '/login/huggingface' : '/logout';
30
  const url = window.location.origin + path + window.location.search;
31
  window.parent?.postMessage({ type: "SET_SCROLLING", enabled: true }, "*");
32
- setTimeout(() => {
33
- try { (window.top || window).location.assign(url); }
34
- catch (e) { window.location.assign(url); }
35
- }, 500);
36
  }
37
  """
38
 
 
19
  return _orig_json_schema_to_python_type(schema, defs)
20
  _gc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
21
 
22
+ # HF Spaces embeds the app in an iframe. Gradio's LoginButton uses window.location.assign()
23
+ # which navigates the iframe itself, causing cookie issues in Safari and redirect loops in
24
+ # incognito. HF docs recommend using target=_blank to open OAuth in a new tab instead.
 
25
  import gradio.components.login_button as _login_btn_mod
26
  _login_btn_mod._js_handle_redirect = """
27
  (buttonValue) => {
28
  const path = buttonValue === BUTTON_DEFAULT_VALUE ? '/login/huggingface' : '/logout';
29
  const url = window.location.origin + path + window.location.search;
30
  window.parent?.postMessage({ type: "SET_SCROLLING", enabled: true }, "*");
31
+ setTimeout(() => { window.open(url, '_blank'); }, 500);
 
 
 
32
  }
33
  """
34