Logins and logouts (sessions) are working
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { LOGIN, LOGOUT } from "../actions/accounts.js";
|
||||
|
||||
const initialStore = {
|
||||
id: 0,
|
||||
email: '',
|
||||
username: '',
|
||||
token: 0
|
||||
};
|
||||
|
||||
export function accountReducer(store = initialStore, action) {
|
||||
switch(action.type) {
|
||||
case LOGIN:
|
||||
let newStore = JSON.parse(JSON.stringify(initialStore));
|
||||
|
||||
newStore.id = action.id;
|
||||
newStore.email = action.email;
|
||||
newStore.username = action.username;
|
||||
newStore.token = action.token;
|
||||
|
||||
return newStore;
|
||||
|
||||
case LOGOUT:
|
||||
return initialStore;
|
||||
|
||||
default:
|
||||
return store;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import { accountReducer } from './accounts.js';
|
||||
|
||||
//compile all reducers together
|
||||
export default combineReducers({
|
||||
account: accountReducer
|
||||
});
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { ACTION_NAME } from "../actions/actions.jsx";
|
||||
|
||||
const initialState = {};
|
||||
|
||||
export default function reducer(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case ACTION_NAME:
|
||||
//DO NOTHING
|
||||
return state;
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user