Skip to content

Conversation

@tp
Copy link
Contributor

@tp tp commented Sep 17, 2025

  • Since feat!: Mark JWT fields final #68 was rejected, this needs to be enforced for both the constructor and the field setter
  • You'll see that we copy/convert the Maps to Map<String, dynamic>, this has 2 reasons
    • For some literal maps (e.g. in the test cases, but also likely application code), we would get Map<String, String> (for example), so we need to convert those for the doc comments to be correct
    • Given the previous point, I thought it would be confusing if we only converted maps other than the "desired" Map<String, dynamic>, as some would then stay "in sync" with the original map (if it was ever changed) and some would not. (That's why feat!: Mark JWT fields final #68 also made them read-only, to bring any such late modifications to attention and err.)

Closes #67

@tp tp changed the title Document and enfore JWT payload type to be either String or Map<String, dynamic> Document and enforce JWT payload type to be either String or Map<String, dynamic> Sep 17, 2025
@tp tp force-pushed the clarify-payload-type branch from 595289c to 6d95e98 Compare September 17, 2025 07:32
(jsonBase64.decode(base64Padded(parts[1])) as Map<String, dynamic>);

final audiance = _parseAud(payload['aud']);
final issuer = payload['iss']?.toString();
Copy link
Contributor Author

@tp tp Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, any non-Map payload would've failed anyway.

var payload = this.payload;
if (payload is Map<String, dynamic>) {
try {
payload = Map<String, dynamic>.from(payload);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it made sense that this was taking a copy of the map (as it might've been immutable or used again in the previous variant which was not holding it's own copy), but I wonder if the "writing back" to payload was intentional?

Now we don't write back to the JWT object (this) (and the local reference is also needed to get the type checking work properly, as it's now based on Object instead of the "always working" dynamic).

@tp tp force-pushed the clarify-payload-type branch from 6d95e98 to 16c496e Compare September 17, 2025 07:49
@tp tp marked this pull request as ready for review September 17, 2025 07:52
@tp tp requested a review from jonasroussel as a code owner September 17, 2025 07:52
@tp
Copy link
Contributor Author

tp commented Sep 29, 2025

@jonasroussel Thanks for your reviews on these PRs over the last few days.

Is there anything I can/should do now, or will you just wait with the merge until you want to make another release?

@jonasroussel
Copy link
Owner

Thanks to you for your contribution !

If you have nothing more to add, I will merge all the PRs into main and soon make a new release.

@tp
Copy link
Contributor Author

tp commented Oct 1, 2025

@jonasroussel Great. Yes, this would be everything from my side right now.

There were a few more ideas (like an immutable JWT class and possibly using distinct functions for String vs. JWT payloads), but since those are majorly breaking, I did not pursue them after our discussion on the immutable showcase PR.

@jonasroussel jonasroussel merged commit 0bf4424 into jonasroussel:main Oct 1, 2025
2 checks passed
@ahmednfwela
Copy link

@tp @jonasroussel

this was a breaking change that had a minor version pump, leading to other libraries breaking

meilisearch/meilisearch-dart#450

@tp
Copy link
Contributor Author

tp commented Oct 17, 2025

@ahmednfwela Sorry I missed that, even though we explicitly tried to contain the changes… But migrating away from dynamic I didn't think how correct but type-unchecked code could break here (in the samples and our project code we always type-check it as a Map first before accessing it).

Then we might as well go for a fully type-safe route and move away from Object = String or Map as it was in 3.3.0.

meili-bors bot added a commit to meilisearch/meilisearch-dart that referenced this pull request Oct 22, 2025
451: Type casting for JWT claims in tenant token tests r=curquiza a=ahmednfwela

# Pull Request

## Related issue
Fixes #450 

## What does this PR do?
- Fixes a breaking change that was made in jonasroussel/dart_jsonwebtoken#71

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **Tests**
  * Improved type safety when verifying JWT token payloads in the test suite.

* **Chores**
  * Updated development lint dependency constraint to the 6.x release line for dev tooling consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: ahmednfwela <[email protected]>
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.

Type payload as Map<String, dynamic>

3 participants