Closed ynnoj closed 7 years ago
Please share the full implementation of your authenticator. Also you'd probably want to change the above to
return ajax.request('url', {
method: 'POST',
data: body
});
import Ember from 'ember';
import Base from 'ember-simple-auth/authenticators/base';
import Config from '../config/environment';
const { RSVP, inject: { service } } = Ember;
export default Base.extend({
ajax: service(),
restore() {
},
authenticate() {
const ajax = this.get('ajax');
const data = {
client_id: Config.clientId,
client_secret: Config.clientSecret,
grant_type: 'client_credentials'
};
const body = Object.keys(data).map((key) => {
return `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`;
}).join('&');
return ajax.request('redacted', {
method: 'POST',
data: body
}).then((response) => {
return RSVP.resolve(response);
}), (error) => {
return RSVP.reject(error);
};
},
invalidate() {
return Ember.RSVP.resolve();
}
});
@marcoow If I remove the .then()
from the ajax.request
then the request does not resolve.
@marcoow If I remove the .then() from the ajax.request then the request does not resolve.
You're just returning the promise that resolves to the request's response or rejects with an error - that should be fine. Currently, you're returning a promise that resolves with a resolving promise which is most likely not what you want.
You also need to implement the restore
method - otherwise the session will always be lost when reloading the page/restarting the app.
@marcoow I've never actually had a successful session authenticate, hence why the restore method remains empty 😢
I'll try recreate this issue in a test app and share.
I've created a test app that replicates the same symptoms of my working app.
I'm writing a custom authenticator for an app which merely sends an
ajax.request
to my endpoint. The request returns the expected response, but theauthenticate
promise from Ember Simple Auth doesn't seem to resolve as thesessionAuthenticationSucceeded
hook never fires.