Skip to content

Fix: Explicitly cast jwt.payload to Map<String, dynamic> in HasApiTokens#206

Merged
javad-zobeidi merged 2 commits intovania-dart:devfrom
mahdiyarz:fix/operator-defining-issue-from-object
Oct 30, 2025
Merged

Fix: Explicitly cast jwt.payload to Map<String, dynamic> in HasApiTokens#206
javad-zobeidi merged 2 commits intovania-dart:devfrom
mahdiyarz:fix/operator-defining-issue-from-object

Conversation

@mahdiyarz
Copy link
Copy Markdown
Contributor

Summary

This PR resolves Issue #201, where jwt.payload was incorrectly assumed to be a Map<String, dynamic>. In Dart SDK ≥3.4, implicit down casting from Object to Map is 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.

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
@javad-zobeidi javad-zobeidi merged commit 26f0b7e into vania-dart:dev Oct 30, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants