import { createMiddleware } from "@tanstack/react-start";
import { supabaseExt } from "./client";

export const attachExtSupabaseAuth = createMiddleware({ type: "function" }).client(
  async ({ next }) => {
    const { data } = await supabaseExt.auth.getSession();
    const token = data.session?.access_token;
    return next({
      headers: token ? { Authorization: `Bearer ${token}` } : {},
    });
  },
);