localfunctioninitialize_user(context,payload)ifpayload.createdthen-- Only run this logic if the account that has authenticated is new.localchangeset={coins=10,-- Add 10 coins to the user's wallet.gems=5-- Add 5 gems from the user's wallet.artifacts=0-- No artifacts to start with.}localmetadata={}nk.wallet_update(context.user_id,changeset,metadata,true)endend-- change to whatever message name matches your authentication type.nk.register_req_after(initialize_user,"AuthenticateDevice")
funcInitializeUser(ctxcontext.Context,loggerLogger,db*sql.DB,nkNakamaModule,out*api.Session,in*api.AuthenticateDeviceRequest)error{ifout.Created{// Only run this logic if the account that has authenticated is new.
userID,ok:=ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)if!ok{return"",errors.New("Invalid context")}changeset:=map[string]interface{}{"coins":10,// Add 10 coins to the user's wallet.
"gems":5,// Add 5 gems from the user's wallet.
"artifacts":0,// No artifacts to start with.
}varmetadatamap[string]interface{}iferr:=nk.WalletUpdate(ctx,userID,changeset,metadata,true);err!=nil{// Handle error.
}}}// Register as after hook, this call should be in InitModule.
iferr:=initializer.RegisterAfterAuthenticateDevice(InitializeUser);err!=nil{logger.Error("Unable to register: %v",err)returnerr}
Code snippet for this language TypeScript has not been found. Please choose another language to show equivalent examples.