How to detect inactive users

Describe the problem/error/question

Hi people,

we want to automatically deactivate inactive users from n8n. Is there a way to do so or to retrieve the last login date of a user? I looked at the users api but this data seems not returned.

Thank you!

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.31.7
  • Database (default: SQLite): PosgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): queue
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux

Hi @Lorenzo_Tacconi1

If you are on an Enterprise plan, you can use Log Streaming to achieve this automation:

  1. Enable Log Streaming: Configure n8n to stream audit events to an external system (e.g., a webhook, a database, or a logging service like Sentry).
  2. Monitor Login Events: Specifically, look for the User login success audit event.
  3. Track Activity: By capturing these events, you can build a simple database or table that records the timestamp of the most recent login for every user ID.
  4. Automate Deactivation: You can then create a workflow in n8n that:
    • Checks your activity database for users who haven’t logged in for $X$ days.
    • Uses the n8n Public API to call DELETE /users/{id} to remove those inactive users.

Hi @Lorenzo_Tacconi1
Both things sit on the user table in your own Postgres, and the public API exposes neither. lastActiveAt is the inactivity signal, and disabled is a real boolean that the auth path and the API key check both honour, which is the same flag n8n’s own LDAP sync flips, so a scheduled workflow reading one and setting the other covers it.
It records last activity rather than last login, as a date stamped to the start of the day and written at most once per day on any authenticated request, so set the threshold in whole days and expect NULL for anyone not seen since the column was added.

Hi @Lorenzo_Tacconi1

The public API can’t do the deactivation. It only does role change and delete for users. And the n8n node? No user resource at all.

So both steps live in the database. One scheduled workflow does it:

  1. Postgres node:
SELECT id, email FROM "user"
WHERE "lastActiveAt" < now() - interval '90 days'
  AND disabled = false;
  1. Second Postgres node with the returned ids:
UPDATE "user" SET disabled = true WHERE id = ANY($1);

Leave the instance owner out of the update, and set the threshold in whole days since lastActiveAt is stamped at most once per day, as described above.