|
@@ -38,6 +38,7 @@ const jwtDecode = token => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
function promiseReducer(state = {}, { type, name, status, payload, error }) {
|
|
|
if (type === "PROMISE") {
|
|
|
return {
|
|
@@ -48,48 +49,23 @@ function promiseReducer(state = {}, { type, name, status, payload, error }) {
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
-function authReducer(state, {type, token}){
|
|
|
- if (!state) {
|
|
|
- if (localStorage.authToken) {
|
|
|
- type = 'AUTH_LOGIN'
|
|
|
- token = localStorage.authToken
|
|
|
- } else {
|
|
|
- return {}
|
|
|
- }
|
|
|
- }
|
|
|
- if (type === 'AUTH_LOGIN') {
|
|
|
- let auth = jwtDecode(token)
|
|
|
- if (auth) {
|
|
|
- localStorage.authToken = token
|
|
|
- return { token, payload: auth }
|
|
|
- }
|
|
|
- }
|
|
|
- if (type === 'AUTH_LOGOUT') {
|
|
|
- localStorage.authToken = ''
|
|
|
- console.log(localStorage.authToken)
|
|
|
- return {}
|
|
|
- }
|
|
|
- return state
|
|
|
-}
|
|
|
-
|
|
|
-// function authReducer(state, {type, token}){
|
|
|
-// if (state === undefined && localStorage.authToken){
|
|
|
-// token = localStorage.authToken;
|
|
|
-// // token = '';
|
|
|
-// type = 'AUTH_LOGIN'
|
|
|
-// }
|
|
|
-// if (type === 'AUTH_LOGIN'){
|
|
|
-// if(jwtDecode(token)){
|
|
|
-// localStorage.authToken = token;
|
|
|
-// return { token, payload: jwtDecode(token) };
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (type === 'AUTH_LOGOUT'){
|
|
|
-// localStorage.authToken = '';
|
|
|
-// return {}
|
|
|
-// }
|
|
|
-// return state || {}
|
|
|
-// }
|
|
|
+ function authReducer(state, { type, token }) {
|
|
|
+ if (state === undefined && localStorage.authToken) {
|
|
|
+ token = localStorage.authToken
|
|
|
+ type = 'AUTH_LOGIN'
|
|
|
+ }
|
|
|
+ if (type === 'AUTH_LOGIN') {
|
|
|
+ if (jwtDecode(token)) {
|
|
|
+ localStorage.authToken = token
|
|
|
+ return { token, payload: jwtDecode(token) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (type === 'AUTH_LOGOUT') {
|
|
|
+ localStorage.authToken = ''
|
|
|
+ return {}
|
|
|
+ }
|
|
|
+ return state || {}
|
|
|
+ }
|
|
|
|
|
|
const store = createStore(combineReducers({
|
|
|
promise: promiseReducer,
|