mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 12:11:11 -05:00
Fix settings validation and session errors
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user