Hi,
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 : ")
print(nk.json_encode(context))
print("******************")
print(nk.json_encode(payload))
print("******************************************")
payload.user_data = {
data = "test data"
}
return payload
end
nk.register_req_before(before_authenticate_custom, "AuthenticateCustom")
Here are the server logs showing error -
******* before authenticating user -- payload :
{"client_ip":"192.168.1.38","env":{},"execution_mode":"before","query_params":{}}
******************
{"account":{"id":"41a90600df5005c302498cf2231fcf8a33f1c5c9"},"create":true}
******************************************
{"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":"github.com/heroiclabs/nakama/server.(*RuntimeProviderLua).BeforeReq\n\t/go/src/github.com/heroiclabs/nakama/server/runtime_lua.go:1206\ngithub.com/heroiclabs/nakama/server.NewRuntimeProviderLua.func3.5\n\t/go/src/github.com/heroiclabs/nakama/server/runtime_lua.go:248\ngithub.com/heroiclabs/nakama/server.(*ApiServer).AuthenticateCustom.func1\n\t/go/src/github.com/heroiclabs/nakama/server/api_authenticate.go:41\ngithub.com/heroiclabs/nakama/server.traceApiBefore\n\t/go/src/github.com/heroiclabs/nakama/server/api.go:509\ngithub.com/heroiclabs/nakama/server.(*ApiServer).AuthenticateCustom\n\t/go/src/github.com/heroiclabs/nakama/server/api_authenticate.go:55\ngithub.com/heroiclabs/nakama/apigrpc._Nakama_AuthenticateCustom_Handler.func1\n\t/go/src/github.com/heroiclabs/nakama/apigrpc/apigrpc.pb.go:1006\ngithub.com/heroiclabs/nakama/server.StartApiServer.func1\n\t/go/src/github.com/heroiclabs/nakama/server/api.go:101\ngithub.com/heroiclabs/nakama/apigrpc._Nakama_AuthenticateCustom_Handler\n\t/go/src/github.com/heroiclabs/nakama/apigrpc/apigrpc.pb.go:1008\ngithub.com/heroiclabs/nakama/vendor/google.golang.org/grpc.(*Server).processUnaryRPC\n\t/go/src/github.com/heroiclabs/nakama/vendor/google.golang.org/grpc/server.go:971\ngithub.com/heroiclabs/nakama/vendor/google.golang.org/grpc.(*Server).handleStream\n\t/go/src/github.com/heroiclabs/nakama/vendor/google.golang.org/grpc/server.go:1250\ngithub.com/heroiclabs/nakama/vendor/google.golang.org/grpc.(*Server).serveStreams.func1.1\n\t/go/src/github.com/heroiclabs/nakama/vendor/google.golang.org/grpc/server.go:690"}