diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-09-17 01:51:32 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-09-17 01:51:32 +0200 |
| commit | d2b4aaf625f10c659614d7326d8dc3e2e31ae0f3 (patch) | |
| tree | 4755ec719eceb0de2c4fb77b49ef974dd5bca805 /app/client/auth/auth.reducer.js | |
| parent | a77d0812d52d52d80bc750832b4e0fe065ce4cac (diff) | |
auth gate/router combo
Diffstat (limited to 'app/client/auth/auth.reducer.js')
| -rw-r--r-- | app/client/auth/auth.reducer.js | 43 |
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 |
