Skip to content

Instantly share code, notes, and snippets.

@mentix02
Created December 1, 2020 23:38
Show Gist options
  • Save mentix02/88a52a851e3b9412a3e676f6d0e1df1d to your computer and use it in GitHub Desktop.
Save mentix02/88a52a851e3b9412a3e676f6d0e1df1d to your computer and use it in GitHub Desktop.
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