CLI Reference
Complete Keyloom CLI command reference, interactive flow, package detection, file generation, and troubleshooting.
CLI Reference
The Keyloom CLI provides an interactive setup wizard to initialize authentication in your app with sensible defaults.
Prerequisites
- Node.js 18+ with npm, pnpm, or yarn
- Existing Next.js, React, or Node.js project
- Terminal access for interactive prompts
Installation and usage
# Run directly (recommended)
npx keyloom init
pnpm dlx keyloom init
yarn dlx keyloom init
# Or install globally
npm install -g @keyloom/cli
keyloom initCommand reference
keyloom init
Initialize Keyloom in your project with interactive prompts.
Flags:
--no-install- Skip installing dependencies--force- Overwrite existing files without prompting--providers=<list>- Preconfigure providers (comma-separated)--adapter=<type>- Choose adapter:prisma,drizzle,memory--strategy=<type>- Session strategy:jwt,database--help- Show help information--version- Show CLI version
Examples:
# Interactive setup (recommended)
npx keyloom init
# Skip dependency installation
npx keyloom init --no-install
# Preconfigure with GitHub and Google
npx keyloom init --providers=github,google --adapter=prisma
# Force overwrite existing files
npx keyloom init --forceInteractive flow breakdown
The CLI walks through these steps:
1. Framework detection
✔ Detected Next.js 15 (App Router)
✔ Package manager: pnpmSupports:
- Next.js (App Router, Pages Router)
- React (Vite, Create React App)
- Node.js (Express, Fastify)
2. Configuration generation
✔ Created keyloom.config.tsGenerates a base config with:
- Detected framework settings
- Memory adapter (development default)
- JWT session strategy
- Empty providers array
3. Framework integration
? Add Next.js middleware and route handler? (Y/n) › Yes
✔ Created middleware.ts
✔ Created app/api/auth/[...keyloom]/route.tsFor Next.js:
middleware.ts- Route protectionapp/api/auth/[...keyloom]/route.ts- Auth endpoints
4. Dependency installation
? Install @keyloom/core and @keyloom/nextjs? (Y/n) › Yes
✔ Installing dependencies...Installs based on selections:
- Core packages:
@keyloom/core - Framework packages:
@keyloom/nextjs,@keyloom/react - Providers:
@keyloom/providers(if selected) - Adapters:
@keyloom/adapter-prisma,@keyloom/adapter-drizzle
5. Provider configuration
? Add OAuth providers? (Y/n) › Yes
? Select providers: (Use space to select)
❯◉ GitHub
◉ Google
◯ Apple
◯ MicrosoftAdds provider imports and configuration to keyloom.config.ts.
6. Session strategy
? Choose session strategy: (Use arrow keys)
❯ JWT (stateless, edge-friendly)
Database (stateful, requires adapter)Updates config with selected strategy and TTL settings.
7. Adapter selection (if database strategy)
? Choose database adapter: (Use arrow keys)
❯ Prisma
Drizzle
CustomAdds adapter configuration and optionally generates schema files.
Generated files
keyloom.config.ts
import { defineKeyloom } from "@keyloom/core";
import { github, google } from "@keyloom/providers";
export default defineKeyloom({
baseUrl: process.env.NEXT_PUBLIC_APP_URL!,
session: { strategy: "jwt", ttlMinutes: 60 },
providers: [
github({
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
}),
],
secrets: { authSecret: process.env.AUTH_SECRET! },
});middleware.ts (Next.js)
import { withKeyloom } from "@keyloom/nextjs/middleware";
export default withKeyloom({
publicRoutes: ["/", "/about"],
});
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};app/api/auth/[...keyloom]/route.ts (Next.js App Router)
import { createHandler } from "@keyloom/nextjs";
import config from "@/keyloom.config";
const handler = createHandler(config);
export { handler as GET, handler as POST };Package manager detection
The CLI detects your package manager:
- pnpm: Looks for
pnpm-lock.yaml - yarn: Looks for
yarn.lock - npm: Default fallback
Uses the detected manager for:
- Installing dependencies
- Running scripts
- Lock file updates
Framework detection
Detection logic:
-
Next.js: Checks for
nextin dependencies- App Router:
app/directory exists - Pages Router:
pages/directory exists
- App Router:
-
React: Checks for
reactin dependencies- Vite:
vite.config.*exists - CRA:
react-scriptsin dependencies
- Vite:
-
Node.js: Fallback for server-only projects
Error handling and troubleshooting
Common issues
Permission errors
Error: EACCES: permission denied- Run with
sudoon Unix systems - Check file permissions in project directory
Network errors
Error: Failed to install dependencies- Check internet connection
- Try different registry:
npm config set registry https://registry.npmjs.org/
File conflicts
Error: keyloom.config.ts already exists- Use
--forceflag to overwrite - Or manually remove existing files
Framework not detected
Warning: Could not detect framework- Ensure dependencies are installed
- Run
npm installor equivalent first
TypeScript errors
Error: Cannot find module '@keyloom/core'- Run
npm installafter CLI completes - Check
package.jsonfor added dependencies
Debug mode
Enable verbose logging:
DEBUG=keyloom:* npx keyloom initPerformance considerations
- CLI operations are typically fast (< 30 seconds)
- Network-dependent: dependency installation
- File I/O: configuration generation
Security notes
- Generated files contain placeholder environment variables
- Never commit secrets to version control
- Use
.env.localfor sensitive values
See also
- Installation: /docs/getting-started/installation
- Configuration: /docs/core/jwt
- Next.js Integration: /docs/nextjs/overview
Next steps
- Set environment variables in
.env.local - Update
baseUrlinkeyloom.config.ts - Configure OAuth providers with client IDs/secrets
- Test the sign-in flow in development
How is this guide?