Skip to Content

Scopes

A scope keeps one user's or organization's endpoints and events apart from everyone else's. It never grants access by itself.

Every endpoint and every event belongs to exactly one scope, and an event only reaches endpoints in its own scope. That is how one installation serves many users and organizations without crossing their events.

ScopeValue
Application scopenull: endpoints your platform registers for itself
Named scope{ type, id }, for example { type: 'organization', id: 'org_123' }

There is no inheritance and no fallback. Application scope is not a parent of the named scopes: to reach the endpoints in a named scope, publish in that exact scope.

Choosing a scope in code

The root client uses application scope. forScope() returns the same methods bound to a named scope.

import { webhooks } from './webhooks.js'

await webhooks.publish({ type: 'invoice.paid', data }) // application scope

const organization = webhooks.forScope({ type: 'organization', id: organizationId })
await organization.endpoints.create({ url, eventTypes: ['invoice.paid'] })
await organization.publish({ type: 'invoice.paid', data }) // reaches that organization's endpoints

Scopes don't authorize

forScope() and the provider methods trust the scope you pass. Check that the caller may act for that user or organization before choosing the scope. Never pass an unchecked ID from a request body.

The Better Auth routes are the exception: they check the session, organization membership, and permissions on every request. The trusted provider from createBetterAuthManagement() skips those checks, which is what a worker needs.

Rules and limits

  • type is 1 to 64 characters and id is 1 to 200. Neither may be blank or contain null bytes.
  • The same id under two type values is two different scopes.
  • A scope holds at most 1,000 live endpoints. maxEndpoints can lower that per scope.
  • Idempotency keys are unique per scope, not globally.

When an owner goes away

The Better Auth plugin retires a user's or organization's endpoints when the owner is deleted. With standalone management, call removeScope(scope) from your own deletion workflow.

On this page