client/src/reducers/authReducer.js
changeset 44 3b20e2b584fe
parent 12 48ddaa42b810
child 47 64428c7ebc19
--- a/client/src/reducers/authReducer.js	Thu Jun 15 17:18:22 2017 +0200
+++ b/client/src/reducers/authReducer.js	Fri Jun 16 18:36:39 2017 +0200
@@ -1,6 +1,54 @@
+import * as types from '../constants/actionTypes';
+
 export const isAuthenticated = (state = false, action) => {
   switch (action.type) {
     default:
       return state;
   }
-};
+}
+
+export const currentUser = (state = null, action) => {
+  switch (action.type) {
+    case types.AUTH_LOGIN_SUCCESS:
+      return action.user;
+    default:
+      return state;
+  }
+}
+
+export const token = (state = null, action) => {
+  switch (action.type) {
+    case types.AUTH_LOGIN_SUCCESS:
+      console.log('token', action.token)
+      return action.token;
+    default:
+      return state;
+  }
+}
+
+// TODO Use Immutable.Map
+const loginState = {
+  loading: false,
+  success: false,
+  error: false,
+}
+
+export const login = (state = loginState, action) => {
+  switch (action.type) {
+    case types.AUTH_LOGIN_REQUEST:
+      return {
+        loading: true,
+        success: false,
+        error: false,
+      }
+    case types.AUTH_LOGIN_SUCCESS:
+    case types.AUTH_LOGIN_ERROR:
+      return {
+        loading: false,
+        success: action.type === types.AUTH_LOGIN_SUCCESS,
+        error: action.type === types.AUTH_LOGIN_ERROR,
+      }
+    default:
+      return state
+  }
+}