eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.89k stars 1.82k forks source link

egg-passport/egg-passport-local登录失败怎么获取错误信息? #2948

Closed lijinshanmx closed 5 years ago

lijinshanmx commented 6 years ago

const localStrategy = app.passport.authenticate('local', { successRedirect: '/', failureRedirect: '/signin', }); 怎么在登录失败的时候,传递错误信息,比如说用户名不存在或者密码错误等等,翻了好多issue和文档都找不到啊,egg-cnode里面的处理就是直接再次跳转登录页了,没办法给用户一直观的提示。。。failureRedirect回调只是一个简单的url地址,没办法获取到错误信息

egg-bot commented 6 years ago

Translation of this issue:


egg-passport/egg-passport-local How do I get an error message when I log in failed?

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.

lijinshanmx commented 6 years ago

@atian25

lijinshanmx commented 6 years ago

现在我这边的解决是在passport校验user的时候,如果校验不通过,直接throw(401, errormsg),然后在中间件中catch(next()),然后判断code,再把error信息render到view上去。不知道这样是不是符合规范。。。但是好像能解决问题。

lijinshanmx commented 6 years ago

@thonatos 能帮我看一下吗?这个怎么解决比较好?

thonatos commented 6 years ago

还没处理吧?我们把这类问题汇总一下,统一处理。

lijinshanmx commented 6 years ago

嗯嗯,希望有更好的解决方法。 @thonatos ,真是麻烦你们了。十分感谢~

coderwow commented 5 years ago

这个有解决方案吗

egg-bot commented 5 years ago

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 天内没有进展会被自动关闭。

atian25 commented 5 years ago

egg-passport-local 不要用了,直接自己写个 POST 的 Controller 处理