Closed lehni closed 6 years ago
Unfortunately it looks like this is currently only possibly with some nasty cacks inside koa-session
. I've created an issue there to make it possible, let's see how it goes:
The only workaround I see so far is to (ab)use the session.before.beforeSave(ctx)
hook to get access to the ctx
object, temporarily store it on the custom store
so the store can access it in its set()
method. This sounds dodgy to me though, and I'm wondering if there isn't an async
in between somewhere that would mean that we may get the wrong values for ctx
in set()
when multiple requests are being received.
As proposed by @koskimas & @ollisal:
The koa's middleware are perfect for transaction management:
This would allow other middleware to use the transaction too. For example it's sometimes good (or even necessary) that the session update query takes part in the same transaction. This way the session middleware could use
ctx.trx
if it exists.