Last active
December 31, 2020 20:34
-
-
Save PrincewillIroka/574a1602c4636d4ca2d6c1957b648335 to your computer and use it in GitHub Desktop.
index.js file in store
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
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