[Vuejs]-Getting error 401 (Unauthorized) when trying to fetch data

0đź‘Ť

Authentication Middleware: Ensure that the authentication middleware is correctly set up in your C# backend. If you’re using ASP.NET Core, this would typically be done in the Startup.cs file.

Authorize Attribute: Check if your API endpoint (or its controller) is decorated with the [Authorize] attribute. If it is, it means the endpoint requires authentication.

Token in Request: Since you mentioned you’re using a token for authentication, ensure that your Vue application is sending this token with the request.

axios.get('http://localhost:27235/api/lookup', {
    headers: {
        'Authorization': 'Bearer YOUR_TOKEN_HERE'
    },
    withCredentials: true
});

Leave a comment