File size: 3,292 Bytes
611e2c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
"""
Quick script to verify your Supabase API key format and connection.
"""

import os
from dotenv import load_dotenv

load_dotenv()

url = os.getenv("SUPABASE_URL")
key = os.getenv("SUPABASE_SERVICE_KEY")

print("=" * 70)
print("Supabase API Key Verification")
print("=" * 70)
print()

if not url:
    print("❌ SUPABASE_URL is not set in .env file")
    exit(1)

if not key:
    print("❌ SUPABASE_SERVICE_KEY is not set in .env file")
    exit(1)

# Clean the key
key = key.strip()

print(f"πŸ“‹ SUPABASE_URL: {url[:30]}...")
print(f"πŸ“‹ SUPABASE_SERVICE_KEY: {key[:20]}...{key[-10:] if len(key) > 30 else ''} ({len(key)} chars)")
print()

# Check key format
issues = []

if not key.startswith("eyJ"):
    issues.append("❌ Key doesn't start with 'eyJ' (not a JWT token)")

if len(key) < 100:
    issues.append(f"❌ Key is too short ({len(key)} chars, expected ~200+)")

if len(key) > 500:
    issues.append(f"⚠️  Key is unusually long ({len(key)} chars)")

if " " in key or "\n" in key or "\t" in key:
    issues.append("❌ Key contains whitespace (spaces, newlines, tabs)")

if key.startswith('"') or key.endswith('"'):
    issues.append("❌ Key is wrapped in quotes (remove quotes from .env)")

if key.startswith("'") or key.endswith("'"):
    issues.append("❌ Key is wrapped in single quotes (remove quotes from .env)")

if issues:
    print("⚠️  Issues found with API key format:")
    for issue in issues:
        print(f"   {issue}")
    print()
else:
    print("βœ… Key format looks good!")
    print()

# Try to connect
print("πŸ”— Testing connection to Supabase...")
try:
    from supabase import create_client
    client = create_client(url, key)
    
    # Try a simple query
    try:
        client.table("admin_rules").select("id").limit(0).execute()
        print("βœ… Connection successful! API key is valid.")
        print()
        print("πŸ’‘ Next steps:")
        print("   1. Make sure tables exist (run SQL scripts in Supabase)")
        print("   2. Run: python migrate_sqlite_to_supabase.py")
    except Exception as e:
        error_str = str(e)
        if "Invalid API key" in error_str or "401" in error_str:
            print("❌ Connection failed: Invalid API key")
            print()
            print("πŸ”§ How to fix:")
            print("   1. Go to https://app.supabase.com")
            print("   2. Select your project")
            print("   3. Go to Settings β†’ API")
            print("   4. Find 'service_role' key (NOT 'anon' key)")
            print("   5. Click 'Reveal' to show the full key")
            print("   6. Copy the ENTIRE key (it's very long)")
            print("   7. Update SUPABASE_SERVICE_KEY in .env file")
            print("   8. Make sure NO quotes or spaces around the value")
        elif "does not exist" in error_str or "relation" in error_str.lower():
            print("⚠️  Connection works, but table doesn't exist yet")
            print("   This is OK - create tables first, then migrate")
        else:
            print(f"❌ Connection error: {error_str}")
            
except ImportError:
    print("❌ Supabase Python client not installed")
    print("   Run: pip install supabase")
except Exception as e:
    print(f"❌ Error: {e}")

print()
print("=" * 70)