Fix: Explicitly cast jwt.payload to Map<String, dynamic> in HasApiTokens#206
Merged
javad-zobeidi merged 2 commits intovania-dart:devfrom Oct 30, 2025
Merged
Conversation
Resolved type safety issue where jwt.payload was assumed to be a Map<String, dynamic>. In Dart 3.4+, implicit downcasting is disallowed, causing compile-time errors. - Added runtime type check for jwt.payload - Safely cast payload before accessing fields - Throw clear exception if payload is not a Map<String, dynamic> Closes vania-dart#201
…g-issue-from-object
javad-zobeidi
approved these changes
Oct 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves Issue #201, where
jwt.payloadwas incorrectly assumed to be aMap<String, dynamic>. In Dart SDK ≥3.4, implicit down casting fromObjecttoMapis no longer allowed, causing compile-time errors.Details of the Fix
• Added a runtime type check for
jwt.payload.• If the payload is not a
Map<String, dynamic>, an exception is thrown with a clear error message.• Safely cast the payload before accessing its fields.
• Ensures compatibility with Dart’s stricter type system.
Impact
• No breaking changes to public APIs.
• Safer and more reliable JWT validation logic.
• Developers using Dart 3.4+ can now run Vania projects without type errors.