borsa / check_supabase2.py
GitHub Copilot
Harden Telegram menu webhook
96964a0
#!/usr/bin/env python3
"""Test Supabase signup and check auth configuration"""
import psycopg2
import json
import urllib.request
import urllib.error
SUPABASE_URL = "https://mitlbxlqjibfcxswgmbq.supabase.co"
# Step 1: Check via database - auth settings
conn = psycopg2.connect(
host='aws-1-eu-central-1.pooler.supabase.com',
port=5432,
dbname='postgres',
user='postgres.mitlbxlqjibfcxswgmbq',
password='Veteroner06.,'
)
cur = conn.cursor()
# Check auth.users in detail
print("=== All auth.users ===")
cur.execute("""
SELECT id, email, created_at, confirmed_at, banned_until,
is_sso_user, deleted_at, is_anonymous,
raw_app_meta_data
FROM auth.users ORDER BY created_at
""")
for row in cur.fetchall():
print(f" email={row[1]}")
print(f" created={row[2]}, confirmed={row[3]}")
print(f" banned_until={row[4]}, is_sso={row[5]}, deleted={row[6]}, is_anon={row[7]}")
print(f" app_meta={row[8]}")
print()
# Check which users have profiles
print("=== user_profiles ===")
cur.execute("SELECT id, display_name, is_admin, is_banned, created_at FROM user_profiles")
for row in cur.fetchall():
print(f" id={str(row[0])[:8]}... name={row[1]} admin={row[2]} banned={row[3]} created={row[4]}")
# Check auth.instances
try:
cur.execute("SELECT * FROM auth.instances LIMIT 5")
print("\n=== auth.instances ===")
for row in cur.fetchall():
print(f" {row}")
except Exception as e:
print(f"\n=== auth.instances: {e}")
conn.rollback()
# Check auth.flow_state for pending signups
try:
cur.execute("SELECT count(*) FROM auth.flow_state")
print(f"\n=== auth.flow_state count: {cur.fetchone()[0]}")
except Exception as e:
print(f"\n=== auth.flow_state: {e}")
conn.rollback()
# Check if there are any rate limit issues
try:
cur.execute("""
SELECT count(*) FROM auth.users
WHERE created_at > now() - interval '1 hour'
""")
print(f"\n=== Users created in last hour: {cur.fetchone()[0]}")
except Exception as e:
print(f"\n=== Error: {e}")
conn.rollback()
# Check handle_new_user function source code
cur.execute("""
SELECT prosrc FROM pg_proc WHERE proname = 'handle_new_user'
""")
row = cur.fetchone()
if row:
print("\n=== handle_new_user function source ===")
print(row[0])
# Check is_admin function source
cur.execute("""
SELECT prosrc FROM pg_proc WHERE proname = 'is_admin'
""")
row = cur.fetchone()
if row:
print("\n=== is_admin function source ===")
print(row[0])
# Manually try to sync missing profiles
print("\n=== Syncing missing user_profiles ===")
cur.execute("""
SELECT u.id, u.email, u.raw_user_meta_data
FROM auth.users u
LEFT JOIN user_profiles up ON u.id = up.id
WHERE up.id IS NULL
""")
missing = cur.fetchall()
print(f" Found {len(missing)} users without profiles")
for row in missing:
print(f" Missing: {row[1]} (id={str(row[0])[:8]}...)")
conn.close()
# Step 2: Try a test signup via REST API to see the exact error
print("\n=== Testing signup via Supabase REST API ===")
# First get the anon key from the .env or env vars
# Try to find it
import os
import glob
anon_key = None
for pattern in [
'/Volumes/LaCie/borsa_uygulamasi/nextjs-app/.env*',
'/Volumes/LaCie/borsa_uygulamasi/nextjs-app/.env.local',
'/Volumes/LaCie/borsa_uygulamasi/huggingface-space/nextjs-app/.env*',
]:
for f in glob.glob(pattern):
try:
with open(f) as fh:
for line in fh:
if 'SUPABASE_ANON_KEY' in line and '=' in line:
val = line.split('=', 1)[1].strip()
if val and val != 'your_supabase_anon_key':
anon_key = val
print(f" Found anon key in {f}")
except:
pass
if anon_key:
# Try signup
data = json.dumps({
"email": "test_registration_check@example.com",
"password": "TestPass123!"
}).encode()
req = urllib.request.Request(
f"{SUPABASE_URL}/auth/v1/signup",
data=data,
headers={
"apikey": anon_key,
"Content-Type": "application/json"
}
)
try:
resp = urllib.request.urlopen(req, timeout=15)
result = json.loads(resp.read())
print(f" Signup result: {json.dumps(result, indent=2)[:500]}")
except urllib.error.HTTPError as e:
body = e.read().decode()
print(f" Signup HTTP Error {e.code}: {body}")
except Exception as e:
print(f" Signup error: {e}")
else:
print(" Could not find SUPABASE_ANON_KEY - checking .env files...")
for pattern in ['/Volumes/LaCie/borsa_uygulamasi/**/.env*']:
for f in glob.glob(pattern, recursive=True):
print(f" Found env file: {f}")