# Add User Registration to a CodeIgniter App

Yes. An agent installs CodeIgniter Shield in your CodeIgniter 4 app, runs shield:setup, wires register and login, migrates, writes feature tests, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-user-registration/codeigniter/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the starter before it adds accounts to it. In an app laid out like codeigniter4/appstarter, `composer.json` requires PHP `^8.2` and `codeigniter4/framework ^4.7`, with PHPUnit `^10.5`, Faker and vfsStream for development, and maps `App\` to `app/` and `Config\` to `app/Config/`. `app/Config/Routes.php` holds one route, `/` to `Home::index`, which renders `welcome_message`. `app/Config/Filters.php` has the `csrf`, `honeypot` and `secureheaders` aliases but lists them commented out under `$globals`. `app/Config/Database.php` points `default` at MySQLi with empty credentials and defines a `tests` group on SQLite3 `:memory:` with the `db_` prefix; `app/Config/Email.php` has an empty `fromEmail` and the `mail` protocol; `app/Config/Session.php` uses the file handler. `app/Database/Migrations` holds only a `.gitkeep`. `phpunit.dist.xml` boots from the framework's `system/Test/bootstrap.php` and runs `./tests`, where `HealthTest`, an example database test and an example session test live beside `tests/_support` with a sample migration and seeder. `.github/workflows/phpunit.yml` runs PHPUnit on PHP 8.2 and 8.5 with the `sqlite3` extension installed.

Registration comes from Shield, the framework's own authentication package. The agent runs `composer require codeigniter4/shield` (v1.4.1 when this page was written, which requires `codeigniter4/settings`), then `php spark shield:setup`, which the install guide says performs the manual steps: it copies `Auth.php`, `AuthGroups.php` and `AuthToken.php` into `app/Config` extending Shield's classes, adds the `auth` and `setting` helpers to `Autoload.php`, puts `service('auth')->routes($routes)` in `Routes.php`, sets `Config\Security::$csrfProtection` to `session`, asks for the email settings, and runs `php spark migrate --all`. Those routes are the ones `Config\AuthRoutes` defines: `register` and `login` as GET and POST pairs, `logout`, `magic-link` and the `auth-actions` pages. The agent fills `fromEmail` and `fromName` in `Email.php`, points the `.env` database block at the project's database, and leaves `Config\Auth::$allowRegistration` at its default of `true` and `$minimumPasswordLength` at 8.

The app-specific part is the surface around those routes. Because Shield's own `register` view posts a form, the agent turns on `csrf` in `$globals['before']`. It overrides `$views['register']` and `$views['login']` in `app/Config/Auth.php` with views under `app/Views/auth/` that extend a new `app/Views/layouts/default.php`, keeping the field names Shield's controller validates (`email`, `username`, `password`, `password_confirm`) and the `url_to('register')` action. It adds a `/dashboard` route guarded with the `session` filter, a nav that reads `auth()->loggedIn()` and the logout form, and leaves `$actions['register']` at `null` so no activation email is sent until the team has a real transport configured; the pull request says what to set for email activation. The install guide's note about `Class "SQLite3" not found` during `migrate --all` is handled by keeping the sample migration under `tests/_support` out of the default namespace run.

Tests use the framework's own traits: `tests/feature/RegisterTest.php` with `FeatureTestTrait` and `DatabaseTestTrait`, `$migrate = true` and `$namespace = null` so Shield's migrations run against the `tests` SQLite group, posts to `register` with a valid email, username and matching passwords and asserts a redirect to `/`, one row in `users` and one `email_password` identity in `auth_identities`; a second test posts a seven-character password and asserts the validation error; a third signs in through `login` and reaches `/dashboard`. `vendor/bin/phpunit` passes locally and on the existing workflow, since `sqlite3` is already in its extension list.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add user registration and login to this CodeIgniter 4 app with CodeIgniter Shield. Read composer.json, app/Config/Routes.php, app/Config/Filters.php, app/Config/Database.php, app/Config/Email.php, app/Config/Autoload.php, app/Config/Security.php, phpunit.dist.xml, the tests directory and the workflow under .github first. Run composer require codeigniter4/shield and php spark shield:setup, set fromEmail and fromName in app/Config/Email.php, and keep allowRegistration and minimumPasswordLength at Shield's defaults. Enable the csrf filter globally. Override the register and login views with views under app/Views/auth that extend a new app/Views/layouts/default.php and keep Shield's field names and form action. Add a /dashboard route behind the session filter with a nav showing the signed-in user and a logout form. Leave the register action at null and say in the pull request how to enable email activation. Write feature tests with FeatureTestTrait and DatabaseTestTrait against the tests database group for a successful registration, a too-short password, and login reaching the dashboard. Run vendor/bin/phpunit and open a pull request that lists the routes Shield registered and quotes the test output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes `composer.json` and `composer.lock`, `app/Config/Routes.php`, `Filters.php`, `Autoload.php`, `Security.php` and `Email.php`, adds `app/Config/Auth.php`, `AuthGroups.php` and `AuthToken.php`, the layout and two auth views, a dashboard view and controller, and `tests/feature/RegisterTest.php`. Its description lists the routes `service('auth')->routes()` registered, shows the three tests passing, and states that activation is off and what `$actions['register']` to set to turn it on.

A reviewer runs `php spark migrate --all` against a local database and signs up through the new form, then reads `app/Config/Auth.php` for the settings that matter to them: whether usernames are required, which fields `$validFields` allows for login, the password validators, and where `$redirects` send a new user. They check `Filters.php` to confirm CSRF is on for every POST now that there are forms, and that the `session` filter guards `/dashboard` and nothing else yet.

Shield's tables, views and routes are the package's own, so upgrades come from Composer; the app owns only its layout, its views and its tests.

## Run it on every new CodeIgniter project

A studio that starts client projects from the app starter sends this body once per repository from its own server, each `POST /o/{org}/sessions` naming that repository in `resources` with a `request_id` that is a UUID v5 of the repository name, so a retried call returns the run already started. Each run reads the project's own `Database.php` and `Email.php` and writes the pull request against what it finds.

An automation on the Project with a `linear` trigger on `linear.issue.labeled` and the label `auth` starts one run per follow-up, such as email activation, a password reset page or a user group. The trigger adds the issue after the prompt and fills in no placeholder, so the prompt tells the agent to read the request from the issue and to work through Shield's `$actions`, groups and filters rather than adding a second authentication path.

## Why run it on Rush?

Shield's setup command does the mechanical part, and the rest is judgement: which filters to turn on now that there are forms, how to keep the package's views out of the app's layout without breaking its field names, and how to run its migrations in the in-memory test database so the suite stays green on the workflow. The agent makes those choices against the real app in its own sandbox and shows the test output in the pull request.

A reviewer reads a config, three views and three tests. An agency with many CodeIgniter sites starts the same request across all of them at once and gets one pull request per site, each against that site's database and email settings.

## Frequently asked questions

### Why Shield rather than a hand-written users table?

Shield is the framework's own authentication package: its `shield:setup` command wires the config, routes, helpers, CSRF setting and migrations in one step, and its session authenticator, password validators, groups and token support are maintained with the framework. A hand-written table would reimplement the part that is easiest to get wrong.

### Does registration send an activation email?

Not in this pull request. `$actions['register']` stays `null` because the starter's `Email.php` has no transport configured. The description names the action class to set once SMTP details exist, and the agent fills in `fromEmail` and `fromName` so that step is a one-line change.

### Which database does it need?

Any Shield supports; the install guide notes MySQL needs InnoDB. The tests run against the `tests` group the starter already defines on SQLite3 in memory, with `DatabaseTestTrait` running Shield's migrations, so the workflow needs no database service.

### Can I use my own registration form?

Yes. The agent already overrides `$views['register']` and `$views['login']` with views under `app/Views/auth` that extend the new layout; keep Shield's field names and `url_to('register')` and change anything else.

### What about the existing example tests?

They keep running. The sample migration under `tests/_support` stays where it is, and the new feature tests run the Shield migrations through the test trait rather than the global migrate command, which is also how the agent avoids the SQLite error the install guide warns about.

## More CodeIgniter jobs

- [Write PHPUnit Tests for a CodeIgniter 4 App](https://getrush.ai/run/write-phpunit-tests/codeigniter/)
- [Add CORS to a CodeIgniter 4 API](https://getrush.ai/run/add-cors/codeigniter/)
- [Add CSRF Protection to a CodeIgniter 4 App](https://getrush.ai/run/add-csrf-protection/codeigniter/)

## The same job on other stacks

- [Add User Registration to a Fastify App](https://getrush.ai/run/add-user-registration/fastify/)
- [Add User Registration to a Symfony App from a Linear Issue](https://getrush.ai/run/add-user-registration/symfony/)
- [Add User Registration to a Vapor App](https://getrush.ai/run/add-user-registration/vapor/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
