import { useEffect, useState } from "react";
import {
  getSession,
  subscribeSession,
  type AuthPlatform,
  type AuthSession,
} from "@/lib/auth";

/** Live session that refreshes when profile/avatar changes. */
export function useAuthSession(platform: AuthPlatform): AuthSession | null {
  const [session, setSession] = useState<AuthSession | null>(() => getSession(platform));

  useEffect(() => {
    setSession(getSession(platform));
    return subscribeSession(platform, () => setSession(getSession(platform)));
  }, [platform]);

  return session;
}
