0

I have an issue with React when I try to retrieve the value of return.

The code:

export const RuoloOnline = (jwt) => {
    axios.get("http://localhost:1337/api/users/me",
        {
            headers: {
                "Authorization": `Bearer ${jwt}`
            }
        }
    ).then((res) => { return (res.data.ruolo) }).catch(() => {return 0}) 

if I put a console.log the value is correctly viewed. If I try to call this function outside the file, it generates an undefined return.

2

1 Answer 1

0

Try using asynchronous function calls instead of this function. Your modified code will be

export const RuoloOnline = async (jwt) ={
    return await axios.get("http://localhost:1337/api/users/me",
       {
           headers: { 
                "Authorization": `Bearer ${jwt}`
            }
        }
   );
}

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.