Skip to content

[Bug]: Incorrect relative time displayed for recent logins (Timezone mismatch) #63

@pankaj-bind

Description

@pankaj-bind

Description:
There is a bug in how login times and session durations are being displayed. When a user logs in, the active sessions/login history UI shows the login time incorrectly (e.g., displaying "about 15 hours ago" or an incorrect AM/PM time for a login that just happened). This seems to be a timezone handling issue between the backend and frontend.

Current Behavior:
Immediately after a fresh login, the UI displays a drastically incorrect relative time instead of "Just now" or "0 minutes ago". (See attached screenshot).

Expected Behavior:
The frontend should correctly parse the timestamp sent by the backend, convert it to the user's local timezone, and display the accurate relative time (e.g., "Just now", "5 minutes ago").

Where to look / Possible Causes:

  • Frontend: Check frontend/src/components/ActiveSessionsList.tsx or similar components where the date formatting happens. Ensure we are correctly parsing UTC ISO strings before calculating the relative time.
  • Backend: Check how timestamps are generated and serialized for UserSession or LoginRecord in Django. Ensure timezone.now() is being used and serialized properly in ISO 8601 format with timezone awareness (Z or offset).
  • Hint: We might need to use a library like date-fns (e.g., formatDistanceToNow) on the frontend, ensuring the parsed date is timezone-aware.

Steps to Reproduce:

  1. Log into the application.
  2. Go to the dashboard or settings page where Active Sessions or Login History is displayed.
  3. Observe the "Last active" or login time for the current session.

Screenshots:

Image

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions