mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:11:13 -05:00
Fix settings validation and session errors
This commit is contained in:
@@ -60,19 +60,24 @@ export function PrivacyTab() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data?.privacy_settings) {
|
if (data?.privacy_settings) {
|
||||||
// Validate the data before using it
|
const parseResult = privacySettingsSchema.safeParse(data.privacy_settings);
|
||||||
const validatedSettings = privacySettingsSchema.parse(data.privacy_settings);
|
|
||||||
setPreferences(validatedSettings);
|
|
||||||
|
|
||||||
form.reset({
|
if (parseResult.success) {
|
||||||
privacy_level: (profile?.privacy_level === 'public' || profile?.privacy_level === 'private')
|
setPreferences(parseResult.data);
|
||||||
? profile.privacy_level
|
form.reset({
|
||||||
: 'public',
|
privacy_level: (profile?.privacy_level === 'public' || profile?.privacy_level === 'private')
|
||||||
show_pronouns: profile?.show_pronouns || false,
|
? profile.privacy_level
|
||||||
...validatedSettings
|
: '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 {
|
} else {
|
||||||
// Initialize preferences if they don't exist
|
|
||||||
await initializePreferences();
|
await initializePreferences();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -146,19 +146,30 @@ export function SecurityTab() {
|
|||||||
const fetchSessions = async () => {
|
const fetchSessions = async () => {
|
||||||
if (!user) return;
|
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', {
|
logger.error('Failed to fetch sessions', {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
action: 'fetch_sessions',
|
action: 'fetch_sessions',
|
||||||
error: error.message
|
error: error instanceof Error ? error.message : String(error)
|
||||||
});
|
});
|
||||||
handleError(error, { action: 'Load sessions', userId: user.id });
|
handleError(error, {
|
||||||
} else {
|
action: 'Load active sessions',
|
||||||
setSessions((data as AuthSession[]) || []);
|
userId: user.id
|
||||||
|
});
|
||||||
|
setSessions([]);
|
||||||
|
} finally {
|
||||||
|
setLoadingSessions(false);
|
||||||
}
|
}
|
||||||
setLoadingSessions(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const initiateSessionRevoke = async (sessionId: string) => {
|
const initiateSessionRevoke = async (sessionId: string) => {
|
||||||
|
|||||||
@@ -18,17 +18,18 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Schema for privacy settings in user_preferences
|
* Schema for privacy settings in user_preferences
|
||||||
|
* Uses defaults for backward compatibility with incomplete data
|
||||||
*/
|
*/
|
||||||
export const privacySettingsSchema = z.object({
|
export const privacySettingsSchema = z.object({
|
||||||
activity_visibility: z.enum(['public', 'private'] as const),
|
activity_visibility: z.enum(['public', 'private'] as const).default('public'),
|
||||||
search_visibility: z.boolean(),
|
search_visibility: z.boolean().default(true),
|
||||||
show_location: z.boolean(),
|
show_location: z.boolean().default(false),
|
||||||
show_age: z.boolean(),
|
show_age: z.boolean().default(false),
|
||||||
show_avatar: z.boolean(),
|
show_avatar: z.boolean().default(true),
|
||||||
show_bio: z.boolean(),
|
show_bio: z.boolean().default(true),
|
||||||
show_activity_stats: z.boolean(),
|
show_activity_stats: z.boolean().default(true),
|
||||||
show_home_park: z.boolean()
|
show_home_park: z.boolean().default(false)
|
||||||
});
|
}).passthrough();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schema for profile privacy settings
|
* Schema for profile privacy settings
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export interface AuthSession {
|
|||||||
user_agent: string | null;
|
user_agent: string | null;
|
||||||
ip: string | null; // Pre-hashed by database function
|
ip: string | null; // Pre-hashed by database function
|
||||||
not_after: string | null;
|
not_after: string | null;
|
||||||
aal: AALLevel | null;
|
aal: string | null; // Changed to string to match get_my_sessions() return type
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
-- Backfill missing privacy settings fields for existing users
|
||||||
|
UPDATE user_preferences
|
||||||
|
SET privacy_settings = privacy_settings || jsonb_build_object(
|
||||||
|
'show_avatar', COALESCE((privacy_settings->>'show_avatar')::boolean, true),
|
||||||
|
'show_bio', COALESCE((privacy_settings->>'show_bio')::boolean, true),
|
||||||
|
'show_activity_stats', COALESCE((privacy_settings->>'show_activity_stats')::boolean, true),
|
||||||
|
'show_home_park', COALESCE((privacy_settings->>'show_home_park')::boolean, false)
|
||||||
|
)
|
||||||
|
WHERE
|
||||||
|
privacy_settings IS NOT NULL
|
||||||
|
AND (
|
||||||
|
privacy_settings->>'show_avatar' IS NULL OR
|
||||||
|
privacy_settings->>'show_bio' IS NULL OR
|
||||||
|
privacy_settings->>'show_activity_stats' IS NULL OR
|
||||||
|
privacy_settings->>'show_home_park' IS NULL
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user