import { AdminRPC } from "@my-sst-monorepo/functions/admins/rpc";
import { fetchAuthSession } from "aws-amplify/auth";
import { hc } from "hono/client";
const getAccessToken = async () => {
const session = await fetchAuthSession();
if (!session.tokens) {
throw new Error("No session");
}
return session.tokens.accessToken.toString();
};
const createRpcClient = async () => {
const accessToken = await getAccessToken();
return hc<AdminRPC>(process.env.NEXT_PUBLIC_API_URL!, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
};
export async function listAdmins() {
const rpc = await createRpcClient();
const res = await rpc.admins.$get();
if (!res.ok) {
throw new Error(`Failed to list admins: ${res.status}`);
}
return await res.json();
}