user2975535 user2975535 - 4 months ago 8
Scala Question

Session doesn't work after upgrade to Play Framework 2.5.4, Scala

After upgrading my project to Play Framework 2.5.4 from 2.4.8, I'm having issue while working with session. There are to methods in my controller to test the issue:

def test = Action { implicit request =>
Redirect(controllers.routes.Carts.test2()).withSession(new Session(Map("user" -> "customer")))
}

def test2 = Action { implicit request =>
Ok(request.session.data.toString())
}


Basically
test
method adds session and redirects to
test2
method. When I open page with test method url after redirect I'm getting what I need in the browser:


Map(user -> customer)


But if I refresh page after that I'm getting:


Map(csrfToken ->
ce1a6222484f378d38ab3534c2b400191270395d-1470238791014-c988ce3fe47259173166949a)


So, seems like session works for one request only and then overwrites with csrfToken. I have disabled all the filters. My class with filters looks like this:

class Filters @Inject() () extends HttpFilters {
val filters = Seq.empty
}


Can't understand what is wrong with my code. The same code was working fine before upgrade.

Answer

Check in ur application.conf if session.secure is true bring it to

play.http.session.secure=false