Skip to content

Conversation

felixschmetz
Copy link
Collaborator

@felixschmetz felixschmetz commented Oct 21, 2025

Adds "Last Seen" tracking for users and displays it in the admin dashboard with sorting capability. Shows the most recent login timestamp across all users in each organization.

Backend

  • User Model (models/user.py): Added last_active_at timestamp field
  • User Schema (schemas/user.py): Added last_active_at to schema
  • Database Migration: Created migration to add last_active_at column to user table
  • Authentication (api/deps.py): Updates last_active_at on every Auth0 login
  • Admin Endpoint (api/v1/endpoints/admin.py):
    • Added query to fetch max last_active_at per organization
    • Added support for sorting by last_active_at
    • Included last_active_at in OrganizationMetrics response
  • Admin Schema (schemas/admin.py): Added last_active_at field to OrganizationMetrics

Frontend

  • Admin Dashboard (pages/AdminDashboard.tsx):
    • Added "Last Login" sortable column
    • Displays formatted timestamp or "—" for never-logged-in orgs
    • Added last_active_at to TypeScript types

Notes

  • Existing users will have NULL last_active_at until they log in again. Shows up on dashboard as "-"
  • Timestamp is updated only for Auth0 authentication (not API key auth)
  • Shows the most recent activity across all users in an organization
Screenshot 2025-10-21 at 17 01 06

Summary by cubic

Adds last login tracking and a sortable “Last Login” column to the admin dashboard to surface recent activity per organization. Admins can now quickly see and sort by the most recent user login across orgs.

  • New Features

    • Backend: Added last_active_at to User model/schema; updates on every Auth0 login.
    • Admin API: Returns max last_active_at per organization and supports sorting by it.
    • Frontend: New “Last Active” column with sorting; shows a formatted timestamp or “—” if none.
    • Behavior: Existing users show “—” until their next Auth0 login; API key auth does not update last_active_at.
  • Migration

    • Run Alembic upgrade to add the last_active_at column to the user table.

@felixschmetz felixschmetz changed the title feat: Add last login tracking and sorting to admin dashboard feat: Add "last seen" tracking and sorting to admin dashboard Oct 21, 2025
# Update last login timestamp
user.last_login_at = datetime.utcnow()
await db.commit()
await db.refresh(user)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to use crud module for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you too fast man. checking now, BTW i'm renaming this to last_active_at.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW what's the gain in using the crud layer here rather than the direct approach? every request is gonna go through this and as far as i'm concerned the crud layer has permission checks that don't necessarily apply to this use case?

TBF the overhead is minimal so idc, just wanted to check if there's a reason other than consistency.

@felixschmetz felixschmetz changed the title feat: Add "last seen" tracking and sorting to admin dashboard feat: Add "last active" tracking and sorting to admin dashboard Oct 21, 2025
@felixschmetz felixschmetz force-pushed the feat/introduce_last_login branch from 2bcb4a6 to f4f307e Compare October 21, 2025 15:19
@orhanrauf
Copy link
Contributor

lgtm!

@orhanrauf orhanrauf merged commit 4b2f926 into main Oct 21, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants