Closed lijinshanmx closed 5 years ago
Translation of this issue:
const localStrategy = app.passport.authenticate('local', { successRedirect: '/', failureRedirect: '/signin', });
How to pass the error message when the login fails, for example, the user name does not exist or the password is wrong, etc., many issues and documents can not be found, the processing inside the egg-cnode is to jump to the login page again. There is no way to give the user an intuitive reminder. . . The failureRedirect callback is just a simple url address, there is no way to get the error message.
@atian25
现在我这边的解决是在passport校验user的时候,如果校验不通过,直接throw(401, errormsg),然后在中间件中catch(next()),然后判断code,再把error信息render到view上去。不知道这样是不是符合规范。。。但是好像能解决问题。
@thonatos 能帮我看一下吗?这个怎么解决比较好?
还没处理吧?我们把这类问题汇总一下,统一处理。
嗯嗯,希望有更好的解决方法。 @thonatos ,真是麻烦你们了。十分感谢~
这个有解决方案吗
Hello @lijinshanmx. Please provide a reproducible example following the instruction.
Issues labeled by Need Reproduce
will be closed if no activities in 7 days.
@lijinshanmx,请根据这个说明提供最小可复现代码。
如果在 7 天内没有进展会被自动关闭。
egg-passport-local 不要用了,直接自己写个 POST 的 Controller 处理
const localStrategy = app.passport.authenticate('local', { successRedirect: '/', failureRedirect: '/signin', });
怎么在登录失败的时候,传递错误信息,比如说用户名不存在或者密码错误等等,翻了好多issue和文档都找不到啊,egg-cnode里面的处理就是直接再次跳转登录页了,没办法给用户一直观的提示。。。failureRedirect回调只是一个简单的url地址,没办法获取到错误信息