Express: API call to /login only works with no cookie present

I get back what I expect (a user object) but only on the first request after deleting a cookie.

Otherwise I get this:

error: operator does not exist: integer = text
    at Parser.parseErrorMessage (/home/owner/cp/voip_call_track_backend/node_modules/pg-protocol/dist/parser.js:278:15)
    at Parser.handlePacket (/home/owner/cp/voip_call_track_backend/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/home/owner/cp/voip_call_track_backend/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/home/owner/cp/voip_call_track_backend/node_modules/pg-protocol/dist/index.js:8:42)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:302:12)
    at readableAddChunk (_stream_readable.js:278:9)
    at Socket.Readable.push (_stream_readable.js:217:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

This makes me think the de/serialization steps are the issue.

The error seems to indicate an integer is being compared to text (or varchar).

But as you can see, I’m type casting the id (the only int column) to text during the deserial query :

// server.ts
passport.serializeUser((user: any, callback) => {

passport.deserializeUser(async (userId, callback) => {
  const pgClient = new PgClient();
  try {
    const userRecord = (await pgClient.query('SELECT * FROM app_user WHERE id = $1::text', [userId])).rows[0];
    callback(null, userRecord);
  } catch (error) {

Anyone know what the issue could be?

Here is the cookie itself. As noted if I delete it, the next request will return a successful response.

connect.sid=s%3AOpGFbWt6zvBnie33-Mmz2D6nwRNsEgHB.uWEp49W0DhvdUKVmslAoyA4Psk0aZjJNmskjhEbRUwE; Path=/; Domain=localhost; HttpOnly;

Solved in the deserialize method by casting the userId to text:

    const userRecord = (await pgClient.query('SELECT * FROM app_user WHERE CAST(id as text) = $1::text', [userId.toString()])).rows[0];