arch-atlas

JWT Helper

core/jwtHelper.dart

data

Overview

Pure utility for decoding the JWT payload (no signature verification, since the client only consumes the token) and computing expiry. Used by LoginNotifier on session restore to log whether the cached token is already past its 5-minute pre-expiry window.

User Flow

  1. decodeToken splits the JWT into 3 parts, base64-url decodes the middle segment.
  2. isTokenExpired compares exp * 1000ms against now() minus a 5-minute safety margin.
  3. getTokenExpiry returns the raw DateTime for diagnostic use.

Cases & Edge Cases

  • Malformed JWT (not 3 parts) returns null from decodeToken and is treated as expired by isTokenExpired.
  • Missing exp claim is also treated as expired — the app prefers to force a re-login over trusting a non-expiring token.
  • There is no refresh logic yet — isTokenExpired is logged but not acted upon (LoginNotifier._checkAuthStatus is a TODO).

Code References

  • lib/src/core/jwtHelper.dart:3 // JwtHelper
  • lib/src/features/shared/auth/login/presentation/providers/auth/login_provider.dart:36 // _checkAuthStatus uses isTokenExpired

API Calls

Empty — fill this in later. Open the manifest and add content here.

Notes

Despite the camelCase filename (jwtHelper.dart), the class is JwtHelper. Don't rename without updating every import.