Skip to content

Redundant Supabase Auth Initialization #1033

@codeCraft-Ritik

Description

@codeCraft-Ritik

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

  1. Move the Supabase client creation to a single utility.
  2. Refactor connectService to be the primary subscriber to onAuthStateChange.
  3. Remove direct Supabase session calls from supabaseProfile.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
    });
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions