workos-authkit-vanilla-js
Original:🇺🇸 English
Not Translated
Integrate WorkOS AuthKit with vanilla JavaScript applications. No framework required, browser-only. Use when project is plain HTML/JS, doesn't use React/Vue/etc, or mentions vanilla JavaScript authentication.
1installs
Sourceworkos/skills
Added on
NPX Install
npx skill4agent add workos/skills workos-authkit-vanilla-jsSKILL.md Content
WorkOS AuthKit for Vanilla JavaScript
Decision Tree
Step 1: Fetch README (BLOCKING)
WebFetch:
https://github.com/workos/authkit-js/blob/main/README.mdREADME 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()javascript
// 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
- called with
createClient()await - 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: or custom
REACT_APP_WORKOS_CLIENT_ID - No needed (client-side SDK)
WORKOS_API_KEY
Error Recovery
| Error | Cause | Fix |
|---|---|---|
| CDN not loaded | Add script to |
| Wrong import | npm: check import path; CDN: use |
| Undefined env var | Check env prefix matches build tool |
| CORS errors | | Use local dev server ( |
| Popup blocked | Not user gesture | Call |
| 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