Skip to content

Track and display user last login date#3325

Open
marcusljf wants to merge 1 commit intomainfrom
last-login
Open

Track and display user last login date#3325
marcusljf wants to merge 1 commit intomainfrom
last-login

Conversation

@marcusljf
Copy link
Collaborator

@marcusljf marcusljf commented Jan 8, 2026

Adds a lastLoginAt field to the User model and updates it on login. The workspace members page now displays the last active date for each user. The zod schema and relevant UI components were updated to support this new field.

  • The field won't populate until the user logs in for the first time after the change.
  • If the user never logs in, will show as -
CleanShot 2026-01-07 at 16 40 11@2x

Summary by CodeRabbit

  • New Features
    • Added a "Last active" column to the member table, displaying when each team member last logged in with formatted timestamps. Invited members without login history show a placeholder. Member table layout adjusted for improved display.

✏️ Tip: You can customize this high-level summary in your review settings.

Adds a lastLoginAt field to the User model and updates it on login. The workspace members page now displays the last active date for each user. The zod schema and relevant UI components were updated to support this new field.
@vercel
Copy link
Contributor

vercel bot commented Jan 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
dub Ready Ready Preview Jan 8, 2026 0:47am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

This pull request introduces last login tracking by adding a lastLoginAt field to the User model, updating it during authentication sign-in, and displaying the timestamp in the dashboard members table with special handling for invited users.

Changes

Cohort / File(s) Summary
Database Schema
packages/prisma/schema/schema.prisma
Added nullable lastLoginAt DateTime field to User model
Validation Schema
apps/web/lib/zod/schemas/workspaces.ts
Added lastLoginAt field (z.date().nullish()) to workspaceUserSchema for type validation
Auth Sign-in Logic
apps/web/lib/auth/options.ts
Integrated background updates to lastLoginAt in two sign-in handler locations using waitUntil for non-blocking async operations
Dashboard UI
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page-client.tsx
Added "Last active" column to members table displaying formatted lastLoginAt date or "-" placeholder for invited users; adjusted Name column width from 870 to 750

Sequence Diagram

sequenceDiagram
    actor User
    participant Client as Web Client
    participant Auth as Auth Handler
    participant DB as Database
    participant UI as Dashboard UI

    User->>Client: Sign in
    Client->>Auth: Submit credentials
    Auth->>DB: Verify user
    DB-->>Auth: User authenticated
    
    rect rgba(76, 175, 80, 0.2)
        Auth->>+DB: Background: Update lastLoginAt
        DB-->>-Auth: Update queued (waitUntil)
    end
    
    Auth-->>Client: Return session
    Client->>DB: Fetch members list
    DB-->>Client: Return members with lastLoginAt
    
    rect rgba(33, 150, 243, 0.2)
        Client->>UI: Render members table
        UI->>UI: Format lastLoginAt or show "-"
        UI-->>User: Display "Last active" column
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

🐰 A login tracked, a timestamp gleamed,
Our dashboard users' presence beamed,
Last active shown, no guessing game,
Now we know when you came!
Hop by hop, we build the dream. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Track and display user last login date' accurately and concisely describes the main changes: adding lastLoginAt field tracking and displaying it on the members page.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page-client.tsx (1)

166-188: Consider internationalization for date formatting.

The "Last active" column implementation correctly handles edge cases (invited users and missing data). However, the date formatting uses a hardcoded "en-US" locale.

🌍 Optional: Support international date formats

Consider using the user's browser locale or a workspace-level locale preference:

           <span className="text-sm text-neutral-500">
-             {new Date(user.lastLoginAt).toLocaleDateString("en-US", {
+             {new Date(user.lastLoginAt).toLocaleDateString(undefined, {
                month: "short",
                day: "numeric",
                year: "numeric",
              })}
           </span>

Passing undefined as the locale uses the user's browser locale automatically.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d82326 and 5fc9394.

📒 Files selected for processing (4)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page-client.tsx
  • apps/web/lib/auth/options.ts
  • apps/web/lib/zod/schemas/workspaces.ts
  • packages/prisma/schema/schema.prisma
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-15T01:05:43.266Z
Learnt from: steven-tey
Repo: dubinc/dub PR: 2958
File: apps/web/app/app.dub.co/(dashboard)/[slug]/settings/members/page-client.tsx:432-457
Timestamp: 2025-10-15T01:05:43.266Z
Learning: In apps/web/app/app.dub.co/(dashboard)/[slug]/settings/members/page-client.tsx, defer refactoring the custom MenuItem component (lines 432-457) to use the shared dub/ui MenuItem component to a future PR, as requested by steven-tey.

Applied to files:

  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page-client.tsx
🧬 Code graph analysis (1)
apps/web/lib/auth/options.ts (1)
packages/prisma/index.ts (1)
  • prisma (3-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (4)
packages/prisma/schema/schema.prisma (1)

24-24: LGTM!

The nullable lastLoginAt field is correctly positioned and typed. The nullable constraint is appropriate since existing users won't have login data until their next authentication.

apps/web/lib/zod/schemas/workspaces.ts (1)

216-216: LGTM!

The schema validation for lastLoginAt correctly uses z.date().nullish() which is the proper Zod 4 syntax for nullable/optional date fields.

apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page-client.tsx (1)

140-140: LGTM!

The column width adjustment accommodates the new "Last active" column appropriately.

apps/web/lib/auth/options.ts (1)

578-585: LGTM!

The background update to lastLoginAt is well-implemented:

  • Uses waitUntil to avoid blocking the sign-in response
  • Correctly placed in the events.signIn handler to capture all authentication flows
  • Captures the timestamp at sign-in time with new Date()

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.

1 participant