smart-on-fhir / client-js

JavaScript client for FHIR
Other
292 stars 209 forks source link

Expressjs example is not working in launch.smarthealthit.org #115

Open QusaiAnthem opened 3 years ago

QusaiAnthem commented 3 years ago

We are trying to use the Expressjs example in here: https://codesandbox.io/s/c0che provided by @vlad-ignatov as a starting point to build a SoF application in our team at Anthem. We are facing an issue with the launching of the Example app using the launch.smarthealthit.org:

Steps:

Expected out put: browser to show a patient JSON object Actual: The /launch path get executed but when the we are redirected to the /app path it gets stuck in pending for a bit and fails to load any things. Also, the nodejs server logs the following error: image

To make it work, repeat the steps above but with "Simulate launch within the EHR user interface" being unchecked. The app launches without errors and shows the Patient JSON in the browser, see below: image

We did debugging by putting break points in the code. In the case of failure, the express sessionID is different for the /launch and /app handlers. So, the ready method is not recognizing the launch state and shows the "Error: No state found! Please (re)launch the app" error as shown in the screenshot above. We suspected that it might relate to the application being rendered in an iframe (by keeping "Simulate launch within the EHR user interface" unchecked). We tried to set X-Frame-Options header to allow the response content to be rendered in an iframe but we got no success with that.

May anyone help out please?

Thank you

vlad-ignatov commented 3 years ago

Thank you for helping me realize that all of my server examples are somehow broken in a similar way (despite being frozen). In my case, it turns out that CodeSandbox is doing some weird routing now, making it impossible to properly resolve relative redirect URLs like "/app" to absolute ones on the same domain (which in turn messes up the cookies and the session). I have that fixed now.

As for your case:

  1. This is a standalone launch example. To use it in EHR launches, please remove the iss option from smartSettings.
  2. Can you check (at runtime) if your launch and redirect urls are using the same origin. If not, try to use full URL in the redirectUri option and see if that helps.
QusaiAnthem commented 3 years ago

No problem and thank you for following up. I tried both options:

  1. I got this from the example code comments and tried this before. I just tried again but no success
  2. The origin is the same. I tried to put the full URL but with no success.

I tried to look at the Launcher code here (https://github.com/smart-on-fhir/smart-launcher) to find some hints or so but I am still in the find.

QusaiAnthem commented 3 years ago

@vlad-ignatov do you have a nodejs example that works fine as "EHR launch" with "Simulate launch within the EHR user interface" checked?

mfs-abhinav commented 2 years ago

@vlad-ignatov do you have any update on above issue? We are getting the exact same issue.