Fix settings validation and session errors

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 23:48:34 +00:00
parent 439a7f4abf
commit 21d16f01ed
5 changed files with 62 additions and 29 deletions

View File

@@ -60,19 +60,24 @@ export function PrivacyTab() {
}
if (data?.privacy_settings) {
// Validate the data before using it
const validatedSettings = privacySettingsSchema.parse(data.privacy_settings);
setPreferences(validatedSettings);
form.reset({
privacy_level: (profile?.privacy_level === 'public' || profile?.privacy_level === 'private')
? profile.privacy_level
: 'public',
show_pronouns: profile?.show_pronouns || false,
...validatedSettings
});
const parseResult = privacySettingsSchema.safeParse(data.privacy_settings);
if (parseResult.success) {
setPreferences(parseResult.data);
form.reset({
privacy_level: (profile?.privacy_level === 'public' || profile?.privacy_level === 'private')
? profile.privacy_level
: 'public',
show_pronouns: profile?.show_pronouns || false,
...parseResult.data
});
} else {
console.warn('Invalid privacy settings, reinitializing with defaults', {
errors: parseResult.error.issues
});
await initializePreferences();
}
} else {
// Initialize preferences if they don't exist
await initializePreferences();
}
} catch (error) {

View File

@@ -146,19 +146,30 @@ export function SecurityTab() {
const fetchSessions = async () => {
if (!user) return;
const { data, error } = await supabase.rpc('get_my_sessions');
setLoadingSessions(true);
if (error) {
try {
const { data, error } = await supabase.rpc('get_my_sessions');
if (error) {
throw error;
}
setSessions((data as AuthSession[]) || []);
} catch (error) {
logger.error('Failed to fetch sessions', {
userId: user.id,
action: 'fetch_sessions',
error: error.message
error: error instanceof Error ? error.message : String(error)
});
handleError(error, { action: 'Load sessions', userId: user.id });
} else {
setSessions((data as AuthSession[]) || []);
handleError(error, {
action: 'Load active sessions',
userId: user.id
});
setSessions([]);
} finally {
setLoadingSessions(false);
}
setLoadingSessions(false);
};
const initiateSessionRevoke = async (sessionId: string) => {