Skip to content

Feature: Track User Account Creation and Last Login Timestamps #23

@fred-maina

Description

@fred-maina

Description

Currently, the User entity lacks fields to track when an account was created (createdAt) and when the user last logged in (lastLoginAt). These are standard audit fields that are essential for user management, analytics, and security (e.g., identifying inactive accounts).

Acceptance Criteria

  1. Modify User.java:
    • Add a createdAt field of type Instant (or LocalDateTime).
    • Add a lastLoginAt field of type Instant (or LocalDateTime).
    • Use JPA annotations like @CreationTimestamp for createdAt to handle it automatically.
  2. Create a Flyway migration (V8):
    • Add the new columns to the users table.
    • created_at should be NOT NULL (you may need to set a default value for existing records, e.g., NOW()).
    • last_login_at can be NULL.
  3. Update AuthService:
    • In the login method, after a successful password check, update the user's lastLoginAt timestamp and save the user.
    • In handleGoogleOAuth, when an existing user logs in, update their lastLoginAt. When a new user is created via OAuth, ensure createdAt is set (if not handled by @CreationTimestamp) and lastLoginAt is also set.
  4. Update UserDto: Include these new fields so they can be returned in API responses (like /api/auth/me).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions