# Multiple account login

**URL:** <https://forum.heroiclabs.com/t/multiple-account-login/3841>\
**Category:** Local Setup\
**Tags:** authentication, sdk-unity\
**Created:** [May 4, 2023, 7:38am UTC](https://forum.heroiclabs.com/t/multiple-account-login/3841 "2023-05-04T07:38:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![UmarBhatPlaystrom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/umarbhatplaystrom/32/1635_2.png) [@UmarBhatPlaystrom](https://forum.heroiclabs.com/u/UmarBhatPlaystrom)\
**Post date:** [May 4, 2023, 7:38am UTC](https://forum.heroiclabs.com/t/multiple-account-login/3841/1 "2023-05-04T07:38:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [May 10, 2023, 3:15pm UTC](https://forum.heroiclabs.com/t/multiple-account-login/3841/2 "2023-05-10T15:15:11Z")

</div>

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](https://heroiclabs.com/docs/nakama/getting-started/console/accounts/#authentication).

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.

---

<div class="post-metadata">

**Author:** ![UmarBhatPlaystrom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/umarbhatplaystrom/32/1635_2.png) [@UmarBhatPlaystrom](https://forum.heroiclabs.com/u/UmarBhatPlaystrom)\
**Post date:** [May 11, 2023, 4:54pm UTC](https://forum.heroiclabs.com/t/multiple-account-login/3841/3 "2023-05-11T16:54:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [May 11, 2023, 6:16pm UTC](https://forum.heroiclabs.com/t/multiple-account-login/3841/4 "2023-05-11T18:16:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![UmarBhatPlaystrom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/umarbhatplaystrom/32/1635_2.png) [@UmarBhatPlaystrom](https://forum.heroiclabs.com/u/UmarBhatPlaystrom)\
**Post date:** [May 11, 2023, 7:14pm UTC](https://forum.heroiclabs.com/t/multiple-account-login/3841/5 "2023-05-11T19:14:21Z")

</div>

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](https://heroiclabs.com/docs/nakama/concepts/authentication/#google) 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](https://heroiclabs.com/docs/nakama/getting-started/configuration/#google-auth). 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

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [May 12, 2023, 10:04am UTC](https://forum.heroiclabs.com/t/multiple-account-login/3841/6 "2023-05-12T10:04:03Z")

</div>

> [@Add google credentials flag to Nakama Configuration](https://forum.heroiclabs.com/t/add-google-credentials-flag-to-nakama-configuration/3864/2):
>
> The flag was recently introduced, please ensure you’re on the latest release of Nakama (3.16.0).
