feat(api): add API key authentication to backend endpoints

Add API key security using fastapi.security.APIKeyHeader to protect /v1/completions and /v1/ocr endpoints. Updated frontend to include X-API-Key header in API requests. Also changed default API base URL from http://149.104.29.239:8001 to https://api.learnteach.tech:8002.
This commit is contained in:
2026-02-19 18:18:47 +08:00
parent 4fe4becdd5
commit 4a979ba7c3
4 changed files with 24 additions and 6 deletions

View File

@@ -22,7 +22,10 @@ export async function fetchSuggestion(prefix, suffix, signal, apiUrl = API_URL)
try {
const settings = useSettingsStore()
const clientIP = await getClientIP()
const headers = { 'Content-Type': 'application/json' }
const headers = {
'Content-Type': 'application/json',
'X-API-Key': 'your-secret-key-here'
}
// Only send IP if privacy mode is OFF
if (clientIP && !settings.privacyMode) {