From 88d092e21a4ea296ce804ef416683807df4b7d38 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 5 Mar 2021 21:34:34 +0100 Subject: change password. log in --- .../frontend/app/views/auth/auth.reducer.js | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 animism-align/frontend/app/views/auth/auth.reducer.js (limited to 'animism-align/frontend/app/views/auth/auth.reducer.js') 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 + } +} -- cgit v1.2.3-70-g09d2