diff --git a/src/components/AppleMap.js b/src/components/AppleMap.js index 5a58a2e..98d2737 100644 --- a/src/components/AppleMap.js +++ b/src/components/AppleMap.js @@ -54,21 +54,24 @@ class AppleMap { } static authenticateMap() { - apiFetch( { path: 'MapsBlockApple/v1/GetJWT/' } ) - .then( ( token ) => { - mapkit.init( { - authorizationCallback( done ) { - done( token ); - }, + function getJWTToken( resolveCallback ) { + apiFetch( { path: 'MapsBlockApple/v1/GetJWT/' } ) + .then( resolveCallback ) + .catch( ( error ) => { + dispatch( 'core/notices' ).createErrorNotice( + error.message, + { + isDismissible: true, + type: 'snackbar', + } + ); + mapkit.dispatchEvent( new Event( 'error' ) ); } ); - } ) - .catch( ( error ) => { - dispatch( 'core/notices' ).createErrorNotice( error.message, { - isDismissible: true, - type: 'snackbar', - } ); - mapkit.dispatchEvent( new Event( 'error' ) ); - } ); + } + + mapkit.init( { + authorizationCallback: getJWTToken, + } ); } } diff --git a/src/edit.js b/src/edit.js index 3afa105..1a6f85e 100644 --- a/src/edit.js +++ b/src/edit.js @@ -52,8 +52,8 @@ export default function MapsBlockAppleEdit( props ) { break; case 'Refreshed': setIsLoading( false ); - setAuthenticated( false ); - mapkit.authenticated = false; + setAuthenticated( true ); + mapkit.authenticated = true; break; default: setIsLoading( false );