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
- 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.
- 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.
- 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.
- Update
UserDto: Include these new fields so they can be returned in API responses (like /api/auth/me).
Description
Currently, the
Userentity 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
User.java:createdAtfield of typeInstant(orLocalDateTime).lastLoginAtfield of typeInstant(orLocalDateTime).@CreationTimestampforcreatedAtto handle it automatically.userstable.created_atshould beNOT NULL(you may need to set a default value for existing records, e.g.,NOW()).last_login_atcan beNULL.AuthService:loginmethod, after a successful password check, update the user'slastLoginAttimestamp and save the user.handleGoogleOAuth, when an existing user logs in, update theirlastLoginAt. When a new user is created via OAuth, ensurecreatedAtis set (if not handled by@CreationTimestamp) andlastLoginAtis also set.UserDto: Include these new fields so they can be returned in API responses (like/api/auth/me).