gpt4 book ai didi

swift - Vapor 如何通过电子邮件查找用户

转载 作者:行者123 更新时间:2023-12-04 14:14:38 27 4
gpt4 key购买 nike

如何在登录方法中通过电子邮件在 vapor 中正确找到用户并返回该用户或返回错误,我试过:

    func login(_ req: Request) throws -> Future<User> {
return try req.content.decode(User.self).map { loginUser in
let query = User.query(on: req)
return query
.filter(\.email == loginUser.email)
.first()
.flatMap { user in
return user!.save(on: req)
}

}
}

但是我得到了

Cannot convert return expression of type 'EventLoopFuture' to return type 'User'

最佳答案

func login(_ req: Request) throws -> Future<User> {
return try req.content.decode(User.self).flatMap { loginUser in
return User.query(on: req)
.filter(\.email == loginUser.email)
.first()
.unwrap(or: Abort(.notFound, reason: "User not found"))
}
}

关于swift - Vapor 如何通过电子邮件查找用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61622814/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com