1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.LOGOUT_SUCCESS = exports.LOGIN_ERROR = exports.LOGIN_SUCCESS = exports.AUTHENTICATION_REQUIRED = undefined;
|
7 |
|
8 | var _stringify = require('babel-runtime/core-js/json/stringify');
|
9 |
|
10 | var _stringify2 = _interopRequireDefault(_stringify);
|
11 |
|
12 | exports.default = createAuthActions;
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 |
|
17 |
|
18 | var AUTHENTICATION_REQUIRED = exports.AUTHENTICATION_REQUIRED = 'AUTHENTICATION_REQUIRED';
|
19 | var LOGIN_SUCCESS = exports.LOGIN_SUCCESS = 'LOGIN_SUCCESS';
|
20 | var LOGIN_ERROR = exports.LOGIN_ERROR = 'LOGIN_ERROR';
|
21 | var LOGOUT_SUCCESS = exports.LOGOUT_SUCCESS = 'LOGOUT_SUCCESS';
|
22 |
|
23 | function createAuthActions(depsContainer) {
|
24 |
|
25 | var authenticationRequired = function authenticationRequired() {
|
26 | return { type: AUTHENTICATION_REQUIRED };
|
27 | };
|
28 |
|
29 | var login = function login(email, password) {
|
30 | return function (_ref) {
|
31 | var dispatch = _ref.dispatch;
|
32 |
|
33 | var url = '/auth/login';
|
34 |
|
35 | depsContainer.fetch(url, {
|
36 | method: 'POST',
|
37 | headers: {
|
38 | 'Content-Type': 'application/json',
|
39 | 'Accept': 'application/json'
|
40 | },
|
41 | body: (0, _stringify2.default)({ email: email, password: password })
|
42 | }).then(function (response) {
|
43 | dispatch({ type: LOGIN_SUCCESS, response: response });
|
44 | return response;
|
45 | }).catch(function (error) {
|
46 | var message = 'Ajejej, auth fetch error: ' + error.message + ', url: ' + url;
|
47 | dispatch({ type: LOGIN_ERROR, error: error });
|
48 | throw new Error(message);
|
49 | });
|
50 | };
|
51 | };
|
52 |
|
53 | var logout = function logout() {
|
54 | return { type: LOGOUT_SUCCESS };
|
55 | };
|
56 |
|
57 | return {
|
58 | authenticationRequired: authenticationRequired,
|
59 | login: login,
|
60 | logout: logout
|
61 | };
|
62 | } |
\ | No newline at end of file |