summaryrefslogtreecommitdiff
path: root/app/client/auth/auth.reducer.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/client/auth/auth.reducer.js')
-rw-r--r--app/client/auth/auth.reducer.js43
1 files changed, 25 insertions, 18 deletions
diff --git a/app/client/auth/auth.reducer.js b/app/client/auth/auth.reducer.js
index cacb0d5..7b3193a 100644
--- a/app/client/auth/auth.reducer.js
+++ b/app/client/auth/auth.reducer.js
@@ -1,12 +1,14 @@
-import types from '../types';
+import types from '../types'
const authInitialState = {
token: null,
user: {},
groups: {},
+ initialized: false,
loading: false,
isAuthenticated: false,
-};
+ returnTo: null,
+}
const auth = (state = authInitialState, action) => {
switch(action.type) {
@@ -17,35 +19,40 @@ const auth = (state = authInitialState, action) => {
isAuthenticated: !!action.data,
loading: false,
error: null,
- };
+ }
+
+ case types.auth.initialized:
+ return {
+ ...state,
+ loading: false,
+ initialized: true,
+ error: null,
+ }
case types.auth.loading:
return {
...state,
loading: true,
error: null,
- };
+ }
case types.auth.set_current_user:
- const groups = {}
- action.data.groups.forEach(g => groups[g.name.toLowerCase()] = true)
- if (action.data.is_staff) {
- groups['staff'] = true
- }
- if (action.data.is_superuser) {
- groups['superuser'] = true
- }
return {
...state,
user: action.data,
- groups,
error: null,
- };
+ }
+
+ case types.auth.set_return_to:
+ return {
+ ...state,
+ returnTo: action.data,
+ }
case types.auth.logout_user:
return {
...authInitialState
- };
+ }
case types.auth.set_error:
return {
@@ -72,11 +79,11 @@ const auth = (state = authInitialState, action) => {
// console.error("error loading initial state")
// }
// }
- return state;
+ return state
default:
- return state;
+ return state
}
}
-export default auth;
+export default auth