Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ember-simple-auth data adapter mixin doesn't work with Ember 3.13 without jQuery #1961

Closed
BryanHunt opened this issue Sep 26, 2019 · 7 comments

Comments

@BryanHunt
Copy link

BryanHunt commented Sep 26, 2019

I used ember-cli-update to update a project to EmberJS 3.13 which removes jQuery. This causes the beforeSend hook in the data adapter mixin to not be called and thus the token from ember-simple-auth-token to not be sent with any EmberData requests.

To work around this problem, I added the @ember/jquery module back and enabled jquery integration in optional-features.json.

I found: https://stackoverflow.com/questions/55180689/ember-simple-auth-and-ember-fetch-no-authorization-in-fetch-query but I couldn't get that to work. I did get authorization to work without jQuery by:

import DS from 'ember-data';
import { inject as service} from "@ember/service"

export default DS.JSONAPIAdapter.extend({
  session: service(),

  ajaxOptions(...args) {
    const hash = this._super(...args);

    let token = this.get('session.data.authenticated.token');
    hash.headers['Authorization'] = `Bearer ${token}`

    return hash;
  }
});
@oliverlj
Copy link

oliverlj commented Oct 27, 2019

This solution works for me as ember data use fetch now.

app/adapters/application.js

import { computed } from '@ember/object';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend(DataAdapterMixin, {
    headers: computed('session.data.authenticated.token', function () {
        if (this.session.isAuthenticated) {
            return { 'Authorization': 'Bearer ' + this.session.data.authenticated.token };
        }
    })
});

@brunoocasali
Copy link
Contributor

@oliverlj in your OPTIONS requests you must send authorization header too?

@oliverlj
Copy link

oliverlj commented Oct 29, 2019

I don't use options request for the moment

@ahemed-haneen
Copy link

the mixins are not a part of octane anymore...so what can we do about that?

@pax7
Copy link

pax7 commented Feb 24, 2020

@theloosecannon this is what i'm currently trying to work with

class ApplicationAdapter extends JSONAPIAdapter {
}

export default ApplicationAdapter.extend(DataAdapterMixin, {
});

@brunoocasali
Copy link
Contributor

Is possible to use ES6 classes with mixins (it works for every kind of class, component, model...):

export default class ApplicationAdapter extends JSONAPIAdapter.extend(DataAdapterMixin) {
 // your code
}

@marcoow
Copy link
Member

marcoow commented Jun 5, 2020

Closing this as all mixins are deprecated now – see #2198

@marcoow marcoow closed this as completed Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants