compose slick dbaction with authenticated action

2020-07-26 14:19发布

问题:

I have my custom authenticated action that is like

def Authenticated(rights: String*) = new ActionBuilder[MyAuthenticatedRequest] {
  ***
}

In my controller I use this action to check the user has the right to view the page

def password = Authenticated(UserRights.USER) { implicit request: MyAuthenticatedRequest[_] =>
  Users.findById(request.account.id) match {
    case Some(user) => Ok(views.html.settings.password(frontUser, user))
    case _ => NotFound
  }
}

My oject Users uses slick to retrieve the user in the database

def findById(id: Long)(implicit s: Session): Option[User] = users.where(_.id === id).firstOption

In my controller I have an error

could not find implicit value for parameter s: play.api.db.slick.Config.driver.simple.Session

This is due to the fact that I have to open a session in my controller before querying the database.

I would like to use DBAction that is provided by play-slick and compose it with my authenticated action but I have some problems understanding how action composition works