ReactCLI
init
Create the base SimpleAuth client, provider, barrel file, and useCurrentUser hook in your project.
Synopsis
npx @simpleauthjs/react init [flags]What it writes
The command materializes these paths relative to the target project. The authoritative list is BASE_FILE_OPS in packages/simpleauth-react/src/generators/registry.ts in this repository:
components/simpleauth/client.ts—getSimpleAuthClient()using your public env vars.components/simpleauth/provider.tsx—SimpleAuthProvideranduseSimpleAuthClient.components/simpleauth/index.ts— barrel exports updated by lateraddruns.components/simpleauth/hooks/use-current-user.ts—useCurrentUser.
Flags
| Name | Alias | Type | Default | Description |
|---|---|---|---|---|
--cwd | — | string | Current working directory | Project root to write into. |
--force | — | boolean | false | Overwrite existing SimpleAuth files if they already exist. |
--yes | — | boolean | false | Reserved for non-interactive defaults (currently equivalent to running without prompts). |
--api-key-env | — | string | Auto from framework | Name of the env var holding your public API key. |
--no-install | — | boolean | false | Skip installing @simpleauthjs/core when it is missing. |
Framework detection
The CLI reads package.json dependencies. If next is present, Next defaults apply; otherwise if react is present, Vite-style defaults apply.
| Framework | Public key variable | Env file hint |
|---|---|---|
| Next.js | NEXT_PUBLIC_SIMPLEAUTH_PUBLIC_KEY | .env.local |
| Vite / React | VITE_SIMPLEAUTH_PUBLIC_KEY | .env |
The generated getSimpleAuthClient() uses the hosted API at https://simpleauth.net by default (via @simpleauthjs/core).
Troubleshooting
- "Found existing files" — Remove the old files or re-run with
--forceto replace them. - "No package.json found" — Run the command from your app root (or pass
--cwd). - "Remember to install @simpleauthjs/core" — You passed
--no-install; add the dependency yourself before importing generated code.