Hi,
In Electron, when using this API action, my stored global jwt_token will not load; the dmx-api-action seems to run before the global jwt_token is available, resulting in an empty Bearer being sent.
"jwt_token" Its a global variable set in javascript during login, in previous steps, so yes, it already exist and is available, for example, I can do this: <dmx-value id="var2" dmx-bind:value="jwt_token"></dmx-value>
Then with a html input element I can bind the var2.value and I can see the token, but dmx-api-action looks like run before.
If I add this script to load API Action with a wait time, the APi works normally and the jwt_token from global is correctly tooked without problem.
how do you get the jwt_token to start with? Is that pulled from a action script into your page. Instead of loading the api on its own, have an on success event of pulling the token and then run the api after the token is received?
Hi @baub
Correct, the jwt_token is sent on success event into a function with the token obteined from the login.
The function store the token with Electron safeStorage and at same time in dmx.global.set.
The token is available because I can bind the value into a text input using the Defined Global Variable in the main page that is jwt_token, and the token appears on page load without issue.
The problem is that dmx-api-action seems to execute before jwt_token is available.
Hi @franse
Because with this javascript that allow to load the api with a wait time make me think that.
With this method works, but I'm not sure if is the best.
You might try turning off auto run on the api and use a page flow with Auto run turned on, to use a while loop so you can wait for the value to be available before executing the api.
Hello,
After some testing, I realized the cause of all this was the jwt_token update, thanks @baub.
After a successful login, my function set dmx.global.set correctly. However, the problem lay in where that function was called. Originally, it was set before the body, and now, to make it work, I translated that script after dmxAppConnect.js in <head>.
Now, the API actions took the global jwt_token variable and correctly parsed its value in the authorization header.
Thanks @baub, @franse and @mebeingken for your time.