Metanow Docs
API & Integration

Authentication

How to authenticate with the MetaNow Console API using sessions or bearer tokens.

MetaNow Console uses Better Auth for identity and session management. Every non-public API endpoint is protected by OrgGuard, which resolves the caller's organisation from either a session cookie or a bearer token.

Methods

Browser-based sign-in uses an HTTP-only session cookie. The auth endpoints live at {BETTER_AUTH_URL}/api/auth/*.

Sign up

POST {BETTER_AUTH_URL}/api/auth/sign-up/email
Content-Type: application/json

{
  "name": "Alice",
  "email": "alice@example.com",
  "password": "your-password"
}

Sign in

POST {BETTER_AUTH_URL}/api/auth/sign-in/email
Content-Type: application/json

{
  "email": "alice@example.com",
  "password": "your-password"
}

On success the server sets a Set-Cookie header. Subsequent requests from the same browser origin automatically include the cookie.

Sessions expire after 7 days. They are refreshed automatically if the cookie is used within a 24-hour window.

For programmatic access (scripts, CI jobs, AI agents), use an agent token instead of a session cookie.

GET /entities
Authorization: Bearer mnk_your_agent_token_here

Agent tokens are long-lived, scoped bearer tokens that do not require a user session. See Agent Tokens for how to create and manage them.

Google OAuth (optional)

If the server is configured with GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, users can sign in with Google. The redirect URI registered in the Google Console must be:

{BETTER_AUTH_URL}/api/auth/callback/google

The sign-in flow redirects the user to Google and back. No additional work is needed on the API consumer side.

How OrgGuard resolves tenancy

Every protected endpoint is wrapped in OrgGuard. On each request it:

  1. Calls auth.api.getSession() with the request headers — this checks both the session cookie and the Authorization: Bearer header.
  2. Looks up the platform user row using the better_auth_id returned by the session. The platform user row carries the org_id.
  3. Attaches { orgId, userId } to the request. Every subsequent service call receives orgId as its first argument.

A valid session with no matching platform user row returns 401 Unauthorized. This state should not occur in normal operation (the sign-up hook creates both records atomically), but it is treated as unauthenticated to avoid ambiguity.

Error responses

StatusMeaning
401 UnauthorizedNo active session or invalid bearer token
403 TWO_FACTOR_SETUP_REQUIREDThe session belongs to a tenant admin or a head-office account that has not set up two-step sign-in yet. Every API call is refused until it does (/api/auth/two-factor/*)
403 EMAIL_NOT_VERIFIEDPOST /api/auth/sign-in/email with the right password on an address that is not confirmed yet; a new confirmation link is mailed
404 Not FoundResource belongs to another org (never 403)

Cross-org access returns 404 rather than 403 to prevent an attacker from probing whether a resource exists in another organisation.

On this page