User Nakama ID

How client should find the user id stored in database?

@SinaZK Can you add more detail to your question? Each user is assigned an ID when their account is created. What do you mean “find the user id stored”? Find based on what?

I mean every chat message has sender_id and i want to separate my messages and other group messages and i want to know my nakama user id. Another example is when i want to list my groups i need nakama user id.

We use authenticate device for auth and it just respond the token not the user id.

@SinaZK The session object in Nakama will give you back the user ID:

https://github.com/heroiclabs/nakama-dotnet/blob/master/src/Nakama/ISession.cs#L65

This is covered with examples in the Unity client sdk guide:

https://heroiclabs.com/docs/unity-client-guide/#sessions

You can also access the user ID from the context object in server-side logic. For Lua it looks like:

local nk = require("nakama")
local function custom_rpc_func(context, payload)
    nk.logger_info(("User id: %q"):format(context.user_id))
end
nk.register_rpc(custom_rpc_func, "some_id")

And in Go code:

func CustomRpcFunc(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
    userID, _ := ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)
    logger.Info("User id: %s", userID)
    return "", nil
}

All of this is covered in the documentation. Hope it helps.

Tnx. İ implemented a rpc func and passed Id to client.

@SinaZK This is not needed. I do not recommend this approach because it complicates your game client code and is wholly unnecessary because the client sdk already has the user ID as soon as the user has authenticated to obtain a session.

Ok I’m going to use the session. Tnx for your replies.

1 Like