Spaces:
Running
Running
Show Google sign-in only when enabled
Browse files- frontend/src/lib/auth.tsx +1 -1
- frontend/src/pages/Auth.tsx +1 -1
- platform_app/core.py +18 -1
frontend/src/lib/auth.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { createClient, type SupabaseClient } from "@supabase/supabase-js";
|
|
| 2 |
import { createContext, useCallback, useContext, useEffect, useState, type ReactNode } from "react";
|
| 3 |
import { api, type Profile } from "./api";
|
| 4 |
|
| 5 |
-
type Config = { enabled: boolean; supabase_url: string; supabase_anon_key: string; dev_auth: boolean; calibrated_model: boolean };
|
| 6 |
|
| 7 |
let supabase: SupabaseClient | null = null;
|
| 8 |
let config: Config | null = null;
|
|
|
|
| 2 |
import { createContext, useCallback, useContext, useEffect, useState, type ReactNode } from "react";
|
| 3 |
import { api, type Profile } from "./api";
|
| 4 |
|
| 5 |
+
type Config = { enabled: boolean; supabase_url: string; supabase_anon_key: string; dev_auth: boolean; calibrated_model: boolean; providers?: { google?: boolean } };
|
| 6 |
|
| 7 |
let supabase: SupabaseClient | null = null;
|
| 8 |
let config: Config | null = null;
|
frontend/src/pages/Auth.tsx
CHANGED
|
@@ -66,7 +66,7 @@ export default function Auth({ mode }: { mode: "signin" | "signup" }) {
|
|
| 66 |
<p className="mt-6 rounded-xl bg-nile-soft px-4 py-3 text-nile-deep">{notice}</p>
|
| 67 |
) : (
|
| 68 |
<form onSubmit={submit} className="mt-8 space-y-4">
|
| 69 |
-
{config?.supabase_url && (
|
| 70 |
<>
|
| 71 |
<Button type="button" variant="outline" className="w-full" onClick={() => signInWithGoogle().catch((e) => setError(e.message))}>
|
| 72 |
<svg width="18" height="18" viewBox="0 0 48 48" aria-hidden="true"><path fill="#FFC107" d="M43.6 20.5H42V20H24v8h11.3C33.7 32.7 29.2 36 24 36c-6.6 0-12-5.4-12-12s5.4-12 12-12c3.1 0 5.8 1.2 7.9 3.1l5.7-5.7C34 6.1 29.3 4 24 4 12.9 4 4 12.9 4 24s8.9 20 20 20 20-8.9 20-20c0-1.3-.1-2.4-.4-3.5z"/><path fill="#FF3D00" d="M6.3 14.7l6.6 4.8C14.7 15.1 19 12 24 12c3.1 0 5.8 1.2 7.9 3.1l5.7-5.7C34 6.1 29.3 4 24 4 16.3 4 9.7 8.3 6.3 14.7z"/><path fill="#4CAF50" d="M24 44c5.2 0 9.9-2 13.4-5.2l-6.2-5.2C29.2 35.1 26.7 36 24 36c-5.2 0-9.6-3.3-11.3-7.9l-6.5 5C9.5 39.6 16.2 44 24 44z"/><path fill="#1976D2" d="M43.6 20.5H42V20H24v8h11.3c-.8 2.2-2.2 4.2-4.1 5.6l6.2 5.2C37 39.2 44 34 44 24c0-1.3-.1-2.4-.4-3.5z"/></svg>
|
|
|
|
| 66 |
<p className="mt-6 rounded-xl bg-nile-soft px-4 py-3 text-nile-deep">{notice}</p>
|
| 67 |
) : (
|
| 68 |
<form onSubmit={submit} className="mt-8 space-y-4">
|
| 69 |
+
{config?.supabase_url && config.providers?.google && (
|
| 70 |
<>
|
| 71 |
<Button type="button" variant="outline" className="w-full" onClick={() => signInWithGoogle().catch((e) => setError(e.message))}>
|
| 72 |
<svg width="18" height="18" viewBox="0 0 48 48" aria-hidden="true"><path fill="#FFC107" d="M43.6 20.5H42V20H24v8h11.3C33.7 32.7 29.2 36 24 36c-6.6 0-12-5.4-12-12s5.4-12 12-12c3.1 0 5.8 1.2 7.9 3.1l5.7-5.7C34 6.1 29.3 4 24 4 12.9 4 4 12.9 4 24s8.9 20 20 20 20-8.9 20-20c0-1.3-.1-2.4-.4-3.5z"/><path fill="#FF3D00" d="M6.3 14.7l6.6 4.8C14.7 15.1 19 12 24 12c3.1 0 5.8 1.2 7.9 3.1l5.7-5.7C34 6.1 29.3 4 24 4 16.3 4 9.7 8.3 6.3 14.7z"/><path fill="#4CAF50" d="M24 44c5.2 0 9.9-2 13.4-5.2l-6.2-5.2C29.2 35.1 26.7 36 24 36c-5.2 0-9.6-3.3-11.3-7.9l-6.5 5C9.5 39.6 16.2 44 24 44z"/><path fill="#1976D2" d="M43.6 20.5H42V20H24v8h11.3c-.8 2.2-2.2 4.2-4.1 5.6l6.2 5.2C37 39.2 44 34 44 24c0-1.3-.1-2.4-.4-3.5z"/></svg>
|
platform_app/core.py
CHANGED
|
@@ -56,9 +56,26 @@ def enabled() -> bool:
|
|
| 56 |
return bool(DATABASE_URL)
|
| 57 |
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def public_config() -> Dict[str, Any]:
|
| 60 |
return {"enabled": enabled(), "supabase_url": SUPABASE_URL, "supabase_anon_key": SUPABASE_ANON_KEY,
|
| 61 |
-
"dev_auth": DEV_AUTH}
|
| 62 |
|
| 63 |
|
| 64 |
# --------------------------------------------------------------------------------------
|
|
|
|
| 56 |
return bool(DATABASE_URL)
|
| 57 |
|
| 58 |
|
| 59 |
+
_providers: Dict[str, Any] = {"at": 0.0, "value": {}}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _auth_providers() -> Dict[str, bool]:
|
| 63 |
+
"""Which sign-in providers are switched on in Supabase (cached for 5 minutes)."""
|
| 64 |
+
if not SUPABASE_URL or time.time() - _providers["at"] < 300:
|
| 65 |
+
return _providers["value"]
|
| 66 |
+
try:
|
| 67 |
+
r = httpx.get(f"{SUPABASE_URL}/auth/v1/settings", headers={"apikey": SUPABASE_ANON_KEY}, timeout=5)
|
| 68 |
+
ext = r.json().get("external", {}) if r.status_code == 200 else {}
|
| 69 |
+
_providers["value"] = {"google": bool(ext.get("google"))}
|
| 70 |
+
except Exception:
|
| 71 |
+
pass
|
| 72 |
+
_providers["at"] = time.time()
|
| 73 |
+
return _providers["value"]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
def public_config() -> Dict[str, Any]:
|
| 77 |
return {"enabled": enabled(), "supabase_url": SUPABASE_URL, "supabase_anon_key": SUPABASE_ANON_KEY,
|
| 78 |
+
"dev_auth": DEV_AUTH, "providers": _auth_providers()}
|
| 79 |
|
| 80 |
|
| 81 |
# --------------------------------------------------------------------------------------
|