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?
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.
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
but there is no other way to get user by custom id? Or i’m missing something? In our case we need to block user by their custom id and i see nothing to do this except custom sql
Probably the most frustrating thing about Nakama is that the developers constantly think they know all use cases of the software, and instead of trying to actually help with your issues, run interference.
For anyone interested, here is the Go code I used to fetch users by custom_id. Since custom_id is indexed and unique, it is perfectly safe to do.
func getUserId(ctx context.Context, db *sql.DB, customId string) (string, error) {
var userID string
query := `
SELECT u.id
FROM users u
WHERE u.custom_id = $1`
if err := db.QueryRowContext(ctx, query, customId).Scan(&userID); err != nil {
if err == sql.ErrNoRows {
return "", nil
}
return "", err
}
return userID, nil
}