How to pass data from before hook to after hook

How can I pass data from before hook to after hook for Authenticate hooks in Lua runtime?
Here’s my test code -

local function before_authenticate_custom(context, payload)
    print("******* before authenticating user -- payload : ")

     payload.user_data = {
        data = "test data"

    return payload
nk.register_req_before(before_authenticate_custom, "AuthenticateCustom")

Here are the server logs showing error -

******* before authenticating user -- payload :
{"level":"error","ts":"2019-08-14T14:54:33.319+0530","msg":"Could not unmarshall result to request","result":{"account":{"id":"41a90600df5005c302498cf2231fcf8a33f1c5c9"},"create":true,"user_data":{"data":"test data"}},"error":"unknown field \"user_data\" in api.AuthenticateCustomRequest","stacktrace":"*RuntimeProviderLua).BeforeReq\n\t/go/src/\\n\t/go/src/\*ApiServer).AuthenticateCustom.func1\n\t/go/src/\\n\t/go/src/\*ApiServer).AuthenticateCustom\n\t/go/src/\\n\t/go/src/\\n\t/go/src/\\n\t/go/src/\*Server).processUnaryRPC\n\t/go/src/\*Server).handleStream\n\t/go/src/\*Server).serveStreams.func1.1\n\t/go/src/"}

This is a great question. We are adding this in for 2.7.0.

In the meantime, what kind of information are you thinking of passing through from one function to another?

@mofirouz, great news :+1:
So, our use case is, we need to fetch player details from other server and initialize a new user or update already existing user’s information on this game server.
Other server’s player_id is used for custom auth on game server.
If no player data is received from other server in before hook, then we are not letting that user authenticate on the game server.
So, This will require two API calls
First, in the before hook to fetch player details from other server.
And second, in after hook to fetch player details from other server and then update the user’s details in game server upon successful authentication.
All this could be achieved with a single API call in the before hook if we can pass the fetched player data from before hook to after hook.