繁体   English   中英

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

[英]Loopback Logout from React returns 401 (Unauthorized)

我尝试从前端使用axios尝试注销时收到401 (Unauthorized)错误,即使注销可以从回送用户界面或邮递员使用

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请求所期望的那样)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM