Am I doing something wrong, or does the @dfinity/agent
not work in the Next.js SSG context?
In a pre-rendered Next.js project set for static export (output: "export"
), I am defining the request generateStaticParams
, which is used to generate the dynamic routes at build time. Within that function, I use the HttpClient
to fetch some data, as in this dummy example:
export async function generateStaticParams() {
const agent = await HttpAgent.create({
identity: new AnonymousIdentity(),
host: "https://icp-api.io",
verifyQuerySignatures: true,
});
const actor = Actor.createActor(idlFactory, {
agent,
canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai"
});
const {icrc1_balance_of} = actor;
// ⚠️ ERRORS
// - Invalid signature from replica
// - Certificate is signed more than 5 minutes in the past ...
console.log(await icrc1_balance_of({
owner: Principal.fromText("2vxsx-fae"),
subaccount: []
}))
return [{product_id: "2vxsx-fae"}]
}
As a result, I end up facing the following errors (one or the other):
Error: Invalid certificate: Invalid signature from replica ncr4b-rasb7-tueb3-n4uos-5nxou-3wbxv-xmyt3-wfdsd-vu4b6-5x3cp-aqe signed query.
or
Error: Invalid certificate: Certificate is signed more than 5 minutes in the past. Certificate time: 2024-08-11T15:55:32.249Z Current time: 2024-08-11T16:03:35.551Z
So I’m wondering if I am doing something wrong or if indeed Agent-js does not work in that context?
This error was reported by a Juno developer, and I am able to reproduce it with a sample repo:
git clone https://github.com/peterpeterparker/next-agentjs
cd next-agentjs
npm ci
npm run dev