SimpleAuth
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.tsgetSimpleAuthClient() using your public env vars.
  • components/simpleauth/provider.tsxSimpleAuthProvider and useSimpleAuthClient.
  • components/simpleauth/index.ts — barrel exports updated by later add runs.
  • components/simpleauth/hooks/use-current-user.tsuseCurrentUser.

Flags

NameAliasTypeDefaultDescription
--cwdstringCurrent working directoryProject root to write into.
--forcebooleanfalseOverwrite existing SimpleAuth files if they already exist.
--yesbooleanfalseReserved for non-interactive defaults (currently equivalent to running without prompts).
--api-key-envstringAuto from frameworkName of the env var holding your public API key.
--no-installbooleanfalseSkip 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.

FrameworkPublic key variableEnv file hint
Next.jsNEXT_PUBLIC_SIMPLEAUTH_PUBLIC_KEY.env.local
Vite / ReactVITE_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 --force to 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.

On this page