import React, { useState, useEffect } from 'react'; import { Settings, Save, Trash2, Key, User, Lock, Plus, X, RefreshCw, Server, Database } from 'lucide-react'; import { useAppContext } from './AppContext'; const ProfilePage = () => { const { activeSpecId, activeSpecName, storedCredentials, saveProfile, addToast, } = useAppContext(); const [profileForm, setProfileForm] = useState({ name: '', email: '', password: '', token: '' }); const [extraKvs, setExtraKvs] = useState([]); const [isSaving, setIsSaving] = useState(false); // Sync stored credentials into local form useEffect(() => { if (!storedCredentials) return; setProfileForm({ name: storedCredentials.name || '', email: storedCredentials.email || storedCredentials.username || '', password: '', // Don't prefill password token: storedCredentials.access_token || storedCredentials.token || '' }); const standardKeys = new Set(['name', 'email', 'username', 'password', 'access_token', 'token', 'refresh_token', 'id_token']); const kvs = Object.entries(storedCredentials) .filter(([k, v]) => !standardKeys.has(k) && k !== '_clear') .map(([k, v]) => ({ key: k, val: String(v) })); setExtraKvs(kvs); }, [storedCredentials]); const handleSave = async () => { if (!activeSpecId) return; setIsSaving(true); try { const payload = { name: profileForm.name, username: profileForm.email, extra: {} }; if (profileForm.password) payload.password = profileForm.password; if (profileForm.token) payload.extra.token = profileForm.token; extraKvs.forEach(kv => { if (kv.key && kv.val) payload.extra[kv.key] = kv.val; }); await saveProfile(payload); } catch (err) { console.error("Save failed", err); addToast('error', err.message || "Failed to save profile."); } finally { setIsSaving(false); } }; if (!activeSpecId) { return (
Test user profiles are isolated per collection. Please select an API specification first to manage its credentials.
No custom variables defined. Use these for OTPs, User IDs, or custom test data pointers.