# Prüfe ob .env Datei existiert (optional für lokale Tests)
# Die Functions haben Dev-Fallbacks, funktionieren also auch ohne Supabase
# Starte Netlify Dev Server
netlify dev
# Sollte starten auf:
# - Frontend: http://localhost:3000
# - Functions: http://localhost:8888/.netlify/functions/*Ohne Supabase (Dev-Fallback):
curl http://localhost:8888/.netlify/functions/meErwartete Antwort:
{
"user": {
"id": "dev-user",
"display_name": "Dev",
"coins": 2000
},
"progress": [],
"serverTime": 1234567890,
"note": "dev-fallback"
}Mit Supabase (wenn .env gesetzt):
# Setze Header für Dev-User (optional)
curl -H "X-Dev-User: test-user-123" http://localhost:8888/.netlify/functions/mecurl http://localhost:8888/.netlify/functions/progressGet?unitId=u1curl -X POST http://localhost:8888/.netlify/functions/progressSave \
-H "Content-Type: application/json" \
-H "X-Dev-User: test-user-123" \
-d '{
"unitId": "u1",
"questCoinsEarned": 25,
"questCompletedCount": 1,
"bountyCompleted": false
}'curl -X POST http://localhost:8888/.netlify/functions/coinsAdjust \
-H "Content-Type: application/json" \
-H "X-Dev-User: test-user-123" \
-d '{
"delta": 50,
"reason": "test",
"refType": "test",
"refId": "test-123"
}'# Chat senden
curl -X POST http://localhost:8888/.netlify/functions/chatSend \
-H "Content-Type: application/json" \
-H "X-Dev-User: test-user-123" \
-d '{
"channelId": "class",
"text": "Test-Nachricht",
"username": "TestUser"
}'
# Chat abrufen
curl "http://localhost:8888/.netlify/functions/chatPoll?channelId=class"Erstelle .env im Projekt-Root (wird nicht committed):
SUPABASE_URL=https://dein-projekt.supabase.co
SUPABASE_SERVICE_ROLE_KEY=dein-service-role-key
# ODER
SUPABASE_ANON_KEY=dein-anon-keyWichtig:
SUPABASE_SERVICE_ROLE_KEYhat Admin-Rechte (für Backend-Functions)SUPABASE_ANON_KEYhat nur RLS-Rechte (für Frontend)
Führe das SQL-Script aus:
# Öffne Supabase Dashboard → SQL Editor
# Kopiere Inhalt von docs/supabase_schema.sql
# Führe ausErstelle test-supabase.js:
// test-supabase.js
const { createClient } = require('@supabase/supabase-js');
require('dotenv').config();
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseKey) {
console.error('❌ Fehlende Environment Variables!');
console.log('Setze SUPABASE_URL und SUPABASE_SERVICE_ROLE_KEY in .env');
process.exit(1);
}
const supabase = createClient(supabaseUrl, supabaseKey);
async function testConnection() {
console.log('🔍 Teste Supabase-Verbindung...\n');
// Test 1: Users-Tabelle
try {
const { data, error } = await supabase
.from('users')
.select('count')
.limit(1);
if (error) throw error;
console.log('✅ Users-Tabelle: OK');
} catch (err) {
console.error('❌ Users-Tabelle Fehler:', err.message);
}
// Test 2: Progress-Tabelle
try {
const { data, error } = await supabase
.from('progress')
.select('count')
.limit(1);
if (error) throw error;
console.log('✅ Progress-Tabelle: OK');
} catch (err) {
console.error('❌ Progress-Tabelle Fehler:', err.message);
}
// Test 3: Coin Ledger
try {
const { data, error } = await supabase
.from('coin_ledger')
.select('count')
.limit(1);
if (error) throw error;
console.log('✅ Coin Ledger: OK');
} catch (err) {
console.error('❌ Coin Ledger Fehler:', err.message);
}
// Test 4: User Upsert
try {
const { data, error } = await supabase
.from('users')
.upsert({ id: 'test-user', display_name: 'Test', coins: 0 }, { onConflict: 'id' })
.select();
if (error) throw error;
console.log('✅ User Upsert: OK');
} catch (err) {
console.error('❌ User Upsert Fehler:', err.message);
}
console.log('\n✨ Supabase-Test abgeschlossen!');
}
testConnection();Führe aus:
node test-supabase.js// Test 1: Bootstrap User
fetch('/.netlify/functions/me')
.then(r => r.json())
.then(data => {
console.log('✅ /me Response:', data);
if (data.note && data.note.includes('dev-fallback')) {
console.warn('⚠️ Läuft im Dev-Fallback-Modus (kein Supabase)');
} else {
console.log('✅ Läuft mit Supabase!');
}
});
// Test 2: Progress speichern
fetch('/.netlify/functions/progressSave', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
unitId: 'u1',
questCoinsEarned: 10,
questCompletedCount: 1,
bountyCompleted: false
})
})
.then(r => r.json())
.then(data => console.log('✅ Progress Save:', data));
// Test 3: Coins anpassen
fetch('/.netlify/functions/coinsAdjust', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
delta: 25,
reason: 'test',
refType: 'test',
refId: 'test-123'
})
})
.then(r => r.json())
.then(data => console.log('✅ Coins Adjust:', data));Mögliche Ursachen:
-
@supabase/supabase-jsnicht installiertnpm install @supabase/supabase-js
-
Environment Variables fehlen
- Prüfe
.envDatei - Prüfe Netlify Dashboard → Site Settings → Environment Variables
- Prüfe
-
Supabase Client Initialisierung fehlgeschlagen
- Prüfe
netlify/functions/_supabase.js - Schau in
netlify devTerminal-Logs
- Prüfe
Ursache: Supabase Environment Variables nicht gesetzt
Lösung:
- Erstelle
.envmitSUPABASE_URLundSUPABASE_SERVICE_ROLE_KEY - Oder setze in Netlify Dashboard (für Production)
Mögliche Ursachen:
- Tabellen existieren nicht → Führe
docs/supabase_schema.sqlaus - RLS (Row Level Security) blockiert → Prüfe Supabase Dashboard → Authentication → Policies
- Falscher Key verwendet → Verwende
SERVICE_ROLE_KEYfür Backend-Functions
Lösung: Functions haben bereits CORS-Headers. Falls trotzdem Probleme:
- Prüfe
Access-Control-Allow-OriginHeader in Function-Response - Prüfe Browser Console für genaue Fehlermeldung
# Deploy zu Netlify
netlify deploy --prod
# Teste Production-Endpoints
curl https://deine-site.netlify.app/.netlify/functions/meWichtig: Setze Environment Variables im Netlify Dashboard:
- Site Settings → Environment Variables
SUPABASE_URLSUPABASE_SERVICE_ROLE_KEY
In netlify/functions/me.js (oder anderen Functions):
console.log('🔍 Debug Info:', {
hasSupabaseEnv: !!(process.env.SUPABASE_URL && process.env.SUPABASE_SERVICE_ROLE_KEY),
supabaseUrl: process.env.SUPABASE_URL ? 'SET' : 'MISSING',
authHeader: event.headers?.Authorization ? 'PRESENT' : 'MISSING'
});Schau dann in netlify dev Terminal-Output.
# 1. Starte Netlify Dev
netlify dev
# 2. Öffne Browser Console auf http://localhost:3000
# 3. Führe aus:
fetch('/.netlify/functions/me').then(r => r.json()).then(console.log)
# 4. Erwarte: { user: {...}, progress: [], note: "dev-fallback" }
# Oder: { user: {...}, progress: [...] } wenn Supabase läuftFühre diese Tests in dieser Reihenfolge aus:
-
netlify devstartet ohne Fehler -
/meEndpoint gibt 200 zurück -
/progressGetgibt leeres Array oder Daten zurück -
/progressSavespeichert erfolgreich -
/coinsAdjustpasst Coins an - Frontend zeigt Coins/Progress korrekt an
- Chat senden/abrufen funktioniert
- Supabase-Tabellen existieren (SQL Editor)
- Production-Deploy funktioniert