a.haberberger
a.haberberger

Reputation: 1

Accessing User.currentUser from Boot.scala onAboutToShutdownSession

I'm working on an eShop project in Lift right now. For convenience reasons every user that visits the shop is assigned a persistent ProtoUser entry in Mapper. This entry is flagged temporary. I now have to delete the DB-entry on session termination using onAboutToShutdownSession

Obviously i don't have access to User.currentUser there, as i'm outside a session. (?) I still have the LiftSession Reference in my function.

The question is: How can I access the currentUser (or even currentUserId) SessionVar from either the context of LiftSession or Boot.scala

Thanks for your answers!

Andreas

Upvotes: 0

Views: 302

Answers (1)

David Pollak
David Pollak

Reputation: 7015

You can't access a SessionVar outside a session.

If you've constructed a function during the servicing of a request, you can do something like:

val id = User.currentUserId.get
val f: () => Unit = () => {
   id.foreach{realId => deleteFromDatabase(realId)
}

Because the id val is captured within the scope of a request and f closes over scope, the value of User.currentUserId will be captured and the function will be able to delete the user from the database.

Upvotes: 1

Related Questions