Created
December 1, 2020 23:38
-
-
Save mentix02/88a52a851e3b9412a3e676f6d0e1df1d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { LOGIN, LOGOUT, AuthState, AuthActionType } from "./types"; | |
const initialState: AuthState = { | |
isAuthenticated: false, | |
}; | |
const authReducer = ( | |
state: AuthState = initialState, | |
action: AuthActionType | |
): AuthState => { | |
switch (action.type) { | |
case LOGOUT: | |
return initialState; | |
case LOGIN: | |
return { | |
isAuthenticated: true, | |
token: action.payload.token, | |
username: action.payload.username, | |
}; | |
default: | |
return state; | |
} | |
}; | |
export default authReducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment