workos-authkit-vanilla-js
WorkOS AuthKit for Vanilla JavaScript
Decision Tree
Step 1: Fetch README (BLOCKING)
WebFetch: https://github.com/workos/authkit-js/blob/main/README.md
README is source of truth. If this skill conflicts, follow README.
Step 2: Detect Project Type
Has package.json with build tool (Vite, webpack, Parcel)?
YES -> Bundled project (npm install)
NO -> CDN/Static project (script tag)
Step 3: Follow README Installation
- Bundled: Use package manager install from README
- CDN: Use unpkg script tag from README
Step 4: Implement Per README
Follow README examples for:
- Client initialization
- Sign in/out handlers
- User state management
Critical API Quirk
createClient() is async - returns a Promise, not a client directly.
// CORRECT
const authkit = await createClient(clientId);
Verification Checklist
- README fetched and read before writing code
- Project type detected (bundled vs CDN)
- SDK installed/script added
-
createClient()called withawait - Client ID provided (env var or hardcoded)
- Sign in called from user gesture (click handler)
- No console errors on page load
- Auth UI updates on sign in/out
Environment Variables
Bundled projects only:
- Vite:
VITE_WORKOS_CLIENT_ID - Webpack:
REACT_APP_WORKOS_CLIENT_IDor custom - No
WORKOS_API_KEYneeded (client-side SDK)
Error Recovery
| Error | Cause | Fix |
|---|---|---|
WorkOS is not defined |
CDN not loaded | Add script to <head> before your code |
createClient is not a function |
Wrong import | npm: check import path; CDN: use WorkOS.createClient |
clientId is required |
Undefined env var | Check env prefix matches build tool |
| CORS errors | file:// protocol |
Use local dev server (npx serve) |
| Popup blocked | Not user gesture | Call signIn() only from click handler |
| Auth state lost | Token not persisted | Check localStorage in dev tools |
Task Flow
- preflight: Fetch README, detect project type, verify env vars
- install: Add SDK per project type
- callback: SDK handles internally (no server route needed)
- provider: Initialize client with
await createClient() - ui: Add auth buttons and state display
- verify: Build (if bundled), check console
More from workos/skills
workos
Use when the user asks for a WorkOS docs URL, term, or dashboard field (Sign-in endpoint, initiate_login_uri, Redirect URI, `WORKOS_*` env vars), or is implementing, debugging, or migrating WorkOS — AuthKit, SSO/SAML, Directory Sync, RBAC, FGA, MFA, Vault, Audit Logs, Admin Portal, Pipes (Connected Apps), Feature Flags, Radar (bot/fraud detection), webhooks, Custom Domains, or migrating from Auth0, Clerk, Cognito, Firebase, Supabase, Stytch, Descope, or Better Auth. Also triggers on @workos-inc/* imports.
593workos-widgets
Use when the user is implementing, embedding, or debugging a WorkOS Widget — specifically the User Management, User Profile, Admin Portal SSO Connection, or Admin Portal Domain Verification widgets. Handles the full stack — detecting the frontend (Next.js, React, React Router, TanStack Start, Vite, SvelteKit), generating access tokens via the backend SDK in use (Node, Python, Go, Ruby, PHP, Java, .NET), and wiring up the widget component correctly per the bundled OpenAPI spec. Also use when code imports from @workos-inc/widgets or the user pastes <UserManagement /> or <UserProfile /> JSX.
269workos-authkit-nextjs
Integrate WorkOS AuthKit with Next.js App Router (13+). Server-side rendering required.
64workos-authkit-base
Architectural reference for WorkOS AuthKit integrations. Fetch README first for implementation details.
42workos-authkit-react
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.
33workos-authkit-tanstack-start
Integrate WorkOS AuthKit with TanStack Start applications. Full-stack TypeScript with server functions. Use when project uses TanStack Start, @tanstack/start, or vinxi.
28