import { decode as atob } from 'base-64'; function authReducer(state, { type, token }) { if (state === undefined) { if (localStorage.authToken) { type = "LOGIN" token = localStorage.authToken } else { return {} } } if (type === "LOGIN") { localStorage.authToken = token return { token, payload: JSON.parse(atob(token.split(".")[1])) } } if (type === "LOGOUT") { localStorage.removeItem("authToken") return {} } return state } export default authReducer