workos-authkit-react
Original:🇺🇸 English
Translated
Integrate WorkOS AuthKit with React single-page applications. Client-side only authentication. Use when the project is a React SPA without Next.js or React Router.
3installs
Sourceworkos/skills
Added on
NPX Install
npx skill4agent add workos/skills workos-authkit-reactTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →WorkOS AuthKit for React (SPA)
Decision Tree
START
│
├─► Fetch README (BLOCKING)
│ github.com/workos/authkit-react/blob/main/README.md
│ README is source of truth. Stop if fetch fails.
│
├─► Detect Build Tool
│ ├─ vite.config.ts exists? → Vite
│ └─ otherwise → Create React App
│
├─► Set Env Var Prefix
│ ├─ Vite → VITE_WORKOS_CLIENT_ID
│ └─ CRA → REACT_APP_WORKOS_CLIENT_ID
│
└─► Implement per READMECritical: Build Tool Detection
| Marker File | Build Tool | Env Prefix | Access Pattern |
|---|---|---|---|
| Vite | | |
| CRA | | |
Wrong prefix = undefined values at runtime. This is the #1 integration failure.
Key Clarification: No Callback Route
The React SDK handles OAuth callbacks internally via AuthKitProvider.
- No server-side callback route needed
- SDK intercepts redirect URI client-side
- Token exchange happens automatically
Just ensure redirect URI env var matches WorkOS Dashboard exactly.
Required Environment Variables
{PREFIX}WORKOS_CLIENT_ID=client_...
{PREFIX}WORKOS_REDIRECT_URI=http://localhost:5173/callbackNo needed. Client-side only SDK.
WORKOS_API_KEYVerification Checklist
- README fetched and read
- Build tool detected correctly
- Env var prefix matches build tool
- or
.envhas required vars.env.local - No dependency (wrong skill)
next - No dependency (wrong skill)
react-router - AuthKitProvider wraps app root
- exits 0
pnpm build
Error Recovery
"clientId is required"
Cause: Env var inaccessible (wrong prefix)
Check: Does prefix match build tool? Vite needs , CRA needs .
VITE_REACT_APP_Auth state lost on refresh
Cause: Token persistence issue
Check: Browser dev tools → Application → Local Storage. SDK stores tokens here automatically.
useAuth returns undefined
Cause: Component outside provider tree
Check: Entry file ( or ) wraps in .
main.tsxindex.tsx<App /><AuthKitProvider>Callback redirect fails
Cause: URI mismatch
Check: Env var redirect URI exactly matches WorkOS Dashboard → Redirects configuration.