Skip to content

ServiceKeysManager

Service Keys Manager

Manages service keys (anon and service) for tenant databases. Each tenant has their own auth.service_keys table.

// List all service keys
const { data, error } = await client.admin.serviceKeys.list()
// Create a new service key
const { data, error } = await client.admin.serviceKeys.create({
name: 'Production API Key',
key_type: 'service',
scopes: ['*']
})
// Rotate a key
const { data, error } = await client.admin.serviceKeys.rotate('key-id')

new ServiceKeysManager(fetch): ServiceKeysManager

Parameter Type
fetch FluxbaseFetch

ServiceKeysManager

create(request): Promise<{ data: ServiceKeyWithKey | null; error: Error | null; }>

Create a new service key

The full key value is only returned once - store it securely!

Parameter Type Description
request CreateServiceKeyRequest Key creation options

Promise<{ data: ServiceKeyWithKey | null; error: Error | null; }>

Created key with full key value

const { data, error } = await client.admin.serviceKeys.create({
name: 'Production API Key',
key_type: 'service',
scopes: ['*'],
rate_limit_per_minute: 1000
})
if (data) {
// Store data.key securely - it won't be shown again!
console.log('Key created:', data.key)
}

delete(id): Promise<{ error: Error | null; }>

Delete a service key permanently

Parameter Type Description
id string Service key ID

Promise<{ error: Error | null; }>

Success or error

const { error } = await client.admin.serviceKeys.delete('key-id')

deprecate(id, request?): Promise<{ data: { deprecated_at: string; grace_period_ends_at: string; } | null; error: Error | null; }>

Deprecate a service key (graceful rotation)

Marks the key for removal but keeps it active during grace period.

Parameter Type Description
id string Service key ID
request? DeprecateServiceKeyRequest Deprecation options

Promise<{ data: { deprecated_at: string; grace_period_ends_at: string; } | null; error: Error | null; }>

Deprecation details

const { data, error } = await client.admin.serviceKeys.deprecate('key-id', {
reason: 'Rotating to new key',
grace_period_hours: 48
})

disable(id): Promise<{ error: Error | null; }>

Disable a service key (temporarily)

Parameter Type Description
id string Service key ID

Promise<{ error: Error | null; }>

Success or error

const { error } = await client.admin.serviceKeys.disable('key-id')

enable(id): Promise<{ error: Error | null; }>

Enable a disabled service key

Parameter Type Description
id string Service key ID

Promise<{ error: Error | null; }>

Success or error

const { error } = await client.admin.serviceKeys.enable('key-id')

get(id): Promise<{ data: ServiceKey | null; error: Error | null; }>

Get a service key by ID

Parameter Type Description
id string Service key ID

Promise<{ data: ServiceKey | null; error: Error | null; }>

Service key details

const { data, error } = await client.admin.serviceKeys.get('key-id')

getRevocationHistory(id): Promise<{ data: { id: string; name: string; revocation_reason: string; revoked_at: string; revoked_by: string; } | null; error: Error | null; }>

Get revocation history for a service key

Parameter Type Description
id string Service key ID

Promise<{ data: { id: string; name: string; revocation_reason: string; revoked_at: string; revoked_by: string; } | null; error: Error | null; }>

Revocation history

const { data, error } = await client.admin.serviceKeys.getRevocationHistory('key-id')

list(): Promise<{ data: ServiceKey[] | null; error: Error | null; }>

List all service keys

Promise<{ data: ServiceKey[] | null; error: Error | null; }>

List of service keys

const { data, error } = await client.admin.serviceKeys.list()

revoke(id, request?): Promise<{ error: Error | null; }>

Revoke a service key permanently (emergency)

Use for immediate revocation when a key is compromised.

Parameter Type Description
id string Service key ID
request? RevokeServiceKeyRequest Revocation options

Promise<{ error: Error | null; }>

Success or error

const { error } = await client.admin.serviceKeys.revoke('key-id', {
reason: 'Key was compromised'
})

rotate(id): Promise<{ data: ServiceKeyWithKey | null; error: Error | null; }>

Rotate a service key (create replacement)

Creates a new key with the same settings and deprecates the old one. The new key is returned with its full value.

Parameter Type Description
id string Service key ID to rotate

Promise<{ data: ServiceKeyWithKey | null; error: Error | null; }>

New key with full key value

const { data, error } = await client.admin.serviceKeys.rotate('old-key-id')
if (data) {
console.log('New key:', data.key)
console.log('Old key deprecated at:', data.deprecated_at)
}

update(id, request): Promise<{ data: ServiceKey | null; error: Error | null; }>

Update a service key

Parameter Type Description
id string Service key ID
request UpdateServiceKeyRequest Update options

Promise<{ data: ServiceKey | null; error: Error | null; }>

Updated key

const { data, error } = await client.admin.serviceKeys.update('key-id', {
name: 'New Name',
rate_limit_per_minute: 2000
})