Build Your App
React
Pre-built sign-in and sign-up forms, auth provider, hooks for user and session state, and organization helpers.
@banata-auth/react provides UI components and hooks for building auth flows in your React application. Use it alongside @banata-auth/nextjs to get a complete client + server integration.
npm install @banata-auth/reactPackage Exports
| Import path | What it provides |
|---|---|
@banata-auth/react | UI components (SignInForm, SignUpForm, SocialButtons, AuthCard), provider, and hooks |
@banata-auth/react/plugins | createAuthClient and client plugins (e.g., organizationClient) |
@banata-auth/react/convex | Convex provider bridge for apps that use both Banata Auth and Convex |
Browser Auth Client
Before using any components or hooks, create a browser auth client. This client talks to your app's /api/auth route:
// src/lib/auth-client.ts
"use client";
import { createAuthClient } from "@banata-auth/react/plugins";
export const authClient = createAuthClient({
baseURL: "/api/auth",
});Pre-Built Forms
SignInForm
A complete sign-in form that supports all enabled auth methods:
"use client";
import Link from "next/link";
import { SignInForm } from "@banata-auth/react";
import { authClient } from "@/lib/auth-client";
export default function SignInPage() {
return (
<SignInForm
authClient={authClient}
callbackURL="/"
title="Sign in"
description="Welcome back!"
footer={<Link href="/sign-up">Create an account</Link>}
/>
);
}SignUpForm
"use client";
import Link from "next/link";
import { SignUpForm } from "@banata-auth/react";
import { authClient } from "@/lib/auth-client";
export default function SignUpPage() {
return (
<SignUpForm
authClient={authClient}
callbackURL="/"
title="Create account"
footer={<Link href="/sign-in">Already have an account?</Link>}
/>
);
}SocialButtons
Render social login buttons for specific providers:
import { SocialButtons } from "@banata-auth/react";
import { authClient } from "@/lib/auth-client";
const providers = [
{ id: "google", label: "Google" },
{ id: "github", label: "GitHub" },
];
<SocialButtons
providers={providers}
authClient={authClient}
callbackURL="/dashboard"
/>Each provider object accepts:
| Property | Type | Description |
|---|---|---|
id | string | Provider identifier: "google", "github", "apple", etc. |
label | string | Display text for the button |
icon | ReactNode | Optional custom icon |
Auth Provider and Hooks
To access auth state in client components throughout your app, wrap your layout with BanataAuthProvider:
// src/components/auth-provider.tsx
"use client";
import { BanataAuthProvider } from "@banata-auth/react";
const adapter = {
fetchSession: async () => {
const response = await fetch("/api/auth/get-session");
if (!response.ok) return null;
return response.json();
},
signOut: async () => {
await fetch("/api/auth/sign-out", { method: "POST" });
},
};
export function AuthProvider({ children }: { children: React.ReactNode }) {
return (
<BanataAuthProvider adapter={adapter}>
{children}
</BanataAuthProvider>
);
}Then use the provided hooks in any client component:
useUser()
Get the current user and auth status:
import { useUser } from "@banata-auth/react";
function ProfileButton() {
const { user, isLoading, signOut } = useUser();
if (isLoading) return <span>Loading...</span>;
if (!user) return <a href="/sign-in">Sign in</a>;
return (
<div>
<span>{user.name}</span>
<button onClick={signOut}>Sign out</button>
</div>
);
}useSession()
Access the raw session data:
import { useSession } from "@banata-auth/react";
function SessionInfo() {
const { session, isLoading } = useSession();
if (!session) return null;
return <span>Session expires: {session.expiresAt}</span>;
}useOrganization()
Get the active organization:
import { useOrganization } from "@banata-auth/react";
function OrgHeader() {
const { organization, isLoading } = useOrganization();
if (!organization) return <span>No organization selected</span>;
return <h2>{organization.name}</h2>;
}useBanataAuth()
Access the full auth context:
import { useBanataAuth } from "@banata-auth/react";
const { user, session, organization, isLoading } = useBanataAuth();Organization Client Plugin
If your app uses organizations with custom roles, add the organizationClient plugin to support your project's role catalog:
import { createAuthClient, organizationClient } from "@banata-auth/react/plugins";
export const authClient = createAuthClient({
baseURL: "/api/auth",
plugins: [organizationClient()],
});This lets you use authClient.organization.* methods for creating organizations, managing members, sending invitations, and switching the active organization.
Convex Bridge
If your app uses Convex for data alongside Banata for auth, use BanataConvexProvider to bridge auth tokens into your Convex client:
import { BanataConvexProvider } from "@banata-auth/react/convex";This is a frontend integration detail — it passes the Banata auth token to Convex so your Convex queries can verify the user's identity.
Next Steps
- Next.js Integration — Server-side auth helpers
- SDK Reference — Programmatic access to Banata
- Organizations — Multi-tenant workspaces
- Roles & Permissions — Access control within organizations