Multiple account login

HI! We are developing a unity game where, users can login using Google, Facebook and Apple. When the player is already authenticated using google (for example) and he wants to also connect apple, I want it to succeed in 2 cases:

  • apple account that he is trying to connect is free (isn’t connected to any other user)
  • apple account is linked to the same Nakama user that the google is linked to

In other cases I want to get exception. As far as I investigated there is only one type of exception that Nakama sdk (for unity at least) throws and that is ApiResponseException. The only difference is that it has different status codes of exception. Somehow I found out that status code for Account Already In use is 409, so I can catch it that way, but is this the way? Aren’t there any other options?

Final questions:
How to manage multiple social networks sign in to the same Nakama user? Do I have to have a single Session object for them? Do I have to use “Authenticate” method for each time when player logins to new social network (assume that they are connected to same Nakama user)?

I am not sure if I explained it well, so here is the flow:
player presses “log in Google” → he gets logged in google, and then into nakama using AuthenticateGoogleAsync method → he presses “log in Apple” → what method should I use here? Authenticate? Link? How do I know if an account is free so I can link it, or is it other user, so that when he logs in I switch his saves to that new account.

As you might have noticed, I am weak in all that server stuff:( but I am open to reasearch!

Hello @UmarBhatPlaystrom

If an account is created using one of the provider authentication functions (e.g.: AuthenticateGoogle), upon successful authentication, the account will be automatically linked to that provider. You should be able to see the linked id in the Nakama Console, in the user account info. See Heroic Labs Documentation | Accounts.

If another linked user with the same username or google_id exists, it’ll fail with the 409 error at creation. To link subsequent accounts, you’d use the Link* APIs, which will tie the user account to that provider, but not authenticate it.

You should have a single session object regardless of how many social providers an account is tied to.

For your particular exaple, you’d use the LinkApple to tie the apple id to the Nakama Account. If an account already exists with that apple id, a 409 error will also be returned.

Hope this answers your questions.

Hello @sesposito.
I just debugged a bit and found out that when I try to link another account, I get Error code 409 indeed, but if I have a google account linked and I am trying to link another google account (that is not registered in Nakama yet) I get no errors and google ID field in User Account/Authentication tab just gets overrided. That is not what I expect actually) I expect some type of exception or smth. Like to do that player has to UNlink the current google account and link a new one then.

I am doing something wrong? Can I check somehow if player already has google account linked?
P.S. I am talking about Google auth just for example, other social providers work the same way

You’re right, this is to allow overriding the field if needed but it’ll only work if, as you say, the google id hasn’t been taken yet. You can check whether the user already has a provider set with AccountGet, it’ll include fields with the linked provider ids.

Yep, I am sorry. Actually I used custom id. By getting user information using client.GetAccountAsync(); I can access all the social providers’ id’s except device id - that field is private:)
Anyway, I don’t need that, because I decided to use Google authentication using GPGS. But I got a 401 error, while trying to sign in. Later, after some research I found out that to use GPGS I need to additionally configure my Nakama instance.
Referring documentation it says that I need to obtain Server Side access (which i’ve already obtained✅). And update some google_auth.credentials_json flag that is mentioned here. But I didnt found any extra information about that flag. How should this json look and where should I put it? In my server configuration I didn’t found any references to google_auth.credentials_json.
Thank you, @sesposito