Skip to content

Get started with Bridge authentication, feature flags, and team management in your React application.


Install the Bridge React plugin:

Terminal window
npm add @nebulr-group/bridge-react

Wrap your application with the BridgeProvider and pass your appId:

src/main.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BridgeProvider } from '@nebulr-group/bridge-react';
import App from './App';
import './index.css';
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<BridgeProvider appId="YOUR_APP_ID">
<App />
</BridgeProvider>
</React.StrictMode>
);

Step 3: Set up OAuth callback and protect your routes

Section titled “Step 3: Set up OAuth callback and protect your routes”

Use the built-in CallbackHandler for the /auth/oauth-callback route, and wrap all protected routes in a single ProtectedRoute. The component auto-starts the hosted login flow; no local /login page is needed.

src/App.tsx
import { CallbackHandler, ProtectedRoute, setRouterAdapter } from '@nebulr-group/bridge-react';
import { useEffect } from 'react';
import { BrowserRouter, Routes, Route, useNavigate } from 'react-router-dom';
function RouterAdapterBinder() {
const navigate = useNavigate();
useEffect(() => {
setRouterAdapter({
navigate: (path, options) => navigate(path, { replace: options?.replace }),
replace: (path) => navigate(path, { replace: true }),
getCurrentPath: () => window.location.pathname
});
}, [navigate]);
return null;
}
function App() {
return (
<BrowserRouter>
<RouterAdapterBinder />
<Routes>
{/* Public routes */}
<Route path="/auth/oauth-callback" element={<CallbackHandler />} />
{/* Protected subtree */}
<Route
path="/*"
element={
<ProtectedRoute>
<Routes>
{/* Your protected routes */}
<Route path="/" element={<div>Home</div>} />
{/* <Route path="/dashboard" element={<Dashboard />} /> */}
</Routes>
</ProtectedRoute>
}
/>
</Routes>
</BrowserRouter>
);
}

You’re done. For login UI, route protection, feature flags, profiles and more, see the full Examples.