Skip to main content
The @urbackend/react SDK provides everything you need to build secure, scalable React applications on top of urBackend. It handles the heavy lifting of session persistence, social logins, and routing out of the box.

Features

  • Pre-built Auth UI: A beautiful, customizable <UrAuth /> component for login/signup (email/password & social).
  • Session Management: Automatically persists the access token (ub_auth_token) and refresh token (ub_refresh_token) to localStorage, and handles silent background refreshes over the x-refresh-token header so cross-domain setups work without shared cookies.
  • Protected Routing: Simple <ProtectedRoute> and <GuestRoute> wrappers to secure your pages.
  • Customizable UI: Includes <UrUserButton /> for a ready-to-use profile dropdown.
  • Powerful Hooks: useUser, useAuth, useDb, and useStorage to interact with your backend data natively.

Installation

Install the React SDK along with the core TypeScript SDK (which it uses under the hood):

Setup (Create React App / Vite)

To get started, wrap your root application with the <UrProvider> and pass your project’s Publishable API Key.
Always use your Publishable Key (pk_live_...) in the browser. Never use your Secret Key (sk_live_...) on the frontend, as it grants full administrative access.
src/main.tsx

Setup (Next.js App Router)

If you are using Next.js with the App Router, create a Client Component provider to wrap your application:
src/components/Providers.tsx
Then, wrap your layout:
src/app/layout.tsx

Next Steps

Now that your provider is set up, you can start building your authentication flow and accessing your data.

Authentication UI

Add a login screen in one line of code.

Protect Routes

Secure your application pages.