-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createSlice } from '@reduxjs/toolkit' | ||
// Slice | ||
const slice = createSlice({ | ||
name: 'user', | ||
initialState: { | ||
user: null, | ||
}, | ||
reducers: { | ||
loginSuccess: (state, action) => { | ||
state.user = action.payload; | ||
}, | ||
logoutSuccess: (state) => { | ||
state.user = null; | ||
}, | ||
}, | ||
}); | ||
export default slice.reducer | ||
// Actions | ||
const { loginSuccess, logoutSuccess } = slice.actions | ||
export const login = ({ username | ||
}) => async dispatch => { | ||
try { | ||
// const res = await api.post('/api/auth/login/', { username, password }) | ||
dispatch(loginSuccess({username})); | ||
} catch (e) { | ||
return console.error(e.message); | ||
} | ||
} | ||
export const logout = () => async dispatch => { | ||
try { | ||
// const res = await api.post('/api/auth/logout/') | ||
return dispatch(logoutSuccess()) | ||
} catch (e) { | ||
return console.error(e.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { configureStore } from '@reduxjs/toolkit' | ||
import { combineReducers } from 'redux' | ||
const reducer = combineReducers({ | ||
// here we will be adding reducers | ||
}) | ||
const store = configureStore({ | ||
reducer, | ||
}) | ||
export default store; |