• Hello! i am trying to use a react application to fetch data from Learndash plugin using the JWT auth, but can’t make work. Here is a piece of the code:

    function Dashboard() {
      const [users, setUsers] = useState([]);
      const [posts, setPosts] = useState([]);
    
      useEffect(() => {
        const token = localStorage.getItem('jwt_token');
        fetch('https://localhost/wordpress/wordpress/wp-json/ldlms/v2//users', {
          headers: {
            'Authorization': 'Bearer ' + token
          }
        })
          .then(response => response.json())
          .then(data => setUsers(data))
      }, []);
    
      useEffect(() => {
        const token = localStorage.getItem('jwt_token');
        fetch('https://localhost/wordpress/wordpress/wp-json/wp/v2/posts', {
          headers: {
            'Authorization': 'Bearer ' + token
          }
        })
          .then(response => response.json())
          .then(post_data => setPosts(post_data))
      }, []);
          
      return (
        <>
         {users.map((user, index) => {
            if(index === 0){
                return (

    What am i doing wrong? Any help will be much appreciated ??

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to use with React?’ is closed to new replies.