2018-01-22 15:53:39 -08:00
|
|
|
import Base from 'ember-simple-auth/authenticators/base';
|
2018-01-22 16:09:38 -08:00
|
|
|
import { IAuthenticateResponse, IAuthenticationData } from 'wherehows-web/typings/api/authentication/user';
|
2018-01-22 17:31:48 -08:00
|
|
|
import JQuery from 'jquery';
|
|
|
|
|
|
|
|
const { post } = JQuery;
|
2018-01-22 15:53:39 -08:00
|
|
|
|
|
|
|
export default Base.extend({
|
|
|
|
/**
|
|
|
|
* Implements Base authenticator's authenticate method.
|
|
|
|
* Resolves with data object returned from successful request.
|
|
|
|
* @param {string} username username to authenticate with
|
|
|
|
* @param {string} password matching candidate password for username
|
2018-01-22 16:10:40 -08:00
|
|
|
* @return {Promise<IAuthenticationData>}
|
2018-01-22 15:53:39 -08:00
|
|
|
*/
|
2018-01-22 16:09:38 -08:00
|
|
|
authenticate: async (username: string, password: string): Promise<IAuthenticationData> => {
|
2018-01-22 17:31:48 -08:00
|
|
|
// retaining usage of jquery post method as opposed to fetch, since api currently fails with string response
|
|
|
|
// TODO: update mid-tier exception handling
|
|
|
|
const { data } = await (<JQuery.jqXHR<IAuthenticateResponse>>post({
|
2018-01-22 15:53:39 -08:00
|
|
|
url: '/authenticate',
|
2018-01-22 17:31:48 -08:00
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify({ username, password })
|
|
|
|
}));
|
2018-01-22 15:53:39 -08:00
|
|
|
|
|
|
|
return { ...data };
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the authenticator's restore method
|
|
|
|
* @return {Promise<void>}
|
|
|
|
*/
|
|
|
|
restore: () => Promise.resolve()
|
|
|
|
});
|