Skip to content

Fix block crash when Apple Maps credentials are missing.#233

Merged
faisal-alvi merged 5 commits intodevelopfrom
fix/232-Block_crashes_without_apple_maps_credentials
May 19, 2025
Merged

Fix block crash when Apple Maps credentials are missing.#233
faisal-alvi merged 5 commits intodevelopfrom
fix/232-Block_crashes_without_apple_maps_credentials

Conversation

@elvismdev
Copy link
Contributor

@elvismdev elvismdev commented Jan 27, 2025

Description of the Change

This PR fixes the issue where the Apple Maps block would crash when no credentials were configured instead of showing the credentials form.

Key changes:

  • Added proper credentials check before MapKit initialization
  • Ensured block transitions from loading state to credentials form when no credentials exist

Closes #232

How to test the Change

  1. Create a new post
  2. Add the Apple Maps block
  3. Verify that instead of crashing, you see the credentials form with instructions

Changelog Entry

Fixed - Block crash when no Apple Maps credentials are configured, now properly shows credentials form

Credits

Props @elvismdev

Checklist:

@github-actions
Copy link

@elvismdev thanks for the PR! Could you please fill out the PR template with description, changelog, and credits information so that we can properly review and merge this?

@github-actions github-actions bot added needs:feedback This requires reporter feedback to better understand the request. needs:code-review This requires code review. and removed needs:feedback This requires reporter feedback to better understand the request. labels Jan 27, 2025
@peterwilsoncc
Copy link
Contributor

Thanks for the PR, @elvismdev

While testing the code, it appears that using the settings endpoint prevents contributors and other low privileged users from using the maps block when credentials are saved.

Develop branch PR Branch
Screenshot 2025-01-29 at 11 09 42 AM Screenshot 2025-01-29 at 11 10 17 AM

I think the check needs to be against the MapsBlockApple/v1/GetJWT endpoint API endpoint and if that returns an error we display the unauthenticated version of the block. If it returns a valid response, the authenticated version is shown.

The endpoint is registered in the file includes/rest-routes.php

@jeffpaul
Copy link
Member

@faisal-alvi perhaps this is something you can help update and send back to Peter for review during your OSS week?

@faisal-alvi
Copy link
Contributor

@peterwilsoncc 👋🏻

I’ve updated the block’s authentication logic as suggested. Instead of checking the settings endpoint, the block now checks the MapsBlockApple/v1/GetJWT REST API endpoint to determine authentication status.

  • If the endpoint returns a valid response, the block shows the map.
  • If it returns an error, the block displays the credentials form (unauthenticated state).

This should resolve the issue where contributors and other low-privileged users were unable to use the block when credentials were saved.

Please let me know if you have any feedback or if further adjustments are needed!

@peterwilsoncc
Copy link
Contributor

@faisal-alvi I'm seeing a bug once credentials are saved in that the authentication screen is shown to admins and the error message to contributors rather than the map input. At this point of the execution isAuthenticated is always false

return (

In the console, I am seeing an error when I run the "confirm mapkit credentials button" but that may be related to the issue described above.

TypeError: setting getter-only property "target"
    dispatchEvent https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js?ver=5:2
    ue https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js?ver=5:2
    dispatchEvent https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js?ver=5:2
    onClick http://xu-osp-plugins.local/content/plugins/maps-block-apple/build/index.js?ver=b2cbbe953f00ade16470:1

Screenshot 2025-05-15 at 12 31 16 pm

Screenshot 2025-05-15 at 12 31 46 pm

Screenshot 2025-05-15 at 12 34 09 pm

@faisal-alvi
Copy link
Contributor

@peterwilsoncc Thanks for the feedback! The issue was caused by an unnecessary check in the authentication logic; specifically, I was checking for response && response.jwt after calling the MapsBlockApple/v1/GetJWT endpoint. However, the endpoint already returns a valid response when credentials are present, so the extra .jwt check was preventing proper authentication.

I updated the logic to simply check for a valid response (i.e., if (response) { ... }), which resolves the issue. Now, after saving credentials, the block correctly authenticates and displays the map for all user roles as expected.

Let me know if you have any further feedback or spot anything else!

@faisal-alvi faisal-alvi removed the request for review from fabiankaegy May 16, 2025 15:01
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

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

Thanks @faisal-alvi, this is now working as expected.

@faisal-alvi faisal-alvi merged commit c368adc into develop May 19, 2025
12 of 14 checks passed
@faisal-alvi faisal-alvi deleted the fix/232-Block_crashes_without_apple_maps_credentials branch May 19, 2025 08:54
@dkotter dkotter modified the milestones: 1.2.0, 1.1.5 Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block crashes without apple maps credentials

5 participants

Comments