Replies: 1 comment 1 reply
|
示例: @CustomStrategy()
export class LocalStrategy extends PassportStrategy(Strategy) {
getStrategyOptions(): IStrategyOptions {
return {
usernameField: "username",
passwordField: "password",
passReqToCallback: true,
session: false,
};
}
async validate(req, username: string, password: string) {
const { captcha } = req.body;
// 这里先校验验证码,再校验用户名密码
if (!captcha) {
return false;
// 或者 return [false, { message: "验证码错误" }];
}
return user;
}
}Koa 场景下,Midway 的 passport 组件会创建一个兼容 Express 的 req 对象, 另外验证码错误更建议返回 |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Describe the problem(描述问题)
业务中需要校验请求参数中带过来的验证码,在Strategy validate 参数中拿不到,在config passport设置passReqToCallback:true也没效,请问如何才能拿到body中的其他参数呢?
Midway Versions(Midway 版本)
v4
All reactions