Skip to content

Commit

Permalink
Merge pull request #52 from 10up/fix/rework-authorisations
Browse files Browse the repository at this point in the history
Fix/rework authorisations
  • Loading branch information
helen authored Jun 25, 2020
2 parents 078951e + 666fac8 commit 13a9674
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
31 changes: 17 additions & 14 deletions src/components/AppleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 13a9674

Please sign in to comment.