// hooks/useAuthToken.ts
import { useMemo } from "react";

type AuthStorage = {
  state?: {
    token?: string;
  };
};

export function useAuthToken() {
  const token = useMemo(() => {
    const authStorage = localStorage.getItem("auth-storage");

    if (!authStorage) return null;

    try {
      const parsed: AuthStorage = JSON.parse(authStorage);
      return parsed?.state?.token ?? null;
    } catch (error) {
      console.error("Failed to parse auth-storage:", error);
      return null;
    }
  }, []);

  return token;
}
