add multiplexer

closes #81
This commit is contained in:
Mario Pesch
2021-03-30 15:03:34 +02:00
parent 6b12c501a0
commit 21d282ee1b
10 changed files with 261 additions and 135 deletions
+26 -16
View File
@@ -1,59 +1,69 @@
import { MYBADGES_CONNECT, MYBADGES_DISCONNECT, USER_LOADED, USER_LOADING, AUTH_ERROR, LOGIN_SUCCESS, LOGIN_FAIL, LOGOUT_SUCCESS, LOGOUT_FAIL, REFRESH_TOKEN_SUCCESS } from '../actions/types';
import {
MYBADGES_CONNECT,
MYBADGES_DISCONNECT,
USER_LOADED,
USER_LOADING,
AUTH_ERROR,
LOGIN_SUCCESS,
LOGIN_FAIL,
LOGOUT_SUCCESS,
LOGOUT_FAIL,
REFRESH_TOKEN_SUCCESS,
} from "../actions/types";
const initialState = {
token: localStorage.getItem('token'),
refreshToken: localStorage.getItem('refreshToken'),
token: localStorage.getItem("token"),
refreshToken: localStorage.getItem("refreshToken"),
isAuthenticated: null,
progress: true,
user: null
user: null,
};
export default function foo(state = initialState, action){
switch(action.type){
export default function foo(state = initialState, action) {
switch (action.type) {
case USER_LOADING:
return {
...state,
progress: true
progress: true,
};
case USER_LOADED:
return {
...state,
isAuthenticated: true,
progress: false,
user: action.payload
user: action.payload,
};
case LOGIN_SUCCESS:
case REFRESH_TOKEN_SUCCESS:
localStorage.setItem('token', action.payload.token);
localStorage.setItem('refreshToken', action.payload.refreshToken);
localStorage.setItem("token", action.payload.token);
localStorage.setItem("refreshToken", action.payload.refreshToken);
return {
...state,
user: action.payload.user,
token: action.payload.token,
refreshToken: action.payload.refreshToken,
isAuthenticated: true,
progress: false
progress: false,
};
case MYBADGES_CONNECT:
case MYBADGES_DISCONNECT:
return {
...state,
user: action.payload
user: action.payload,
};
case AUTH_ERROR:
case LOGIN_FAIL:
case LOGOUT_SUCCESS:
case LOGOUT_FAIL:
localStorage.removeItem('token');
localStorage.removeItem('refreshToken');
localStorage.removeItem("token");
localStorage.removeItem("refreshToken");
return {
...state,
token: null,
refreshToken: null,
user: null,
isAuthenticated: false,
progress: false
progress: false,
};
default:
return state;