从 React 环回注销 returns 401(未授权)

Loopback Logout from React returns 401 (Unauthorized)

当我尝试从前端使用 axios 注销时出现 401 (Unauthorized) 错误,即使 注销可以从 Loopback 用户界面或 Postman

handleLogout() {
   let access_token = localStorage.getItem('access_token')
   axios.post('http://localhost:3000/api/Users/logout', {
     data: access_token
   })
 }

我也试过了

axios.post('http://localhost:3000/api/Users/logout', {
  access_token: access_token
})

我做错了什么?

如果您的评论中指出令牌需要作为查询字符串参数,请尝试以下操作:

handleLogout() {
  axios.post(`http://localhost:3000/api/Users/logout?access_token=${localStorage.getItem('access_token')}`);
}

虽然你肯定 POST 方法是预期的?没有数据被传递(正如人们对 POST 请求所期望的那样),尽管如果可以通过令牌识别用户可能有意义。