search

Home  >  Q&A  >  body text

GET http://localhost:3000/api/auth/user/:id 401 (Unauthorized)

I'm using vue3 with axios and prisma but I'm having trouble getting user information.

My postman request works (http://localhost:3000/api/auth/user/7), but my axios request does not.

Can you help me?

async created () {
        const response = await axios.get('http://localhost:3000/api/auth/user/:id', {
            headers: {
                Authorization: 'Bearer ' localStorage.getItem('token')
            }
            
        });
        console.log('ici');

        
    }

P粉232409069P粉232409069257 days ago464

reply all(1)I'll reply

  • P粉322106755

    P粉3221067552024-03-20 15:37:00

    axios does not support URL parameters.

    One solution is to use template strings to build the request URL.

    For example:

    function getID(id) {
        const response = await axios.get(`http://localhost:3000/api/auth/user/${id}`,{
              headers: {
                  Authorization: 'Bearer ' localStorage.getItem('token')
              }
        });
    }
    
    // getID(7);
    

    reply
    0
  • Cancelreply