Welcome to Nebutra Sailor Docs 🎉
ChangelogIntroductionLicensing
Help Center (External) ↗

Authentication

How Nebutra handles auth end-to-end — Better Auth setup, token verification, and session management.

Auth provider

Better Auth is the only auth provider in the Sailor stack. The Sailor Convergence ADR (2026-09-24) deleted the Clerk, NextAuth/Auth.js, and Supabase Auth adapters that @nebutra/auth used to switch between — there is nothing left to choose, and no AUTH_PROVIDER value other than better-auth (or dev, the local fallback used when BETTER_AUTH_SECRET is unset).

Keep AUTH_PROVIDER and NEXT_PUBLIC_AUTH_PROVIDER aligned so server routes, middleware, React hooks, and the landing page all resolve to the same provider.

# .env
AUTH_PROVIDER=better-auth
NEXT_PUBLIC_AUTH_PROVIDER=better-auth

Without BETTER_AUTH_SECRET set, the app runs against the dev fallback — a synthetic user and workspace, useful for local previews, hard-disabled in production. nebutra status reports this as local-fallback.

Google One Tap

The landing page's One Tap implementation is Better Auth's own client oneTapClient, which POSTs to /api/auth/one-tap/callback. It needs NEXT_PUBLIC_GOOGLE_CLIENT_ID set.

Set NEXT_PUBLIC_ENABLE_GOOGLE_ONE_TAP=false to disable the landing prompt. When ACCESS_GATE_MODE=invite, OAuth and One Tap entrypoints are blocked until the invite gate is opened.

Better Auth setup

Production Nebutra uses a dedicated auth center (apps/auth → https://auth.nebutra.com) with:

VariableExample
AUTH_PROVIDERbetter-auth
BETTER_AUTH_URL / NEXT_PUBLIC_AUTH_URLhttps://auth.nebutra.com
AUTH_COOKIE_DOMAIN.nebutra.com
BETTER_AUTH_SECRETshared across auth + web

Single login entry

Product apps are RPs: they soft-redirect auth surfaces to the auth-center. There is one Better Auth UI — do not keep a second sign-in page on app.

SurfaceBehavior
app.nebutra.com/sign-in307 → auth.nebutra.com/sign-in?returnTo=…
app.nebutra.com/sign-up307 → auth.nebutra.com/sign-up?returnTo=…
auth.nebutra.com/*Canonical login UI (credentials, OAuth, optional magic link / passkeys)

OAuth redirect URIs

Register callbacks on the auth-center origin (not app):

https://auth.nebutra.com/api/auth/callback/google
https://auth.nebutra.com/api/auth/callback/github

GET /health on the auth-center returns oauth.callbackUrls for currently enabled providers.

Captcha, magic link, passkeys

Flag / envEffect
NEXT_PUBLIC_TURNSTILE_SITE_KEY + TURNSTILE_SECRET_KEYCloudflare Turnstile on forms (x-captcha-response)
NEXT_PUBLIC_AUTH_MAGIC_LINK=1Magic-link alternate on sign-in
NEXT_PUBLIC_AUTH_PASSKEYS=1Passkey button + conditional UI
PASSKEY_RP_ID / PASSKEY_ORIGINWebAuthn RP overrides (default: auth host)

Keep BETTER_AUTH_SECRET identical across RP apps.

Device authorization (CLI login)

The auth center also mounts Better Auth's deviceAuthorization + bearer plugins, used by nebutra login (see nebutra CLI) — a separate, opt-in surface from the cookie-based session flow above, gated behind AuthConfig.options.deviceAuthorization so it exists only on apps/auth, not on every app that constructs a Better Auth instance.

Token verification (API Gateway)

The Hono API gateway verifies Better Auth on every protected request (@nebutra/auth middleware): session cookies / bearer JWTs are validated against the shared secret and database session store. Service-to-service calls use a short-lived HS256 x-service-token (SERVICE_SECRET) — legacy hex-HMAC tokens are rejected.

app.use("/api/*", authMiddleware());

app.get("/api/projects", async (c) => {
  const { userId, orgId } = c.get("auth");
  // userId and orgId are verified and safe to use
});

JWT claims

Verified user tokens typically include:

{
  "sub": "user_2a8bXXXXXXXXX",
  "org_id": "org_2a8bXXXXXXXXX",
  "org_role": "org:admin",
  "org_slug": "acme",
  "scopes": ["project:read", "project:create", "project:update"],
  "plan": "pro",
  "iat": 1743427200,
  "exp": 1743430800
}

The scopes claim is set by Nebutra's RBAC layer at token issuance time.

Session management

  • Session cookie issued on auth.nebutra.com with AUTH_COOKIE_DOMAIN=.nebutra.com
  • Dashboard and other RPs read the same cookie after returnTo redirect
  • Revoke / sign-out via Better Auth session APIs on the auth-center

Multi-factor authentication

MFA can be enforced at the org level (product settings):

  • TOTP (authenticator apps)
  • SMS OTP (when configured)
  • Passkeys (WebAuthn) — enable on auth-center with NEXT_PUBLIC_AUTH_PASSKEYS=1

Sign-in / Sign-up UI

Use the auth-center pages under apps/auth (/sign-in, /sign-up, /forgot-password, …). Product apps only redirect — there is no per-app sign-in page to build or maintain.

Organization creation flow

After sign-up, users without an organization are redirected to the org creation flow (Nebutra dashboard onboarding).

Without an org-creation path, users can end up with orgId: null and bounce between landing and dashboard. Always implement this flow for multi-tenant apps.

Related

Permissions

How scopes are assigned and enforced.

Multi-Tenancy

Tenant isolation and member roles.

How is this guide?

Edit on GitHub

Last updated on

On this page

Auth provider
Google One Tap
Better Auth setup
Single login entry
OAuth redirect URIs
Captcha, magic link, passkeys
Device authorization (CLI login)
Token verification (API Gateway)
JWT claims
Session management
Multi-factor authentication
Sign-in / Sign-up UI
Organization creation flow
Related