Fetching users by customId

Hi,

we implemented a custom authentication flow using our existing backend.
Using a BeforeAuthenticateCustom hook, we set the customId of the user to the user-id from our existing backend.

Now we would like to implement an rpc method that we can call from our existing backend. Is there any way we can get nakama accounts by their customId?

I only found methods to get an account by userId (accountGetId), facebookId (usersGetId) or username (usersGetUsername).

Is this currently just not possible without keeping track of userId and nakama-userId on our side, or am I missing something here?

Thanks!

Hey @anselm, we definitely recommend authenticating to Nakama using your custom ID from your backend. Then you will want to retain the session object to make future calls to Nakama. If there is something that really prevents you from doing that, the lesser option is to store the custom id as a username for your Nakama user, and then query off that username. Lastly, we do not recommend writing a custom query to retrieve an account by custom_id because it’s intentionally not indexed in the database.

Hi @lugehorsam

Then you will want to retain the session object to make future calls to Nakama

That’s what we do on the client-side, right?

What I am trying to do, is provide some RPC methods, that we can call server to server (using an http_key).

Lastly, we do not recommend writing a custom query to retrieve an account by custom_id because it’s intentionally not indexed in the database.

I was assuming that the custom_id must be indexed because AuthenticateCustom must be able to efficiently check for the existing account. Also, it must be unique, right?

the lesser option is to store the custom id as a username for your Nakama user, and then query off that username

If the username is guaranteed to be unique, that is a valid wordaround for us :slight_smile:

@anselm I don’t know the full details of your service but it is valid to store the session tokens in your service.

Yes apologies, custom_id is indexed and must be unique, but we still do not recommend writing custom SQL for this use case.

1 Like