Skip to content

Instantly share code, notes, and snippets.

@PrincewillIroka
Last active December 31, 2020 20:34
Show Gist options
  • Save PrincewillIroka/574a1602c4636d4ca2d6c1957b648335 to your computer and use it in GitHub Desktop.
Save PrincewillIroka/574a1602c4636d4ca2d6c1957b648335 to your computer and use it in GitHub Desktop.
index.js file in store
export const initialState = {
isLoggedIn: JSON.parse(localStorage.getItem("isLoggedIn")) || false,
user: JSON.parse(localStorage.getItem("user")) || null,
client_id: process.env.REACT_APP_CLIENT_ID,
redirect_uri: process.env.REACT_APP_REDIRECT_URI,
client_secret: process.env.REACT_APP_CLIENT_SECRET,
proxy_url: process.env.REACT_APP_PROXY_URL
};
export const reducer = (state, action) => {
switch (action.type) {
case "LOGIN": {
localStorage.setItem("isLoggedIn", JSON.stringify(action.payload.isLoggedIn))
localStorage.setItem("user", JSON.stringify(action.payload.user))
return {
...state,
isLoggedIn: action.payload.isLoggedIn,
user: action.payload.user
};
}
case "LOGOUT": {
localStorage.clear()
return {
...state,
isLoggedIn: false,
user: null
};
}
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment