React quickstart
Add KolayLogin to any React app (Vite, CRA, Remix, RedwoodJS) — a single provider plus hooks, no middleware required.
Copy this quickstart guide as a prompt for LLMs to implement KolayLogin in your application.
1. Install
npm install @kolaylogin/react2. Wrap your app
src/main.tsx
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { KolayLoginProvider } from '@kolaylogin/react';
import App from './App';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<KolayLoginProvider baseUrl={"https://api.kolaylogin.com"}>
<App />
</KolayLoginProvider>
</StrictMode>,
);3. Use hooks and components
import { SignedIn, SignedOut, useUser, useAuth, SignOutButton } from '@kolaylogin/react';
export default function App() {
const auth = useAuth();
const { isLoaded, user } = useUser();
return (
<>
<SignedIn>
{isLoaded ? (
<div>
<h1>Hi, {user?.firstName ?? user?.email ?? 'friend'}!</h1>
<small>session {auth.sessionId}</small>
<SignOutButton redirectUrl="/" />
</div>
) : (
<p>Loading…</p>
)}
</SignedIn>
<SignedOut>
<a href="/sign-in">Sign in</a>
</SignedOut>
</>
);
}4. Cross-origin cookies
If your React app and the KolayLogin API are on different domains, the instance API must run with KL_COOKIE_SECURE=true, your CORS origins must include your app, and every fetch must carry credentials: "include". @kolaylogin/react does that automatically for its own calls; for your own fetches, pass it.
Refresh is automatic
The provider schedules a
POST /v1/auth/sessions/refresh a few seconds before __session's JWT expires (60s TTL by default). You can disable with <KolayLoginProvider autoRefresh={false}> if you want to run the timer yourself.