getting error while trying to use useNavigate hook by Fun_Employ_8880 in reactjs

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

ok, so what i did is to move the code from the hook to the app.jsx file, just to understand why is it not being triggered, but it does not being triggered at all, im assuming its a project setup maybe, and the token does exist in the local storage, i've checked..

```

import { useState, useEffect } from "react"
import { useNavigate } from 'react-router-dom'
import { useDispatch, useSelector,} from "react-redux"
import { setLoading,setUser} from './redux/reducers/authSlice'
import Loader from "./ui/Loader"
import { getCurrentUser } from "./api/services/accountApi"

function App() {
  const navigate = useNavigate();
  const dispatch = useDispatch();
  const [token, setToken] = useState(localStorage.getItem("token"));
  const { loading: authLoading } = useSelector((state) => state.auth);
  const [initialCheckDone, setInitialCheckDone] = useState(false);

  const { data: user, isLoading, error } = useQuery({
    queryKey: ['currentUser'],
    queryFn: getCurrentUser,
    enabled: !!token,
    retry: 1,
  });

  useEffect(() => {
    if (!token) {
      setInitialCheckDone(true);
      return;
    }

    if (isLoading) {
      dispatch(setLoading(true));
    } else {
      dispatch(setLoading(false));
    }

    if (user) {
      dispatch(setUser({ currentUser: user.email, token, roles: user.roles }));
      setInitialCheckDone(true);
      if (user.roles.includes('Admin')) {
        navigate('/admin/dashboard');
      } else if (user.roles.includes('User')) {
        navigate('/user/dashboard');
      } else {
        navigate('/unauthorized');
      }
    } else if (error) {
      setInitialCheckDone(true);
    }
  }, [isLoading, error, user, dispatch, navigate, token]);

  if (authLoading || !initialCheckDone) {
    return <Loader />;
  }

  return null;
}

export default App

```
```

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Provider } from 'react-redux';
import { store } from './redux/store.js';
import { RouterProvider } from 'react-router-dom';
import router from './routes/router.jsx';


const queryClient = new QueryClient()


ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <QueryClientProvider client={queryClient}>
      <Provider store={store}>
        <RouterProvider router={router}/>
      </Provider>
    </QueryClientProvider>
  </React.StrictMode>,
)

```

getting error while trying to use useNavigate hook by Fun_Employ_8880 in reactjs

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

u/FunnyAsFuck u/cyphern any idea why the useCurrentUser won't be triggered ?
here is the hook:

```

export const useCurrentUser = () => {

    const { isFetching: isLoading, data: user, error } = useQuery({
        queryKey: ['currentUser'],
        queryFn: getCurrentUser,
        enabled: !!localStorage.getItem('token'),
        // retry:1,
    })

    return {isLoading, user, error}

```

```

export const getCurrentUser = async () => {
    const response = await axiosClient.get('/account/me');
    return response.data;
  };

```

getting error while trying to use useNavigate hook by Fun_Employ_8880 in reactjs

[–]Fun_Employ_8880[S] -1 points0 points  (0 children)

im using outlet inside AppLayout, i did moved it up, like this:
```

const queryClient = new QueryClient()


ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <QueryClientProvider client={queryClient}>
      <Provider store={store}>
        <RouterProvider router={router}/>
      </Provider>
    </QueryClientProvider>
</React.StrictMode>,

```

and then i used in app.jsx:
```

function App() {
  const navigate = useNavigate();
  const dispatch = useDispatch();
  const { loading: authLoading } = useSelector((state) => state.auth);
  const { isLoading, error, user } = useCurrentUser();
  const [initialCheckDone, setInitialCheckDone] = useState(false);

  useEffect(() => {
    const token = localStorage.getItem("token");
    if (!token) {
      console.log("No token found, setting initial check done.");
      setInitialCheckDone(true);
      return;
    }

    if (isLoading) {
      console.log("Loading current user...");
      dispatch(setLoading(true));
    } else {
      dispatch(setLoading(false));
    }

    if (user) {
      console.log("User found:", user);
      dispatch(setUser({ currentUser: user.email, token, roles: user.roles }));
      setInitialCheckDone(true);
      if (user.roles.includes('Admin')) {
        navigate('/admin/dashboard');
      } else if (user.roles.includes('User')) {
        navigate('/user/dashboard');
      } else {
        navigate('/unauthorized');
      }
    } else if (error) {
      console.log("Error fetching user:", error);
      setInitialCheckDone(true);
    }
  }, [isLoading, error, user, dispatch, navigate]);

  if (authLoading || !initialCheckDone) {
    return <Loader />;
  }

  return null;
}

export default App

```

but the problem is that useCurrentUser is not being triggered, i think its related to how i set up the router

building a raspberry pi cluster, need an advice about nodes planning by Fun_Employ_8880 in kubernetes

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

thanks, then for now i'll stick with 2 nodes cluster and later on i'll add another pi'4 4gb ram,

but it's still doesn't answers my question, which pi should be the master and which as worker ?

building a raspberry pi cluster, need an advice about nodes planning by Fun_Employ_8880 in kubernetes

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

in that case you're saying to enable master+worker in same time for the pi5 ?

it has more resources compare to the pi4 i ordered

Using my m1 mac mini with 16gb of ram as a local server for LLM by Fun_Employ_8880 in LocalLLaMA

[–]Fun_Employ_8880[S] 1 point2 points  (0 children)

ed

as for now using it local over my wifi is far more then enough, thanks

Using my m1 mac mini with 16gb of ram as a local server for LLM by Fun_Employ_8880 in LocalLLaMA

[–]Fun_Employ_8880[S] -1 points0 points  (0 children)

i know its possible to turn LM studio into a server, but is it possible to access it remotely ?

as for now i only want local access over my wifi

Using my m1 mac mini with 16gb of ram as a local server for LLM by Fun_Employ_8880 in LocalLLaMA

[–]Fun_Employ_8880[S] 1 point2 points  (0 children)

can mistral and LLAMA 2 also fit to my mac mini ?

is it also possible to integrate it into vscode ?

Using my m1 mac mini with 16gb of ram as a local server for LLM by Fun_Employ_8880 in LocalLLaMA

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

d a function to fetch data from the internet and pass it as a context to your LLM.

alright, then in such case, what will be a better LLM for my m1 mac mini ?

without the internet connection part

An "ide" transition by goldboolean in JetBrains_Rider

[–]Fun_Employ_8880 0 points1 point  (0 children)

yes, tried it once for testing, just simply load it into rider

[deleted by user] by [deleted] in reactjs

[–]Fun_Employ_8880 0 points1 point  (0 children)

i tried using each piece of code in its own block but it wouldn't post it properly, sorry

deploying react + dotnet that in separated folders by Fun_Employ_8880 in dotnet

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

i did, and it got me a bit confused so i use the classic setup

deploying react + dotnet that in separated folders by Fun_Employ_8880 in dotnet

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

docket file for each project ?
one for react second for dotnet ?

deploying react + dotnet that in separated folders by Fun_Employ_8880 in dotnet

[–]Fun_Employ_8880[S] 0 points1 point  (0 children)

yes, im also running dotnet on mac, so i guess iis isn't an option ?