summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/auth/auth.reducer.js
diff options
context:
space:
mode:
Diffstat (limited to 'animism-align/frontend/app/views/auth/auth.reducer.js')
-rw-r--r--animism-align/frontend/app/views/auth/auth.reducer.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/animism-align/frontend/app/views/auth/auth.reducer.js b/animism-align/frontend/app/views/auth/auth.reducer.js
new file mode 100644
index 0000000..05741f3
--- /dev/null
+++ b/animism-align/frontend/app/views/auth/auth.reducer.js
@@ -0,0 +1,40 @@
+import * as types from 'app/types'
+import { getDefault } from 'app/session'
+
+const initialState = {
+ logged_in: !!getDefault('access_token', false),
+ user_id: null,
+ user: null,
+}
+
+export default function authReducer(state = initialState, action) {
+ // console.log(action.type, action)
+ switch (action.type) {
+ case types.auth.logged_in:
+ return {
+ ...state,
+ logged_in: true,
+ user_id: action.user_id,
+ user: null,
+ }
+ case types.auth.logged_out:
+ return {
+ ...state,
+ logged_in: false,
+ user_id: null,
+ user: null,
+ }
+ case types.user.show:
+ if (action.data.res.id !== state.user_id) {
+ return state
+ }
+ return {
+ ...state,
+ user: {
+ ...action.data.res,
+ }
+ }
+ default:
+ return state
+ }
+}