Skip to content

fix(auth): OAuth GET callback crashes on Express 5 (req.body undefined) #3492

@PierreBrisorgueil

Description

@PierreBrisorgueil

Symptom

After enabling Google OAuth on a downstream project (trawl), hitting the callback URL returns:

```
{"message":"Cannot read properties of undefined (reading 'strategy')"}
```

URL: `GET /api/auth/google/callback?code=...&scope=...&state=...`

Root cause

`modules/auth/controllers/auth.controller.js:345`

```js
if (req.body.strategy === false && req.body.key) {
```

Express 5 (we're on `^5.2.1`) leaves `req.body` as `undefined` when no body-parser middleware has processed the request. GET callbacks from Google have no body → `req.body.strategy` throws before reaching `passport.authenticate()`.

Express 4 used to initialize `req.body` to `{}`; Express 5 removed this.

Impact

  • Blocks Google OAuth entirely. Every signin attempt throws.
  • Does NOT affect Apple (Apple uses POST `form_post` response mode → body populated).

Fix

Optional-chain the body access:

```js
if (req.body?.strategy === false && req.body?.key) {
```

1 line. Also add `ERRORS.md` entry documenting the Express 5 `req.body` regression pattern.

Tests

Existing `auth.integration.tests.js` exercises POST callback (line 569). Add a GET callback test to prevent regression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions