Skip to content

Commit

Permalink
Await xsrfRequest before starting the app
Browse files Browse the repository at this point in the history
Instead of awaiting the xsrfRequest before calling
get_endpoint, await it before starting the marionettejs
application. That way we do not need to check the promise
before each request and any other request made by the app
will also have the xsrf token. Not matter which ones is
executed first.
  • Loading branch information
MartinRiese committed Jul 25, 2024
1 parent b268bed commit 036fa38
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 2 additions & 1 deletion corehq/apps/cloudcare/static/cloudcare/js/formplayer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ hqDefine("cloudcare/js/formplayer/main", [
FormplayerFrontEnd,
sentry
) {
$(function () {
$(async function () {
sentry.initSentry();

window.MAPBOX_ACCESS_TOKEN = initialPageData.get('mapbox_access_token'); // maps api is loaded on-demand
Expand All @@ -24,6 +24,7 @@ hqDefine("cloudcare/js/formplayer/main", [
singleAppMode: false,
environment: initialPageData.get('environment'),
};
await FormplayerFrontEnd.xsrfRequest;
FormplayerFrontEnd.start(options);

var $menuToggle = $('#commcare-menu-toggle'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ hqDefine("cloudcare/js/formplayer/menus/api", [
}

// If an endpoint is provided, first claim any cases it references, then navigate
return FormplayerFrontend.xsrfRequest.then(function () {
return API.queryFormplayer(options, "get_endpoint");
});
return API.queryFormplayer(options, "get_endpoint");
});

FormplayerFrontend.getChannel().reply("icon:click", function (options) {
Expand Down

0 comments on commit 036fa38

Please sign in to comment.