Error updating api key

I am facing an error while trying to update the api key, my code:
import type { IncomingHttpHeaders } from 'node:http'
import { auth } from '../../lib/auth.ts'
import type { UpdateApiKeyBody } from '../../schemas/api-keys/index.ts'

export async function updateApiKey(
  userId: string,
  keyId: string,
  body: UpdateApiKeyBody,
  headers: IncomingHttpHeaders
) {
  console.log(body)
  const apiKey = await auth.api.updateApiKey({
    body: {
      ...body,
      keyId,
    },
    headers,
  })
  console.log('apiKey', apiKey)

  return apiKey
}


body: { name: 'teste', enabled: true, rateLimitEnabled: false }

error:
[APIError: The property you're trying to set can only be set from the server auth instance only.] {
status: 'BAD_REQUEST',
body: {
code: 'THE_PROPERTY_YOURE_TRYING_TO_SET_CAN_ONLY_BE_SET_FROM_THE_SERVER_AUTH_INSTANCE_ONLY',
message: "The property you're trying to set can only be set from the server auth instance only."
},
headers: {},
statusCode: 400
}

my typing of body:
type UpdateApiKeyBody = {
    name?: string | undefined;
    refillInterval?: number | undefined;
    refillAmount?: number | undefined;
    enabled?: boolean | undefined;
    rateLimitEnabled?: boolean | undefined;
    rateLimitTimeWindow?: number | undefined;
    rateLimitMax?: number | undefined;
    remaining?: number | undefined;
    expiresIn?: number | null | undefined;
    metadata?: Record<string, any> | null | undefined;
    permissions?: Record<string, string[]> | null | undefined;
}
Was this page helpful?