adopted-ember-addons / ember-electron

:zap: Build, test, compile and package desktop apps with Ember and Electron
https://ember-electron.js.org/
Other
805 stars 109 forks source link

Sending headers to an API #150

Closed mk-conn closed 7 years ago

mk-conn commented 7 years ago

Not sure if this is an ember-electron related issue...

In my ember adapter I set an authorization header which works with no problems (running the ember app in a web browser)

headers: Ember.computed(function () {
        const config = get(this, 'configuration').retrieve('conn');
        if (config) {
            const auth = btoa(config.username + ':' + config.password);
            Ember.debug(`adapter: application::headers() auth:${auth}`);

            return {
                Authorization: 'Basic ' + auth
            };
        }

    }).volatile(),

Running in ember-electron the header is not set... Do I have to do this differently in ember-electron?

anulman commented 7 years ago

Not typically, and none of your code seems particularly "off".

Have you dropped in a debugger / console.log statements yet to check state as the fn executes? I'd be most interested in e.g. what the configuration & conn objects are / how they're built.

mk-conn commented 7 years ago

configuration is a service that stores username + password settings in the localstorage... nothing fancy. And debugging shows, that those values are correct. I'm trying to make this project an ember-electron project... https://github.com/mk-conn/nextfeed/blob/master/app/application/adapter.js

Strange thing is, it works when the electron app is opened the first time. On the next click it does not work any more...

pichfl commented 7 years ago

Is there a reason that those computed properties are marked as volatile? Have you tried using DS.PromiseProxy to wrap the calls to your configuration service and make the computed keys dependent?

.volatile works a bit different than one might expect. It means it no longer notifies of changes automatically, see docs here: http://emberjs.com/api/classes/Ember.ComputedProperty.html#method_volatile (at least for me, that was exactly the opposite of what I expected)

I'll try to have a look at the rest of your app if I find some time later today.

mk-conn commented 7 years ago

Hmm.. okay, I'm checking this volatile thing - can't really remember why I did it that way...

anulman commented 7 years ago

@mk-conn was this resolved?

mk-conn commented 7 years ago

Nope, changed to not using volatile() but it didn't make any difference. Also tried to use promise but couldn't make it really work in the headers() method...

mk-conn commented 7 years ago

I'm using ember-electron 2 - now its working! :)