-
Notifications
You must be signed in to change notification settings - Fork 54
Redundant Supabase Auth Initialization #1033
Copy link
Copy link
Open
Description
Summary
The application initializes Supabase and session logic in multiple disparate services, increasing the risk of race conditions and fragmented user states.
Full Description
Currently, supabaseProfile.svelte.ts and connect.svelte.ts both manage authentication-related data. If a session updates in one, the other may not reflect the change immediately. Centralizing this into a single "Source of Truth" ensures that the connectService is the only service responsible for the user's identity.
How to Resolve
- Move the Supabase client creation to a single utility.
- Refactor connectService to be the primary subscriber to onAuthStateChange.
- Remove direct
Supabasesession calls fromsupabaseProfile.svelte.ts.
Code Fix In src/lib/services/connect/services/connect.svelte.ts:
import { supabase } from "../../community/utils/supabase-client"; // Centralized client
export const connectService = {
user: $state<any>(null),
async updateStatus() {
// Single subscription point for the whole app
supabase.auth.onAuthStateChange((event, session) => {
this.user = session?.user || null;
// Sync other profiles here if necessary
});
}
};
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels