如何在未来获得securesocial.currentUser?

时间:2018-01-20 02:40:59

标签: scala securesocial

这是我的代码:

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)
  }

}

1 个答案:

答案 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"))