Website · Quickstart · Docs · Set up with your AI assistant
@nebulr-group/bridge-nextjs adds sign-in, workspaces and roles, feature flags, Stripe subscriptions and plan limits to a Next.js App Router app, with one .env line and three files.
The Bridge is a hosted backend for SaaS apps. It gives you sign-in (passwords, magic links, passkeys, social login and SSO), multi-tenant workspaces with roles, Stripe subscriptions with plan limits, and feature flags, all managed from one dashboard. Your AI coding assistant can set it up for you through the Bridge MCP server.
Let your AI assistant set it up. Connect the Bridge MCP server to Claude, Cursor, Copilot or Gemini CLI and ask it to add Bridge to your app. Not using MCP? Run
npx @nebulr-group/bridge-cli guide add-loginin your project: it detects your framework frompackage.jsonand prints the steps for your assistant to follow.npx @nebulr-group/bridge-cli doctorchecks the result.
- How Bridge works - the whole integration, plan limits, and customising Bridge's pages
- SDK auth quickstart / Hosted auth quickstart
- Parity with bridge-svelte
One line of .env and three files. Every other page Bridge needs, it serves.
# .env.local
NEXT_PUBLIC_BRIDGE_APP_ID=your-app-id
# only for a stage/local app — the hosted sign-in pages follow it:
# NEXT_PUBLIC_BRIDGE_API_BASE_URL=https://api-stage.thebridge.dev// app/layout.tsx — stays a Server Component; the config is plain data
import { BridgeProvider } from '@nebulr-group/bridge-nextjs/client';
import '@nebulr-group/bridge-nextjs/styles';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<BridgeProvider config={{ loginRoute: '/auth/login' }}>{children}</BridgeProvider>
</body>
</html>
);
}// app/auth/[...bridge]/page.tsx — login, signup, oauth-callback, set-password/[token],
// forgot-password, magic-link, setup-passkey/[token], workspaces
import { BridgeAuthRoutes } from '@nebulr-group/bridge-nextjs/client';
export default function AuthPage() {
return <BridgeAuthRoutes />;
}// app/subscription/[[...bridge]]/page.tsx: /subscription (a checkout lands here, with a banner), /plan (the paywall), /error
import { BridgeBillingRoutes } from '@nebulr-group/bridge-nextjs/client';
export default function SubscriptionPage() {
return <BridgeBillingRoutes />;
}Settings resolve as explicit option > NEXT_PUBLIC_BRIDGE_* environment > default. Plan limits need no page code: a backend 402 QUOTA_EXCEEDED opens the upgrade dialog; <QuotaGate> and useQuota() are there when you want more. See How Bridge works.
- Installation
- Configuration
- Authentication
- Feature Flags
- Payments & Subscriptions
- Demo Application
- E2E Tests
- Publishing & Release
npm install @nebulr-group/bridge-nextjsSee the configuration reference.
For authentication examples and implementation details, see:
- Hosted login (no
loginRoute): the session is a cookie, and thewithBridgeAuthmiddleware is the route guard. It enforces unmatched routes underdefaultAccess: 'protected'and any rule withoutpublic: true. It verifies the session token: its PS256 signature against the Bridge JWKS (<apiBaseUrl>/auth/.well-known/jwks.json), issuer<apiBaseUrl>/auth, audience containing yourappId, and expiry; a failed check denies. - SDK auth (
<LoginForm />,loginRouteset): tokens live in the browser, where middleware cannot see them.withBridgeAuthsteps aside for those requests (it is not authoritative there), and<ProtectedRoute>plus your API are the guards. - Neither route guard is authorization. Every API route must verify the user's token itself.
See Route guards.
For feature flag examples and implementation details, see:
- Feature flags. To gate a route by sign-in and a flag together, put
featureFlagon awithBridgeAuthrule (Next.js runs one middleware): see Route guards.
app/subscription/[[...bridge]]/page.tsx serves the subscription page, the paywall and the checkout return pages. A completed checkout comes back to /subscription with a confirmation banner; billing.successRoute sends it anywhere else. See Add billing to your app and Usage limits.
The demo application (demo/) is the ten-line shape above plus example pages. Its one demo-only file, demo/src/test-fixtures/TestBridgeProvider.tsx, passes the E2E harness's per-worker app id to <BridgeProvider>; a real app renders <BridgeProvider> directly.
E2E tests use Playwright. Run them from the repo root.
- Configure env: Copy
config/.env.test.local.exampletoconfig/.env.test.localand fill in the values (test data API key, etc.). - Pre-setup: The first step of
test:e2eruns a pre-setup script that creates/gets the test app and, for local runs only, writesconfig/.env.demo.test.local(the local API root depends on your slot).config/.env.demo.test.stageandconfig/.env.demo.test.prodare tracked in git with every key explicit. - Global setup: resolves the app id from the test-data API and seeds it into the browser as
localStorage['bridge:appId'], which the demo passes toBridgeProvider(viademo/src/test-fixtures/TestBridgeProvider.tsx) — the demo env files deliberately leaveNEXT_PUBLIC_BRIDGE_APP_IDempty. It then asserts that the demo is serving the environment the Playwright project targets (env pill, API root, and the requests the SDK makes on boot), so a stage run can never quietly drive a local or production backend. - Install browsers (once):
npx playwright install - Run tests (always through these scripts — they pass the environment to the webServer that starts the demo on port 3010):
npm run test:e2e— localnpm run test:e2e:stage— stagenpm run test:e2e:prod— prodnpm run test:e2e:headed— local with browser visiblenpm run test:e2e:report— open last HTML report
paymentsAutoRedirect, stripeEnabled, the SSO flags and the plan catalogue are app-level settings. Global setup therefore provisions one Bridge app per Playwright worker (BRIDGE_NEXTJS_TEST_DASHBOARD, …_W1, …_W2, … — idempotent by domain and reused across runs; worker 0 keeps the unsuffixed domain), ensures the TEAM plan every test account is created on, and seeds each worker's app id into that worker's browser storage. A spec that changes an app-level setting restores it in a finally; the appConfigBaseline fixture re-applies the baseline if a spec died before its finally ran. No spec may delete or rename a plan other specs depend on — use clearTenantPlan to put one tenant in the "no plan" state.
Bridge Next.js is published to npm via GitHub Actions. To release a new version, update the version in bridge-nextjs/package.json, merge to main, and tag the release (e.g. v0.1.0).
We welcome contributions! Please see CONTRIBUTING.md for details.
- Quickstart
- Authentication
- Sign-in inside your app
- Feature flags
- Branding
- Live updates
- Subscriptions and plan limits
| Package | For |
|---|---|
@nebulr-group/bridge-svelte |
SvelteKit |
@nebulr-group/bridge-react |
React |
@nebulr-group/bridge-angular |
Angular |
@nebulr-group/bridge-nestjs |
NestJS |
@nebulr-group/bridge-express |
Express |
@nebulr-group/bridge-cli |
CLI for people and AI agents |
@nebulr-group/bridge-auth-core |
Any JavaScript app (core) |
MIT © Nebulr. Built by The Bridge.
