GET http://localhost:3000/api/auth/user/:id 401 (Unauthorized)
P粉232409069
P粉232409069 2024-03-19 16:49:19
0
1
406

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粉232409069
P粉232409069

reply all(1)
P粉322106755

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);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!