# Add Google Login to an AdonisJS App

Yes. An agent installs Ally with the Google driver, adds redirect and callback routes beside your session login, links accounts by verified email, and opens a PR.

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

## What the agent does

The agent reads how sign-in works today. In an app laid out like the `inertia-react` kit in adonisjs/starter-kits, `package.json` runs `@adonisjs/core` 7.5.2 with `@adonisjs/auth` 10.1.0, `@adonisjs/session` 8.1.0, `@adonisjs/lucid` 22.4.2 on `better-sqlite3`, `@adonisjs/inertia` 5.0.1 with React 19, and `@vinejs/vine` 4.4.0; there is no Ally package. `start/routes.ts` puts `signup` and `login` under `middleware.guest()` and `dashboard` and `logout` under `middleware.auth()`, and resolves controllers through `#generated/controllers`. `SessionController.store` validates with `loginValidator`, calls `User.verifyCredentials` and `auth.use('web').login(user)`; `NewAccountController.store` creates the user and logs them in. `config/auth.ts` defines one `web` session guard with `useRememberMeTokens: false`. The `User` model composes the generated `UserSchema` with `withAuthFinder(hash)`, and the single migration creates `users` with `full_name` nullable, `email` unique and `password` not null. `start/env.ts` validates `APP_URL`, which `.env.example` builds from `HOST` and `PORT`. The login page is `inertia/pages/auth/login.tsx`, a `<Form route="session.store">` with email and password fields.

`@adonisjs/ally` 6.3.2 declares a peer on `@adonisjs/core` 7, so it fits this kit. Its configure step writes `config/ally.ts` from a stub that calls `services.google` with `clientId` and `clientSecret` from `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` and a `callbackUrl` of `${APP_URL}/oauth/google/callback`, and registers both variables in `start/env.ts`; the agent runs it with the `google` provider, checks the generated file against the kit's `env.ts` style, and adds the two keys to `.env.example`. The driver's own documentation shows the two handlers it expects: `ally.use('google').redirect()` to send the browser to Google, and on return `accessDenied()`, `stateMisMatch()` and `hasError()` before `await google.user()`.

A new `OauthController` with `redirect` and `callback` goes under the guest group as `GET /oauth/google/redirect` and `GET /oauth/google/callback`. The callback turns each of the three failure checks into a flashed message and a redirect to `session.create`. On success it reads the Google profile and links it to a local account only when the profile's `emailVerificationState` is `verified`: it finds the user by email, or creates one with `fullName` from the profile, then stores the Google id in a new nullable, unique `google_id` column added by a migration, and calls `auth.use('web').login(user)` followed by a redirect to `dashboard`, the same two calls the password login makes. The migration also makes `password` nullable, since a Google-only account has none, and `SessionController.store` is taught to refuse a password login for such an account with a message pointing at the Google button. `node ace migration:run` regenerates `database/schema.ts`, which the file's header says is the only way to edit it.

The login and signup pages get a `Continue with Google` link to the redirect route, rendered beside the existing form so a user with a password sees no change. Tests use the kit's `node ace test` runner: a request to the redirect route answers with a 302 to Google's authorisation endpoint whose query carries the configured `client_id` and a `state`; a callback with a `state` that does not match the cookie lands on the login page with the mismatch message; a callback with `error=access_denied` does the same with the denied message. The agent also runs `pnpm typecheck`, which checks both the server and the `inertia/` tsconfig, and `pnpm lint`.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add Google login to this AdonisJS Inertia React app with @adonisjs/ally. Read package.json, adonisrc.ts, start/routes.ts, start/kernel.ts, start/env.ts, .env.example, config/auth.ts, app/controllers/session_controller.ts, app/controllers/new_account_controller.ts, app/models/user.ts, app/validators/user.ts, database/schema.ts, the migration under database/migrations, app/middleware/guest_middleware.ts and inertia/pages/auth/login.tsx first. Install @adonisjs/ally with the google provider so config/ally.ts, the env rules and .env.example gain GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET. Add an OauthController with redirect and callback under the guest group at /oauth/google/redirect and /oauth/google/callback; handle accessDenied, stateMisMatch and hasError with a flash and a redirect to the login page; link by email only when the Google profile's email is verified, otherwise create the user; store the Google id in a new nullable unique google_id column and make password nullable in a migration, then run node ace migration:run so database/schema.ts is regenerated. Refuse password login for accounts without a password. Add a Continue with Google link to the login and signup pages. Write node ace test tests for the redirect, a state mismatch and an access denied callback. Run pnpm typecheck, pnpm lint and the tests, and open a pull request that quotes the output and lists the Google Cloud console steps the team must do.",
  "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 adds `config/ally.ts`, `app/controllers/oauth_controller.ts`, a migration and a test file, changes `start/routes.ts`, `start/env.ts`, `.env.example`, `adonisrc.ts` (the Ally provider), `app/controllers/session_controller.ts`, `database/schema.ts`, `inertia/pages/auth/login.tsx` and `signup.tsx`, `package.json` and `pnpm-lock.yaml`. Its description quotes the test, typecheck and lint output and ends with the steps that need a person: creating the OAuth client in the Google Cloud console and registering the callback URL built from `APP_URL`.

A reviewer reads the callback for the two account-takeover paths: linking by an unverified email, which the `emailVerificationState` check refuses, and a Google id already attached to another user, which the unique column refuses. They also check that a signup through Google does not bypass anything the password signup validates, and decide whether `fullName` from Google should overwrite a name the user typed earlier.

No existing route changes its behaviour for a user with a password, and the session guard configuration is untouched.

## Run it on every Linear issue labelled auth

An automation on the Project with a `linear` trigger on `linear.issue.labeled` and the label `auth` starts one read-only run per issue, which reads `config/auth.ts`, the routes and the `User` model and comments on the issue with the files the change touches and the console steps it cannot do. The trigger adds the issue after the prompt and fills in no placeholder.

The branch comes from a run the team's own server starts with this body, the repository in `resources`, the issue URL as a second resource, and a `request_id` that is a UUID v5 of the Linear issue id, so a redelivered webhook returns the run already started rather than opening a second pull request.

## Why run it on Rush?

Social login touches the account model, the session guard, a migration, a generated schema file and two pages at once, and the only honest check is the app's own test runner and type checker on all of it. The agent runs `node ace test`, `pnpm typecheck` and `pnpm lint` in its own sandbox and keeps the output with the pull request, so the reviewer reads the result of the build rather than reconstructing it.

The change follows this kit's conventions: generated controllers, the session guard's `login` call, the regenerated schema. A team with several AdonisJS apps starts the same request on each at once and gets one pull request per app, each written against that app's own auth config.

## Frequently asked questions

### Does this replace the password login?

No. `SessionController` and `NewAccountController` keep working as they are. The only change to them is a refusal when an account has no password, which can only happen for an account created through Google.

### What does the team have to do in Google's console?

Create an OAuth client, set its authorised redirect URI to `${APP_URL}/oauth/google/callback`, and put the client id and secret in `.env`. The pull request lists these steps; the agent cannot do them, because they need the team's Google account.

### How are existing users matched?

By email, and only when Google reports the email as verified. A verified match sets `google_id` on the existing row; an unverified profile is refused with a message, because linking on an unverified email would let anyone claim an account.

### Why make password nullable?

The migration sets `password` not null, and a user who only ever signs in with Google has none. The column becomes nullable and the login handler refuses a password attempt for such a row instead of comparing against nothing.

### Can the tests run without Google credentials?

Yes. The redirect test only inspects the URL the app builds, and the failure tests send the error and state parameters the driver checks before it ever calls Google. The success path needs real credentials and is described in the pull request as a manual check.

## More AdonisJS jobs

- [Add Health Checks to an AdonisJS API](https://getrush.ai/run/add-health-checks/adonisjs/)
- [Add i18n to an AdonisJS App](https://getrush.ai/run/add-i18n/adonisjs/)
- [Add Password Reset to an AdonisJS App](https://getrush.ai/run/add-password-reset/adonisjs/)

## The same job on other stacks

- [Add Google Login to an Express and Mongoose API](https://getrush.ai/run/add-google-login/mongoose/)
- [Add Google Login to a Next.js App with NextAuth.js](https://getrush.ai/run/add-google-login/next-auth/)
- [Add Google Login to an Express App with Passport](https://getrush.ai/run/add-google-login/passport/)

## 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/)
