Skip to content

Commit

Permalink
Working login
Browse files Browse the repository at this point in the history
  • Loading branch information
faglo committed Dec 1, 2022
1 parent a8005ae commit b66b259
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Search from "./screens/Search"
import Settings from "./screens/Settings"
import { updateScreen, updateSearch } from "./store/appStateSlice"
import { useAppDispatch, useAppSelector } from "./store/store"
import useLocalStore from "./hooks/useLocalStore"

const sxStyles = {
player: {
Expand Down Expand Up @@ -57,6 +58,8 @@ function App() {
const currentScreen = useAppSelector((state) => state.appState.screen)
const isLoggedIn = useAppSelector((state) => state.appState.logged_in)
const [api] = useVKAPI()
const [loginState, setLoginState] = useState(false)
const [localStore] = useLocalStore("token", "", ".vkm");
// const isLoggedIn = true;
const screens = [
{
Expand Down Expand Up @@ -85,8 +88,8 @@ function App() {

useEffect(() => {
console.log("Login status", isLoggedIn)
console.log("Current screen", currentScreen)
}, [isLoggedIn, api])
setLoginState(isLoggedIn)
}, [isLoggedIn, api, localStore])

const onSearch = () => {
dispatch(updateSearch(searchVal))
Expand All @@ -95,7 +98,7 @@ function App() {
}


if (isLoggedIn && api) {
if (loginState) {
return (
<Box sx={{ display: "flex" }}>
<Drawer sx={sxStyles.drawer} variant={"permanent"} anchor={"left"}>
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useVKAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const useVKAPI = () => {
vkAPIInstance = api;
setVKAPI(api);
dispatch(updateLoggedIn(true));
console.log("Logged in")
}).catch(e => {
rps += 1;
console.log("error", e)
Expand All @@ -50,6 +51,7 @@ const useVKAPI = () => {

const logout = () => {
setLocalStore("")
dispatch(updateLoggedIn(false));
}

return [vkAPI, updateVKAPI, logout] as const;
Expand Down

0 comments on commit b66b259

Please sign in to comment.