这是我的代码:
def getUser(implicit request:play.api.mvc.Request[Any],env:MyEnviroment): Future[User] = {
SecureSocial.currentUser.map {
maybeUser =>
val userId = maybeUser.map(_.main.userId).getOrElse("unknown")
val user: User = UserAccessor.finduserbyid(userId)
Future.successful(user)
}
}
答案 0 :(得分:0)
假设SecureSocial.currentUser
返回Option
,您可能需要以下内容:
SecureSocial.currentUser.map {
maybeUser =>
val userId = maybeUser.map(_.main.userId).getOrElse("unknown")
val user: User = UserAccessor.finduserbyid(userId)
Future.successful(user)
}.getOrElse(Future.failed(new Exception("No current user"))