Auth error for Cloudflare D1 Migrations over remote environments

I have a Hono app with better-auth over Cloudflare Workers that is binded to a D1 database.
On the local environment everything works fine including migrations, but on remote the same endpoint I use for migrations fails with Error: D1_ERROR: not authorized: SQLITE_AUTH

The migration function:
const auth = initAuth(c);

const { toBeCreated, toBeAdded, runMigrations } = await getMigrations(
  auth.options
);

if (!toBeCreated.length && !toBeAdded.length) {
  return c.json({ status: 403, message: "No migrations to run" }, 403);
}

await runMigrations(); // Fails here

return c.json({
  status: 200,
  message: "Database migration ran successfully!",
});


This only happens on deployed D1 databases, on the local mocked through wrangler migrations work well.
It's not because of my API since I don't have any filter on the migratipn route yet, any idea why is happening and how to bypass it?
Was this page helpful?