Link facebook and authenticate facebook

Hello

Please clear out this small confusion as to when should we call LinkFacebook and AuthenticateFacebook
We are using LinkFacebook to create a link between a user created through device ID (play as guest)

Problem (1): checking if user has log in for the first time or not
on client side:

device authentcation (play as guest)
linkFacebookAsync()
AuthenticateFacebookAsync()
this how we are doing things right now

on server side:

BeforeAuthDevice   (before hook)
AfterAuthDevice    (after hook)

BeforeAuthFacebook (before hook)
AfterAuthFacebook  (after hook)

BeforeLinkFacebook (before hook)
AfterLinkFacebook (after hook)

When client clicks on Facebook Login (the first time) it calls functions in this way:

1) BeforeAuthDevice
2) AfterAuthDevice 
3) BeforeLinkFacebook
4) AfterLinkFacebook

How can we check that the user has logged in for the first time?

- if we use nk.AuthenticateFacebook in BeforeLinkFacebook, it tell us that the created bool is true if we do GetAccount, but creates a conflict with the client side
- if we use nk.AuthenticateFacebook in AfterLinkFacebook, it tell us that the created bool is false if we do GetAccount, but creates no conflict with the client side

and due to this, in AfterAuthFacebook, the out.Created field is always false regardless of the fact that the user is log in for the first time or not the first time
through which function can we check if this user has signed in for the first time or not? what we are doing is we check out.Created in AfterAuthenticateFacebook and its false. Even when the link is made or not.

does authenticate facebook check your link with facebook with your device id and returns the values or is it some other way around??

Problem (2): multiple devices and same account

one more confusion: Lets assume the following scenario
– one user has iphone 10
– he logs in with facebook

-- functions performed are:
	-> device authentcation (play as guest)
	-> linkFacebookAsync()
	-> AuthenticateFacebookAsync()

-- the same user shifts from iphone 10 to iphone 11
-- he downloads and instals the game and logs in with facebook
-- functions perfomed are:
	-> device authentcation (play as guest)
	-> linkFacebookAsync()
	-> AuthenticateFacebookAsync()
		
-- running the same steps as in iphone 10 this scenario would give an error because one fb account cannot be linked to different devices

In your original steps here you don’t need to call AuthenticateFacebookAsync. After linking the Facebook account has been validated and the ID stored against the user making the LinkFacebookAsync call.

When linking there is no account creation. Linking is only possible against accounts that already exists, so linking cannot create accounts. Account creation is only possible in Authenticate* calls.

Yes, it would. You should handle this by first trying a Facebook authenticate with the create flag set to false. This will make sure the authenticate call only succeeds if the FB account is already linked somewhere.

If it succeeds then you can decide (or let the user choose) if you want to proceed with that account or a local device one. Perhaps you can link the new device to that existing account, so you end up with an account that has Facebook and 2 device IDs.

If it fails then that Facebook account is new to Nakama and you can link it to the current device ID account.

Thank you for your response.

If we have a button on our UI then how can we make sure on the client side whether to call LinkFacebookAsync or AuthenticateFacebookAsync ?

And if a user changes his device, would we have to unlink his old device and link him to the new device or something else ?

I’m not sure what you mean by “make sure”. You just make the calls I described in the order I suggested, or another order that suits your needs. The user accounts system is designed to be flexible and allow you to create/link/unlink as needed.

That’s up to you. Nakama has no way to know if some device ID is not expected to be seen ever again. This is usually something you want to give the user control over since your game client also can’t know if some old device is no longer expected to be used.

so you end up with an account that has Facebook and 2 device IDs

How is this handled? What happens to the data already stored under the 2nd device ID’s account? Is it merged with the 1st device + Facebook account? How is the merge handled?

You cannot link a device ID with an existing account to another existing account - to do so you’ll have to unlink the device ID from first account, then link to new account, nothing is built-in in Nakama for this.

So it leaves an account with no ID at all, right? Like a ghost account.

No you cannot have an account without an ID. You’ll need to attach a different ID, or delete the account. Note deleting the account is only available via the server runtime - which is usually where this logic should reside.

you’ll have to unlink the device ID from first account

So if this account has only a device ID…

So if this account has only a device ID…

the answer is

You’ll need to attach a different ID, or delete the account. Note deleting the account is only available via the server runtime - which is usually where this logic should reside.

I think I understand, so I’ll summarize:

Situation:

  • Device A creates Account A with Device ID A.
  • Device A links Facebook ID to Account A.
  • Device B creates Account B with Device ID B.

To link all 3 IDs to Account A:

  • Link a fake ID to Account B
  • Unlink Device ID B from Account B
  • Link Device ID B to Account A

To link all 3 IDs to Account B:

  • Link a fake ID to Account A
  • Unlink Device ID A from Account A
  • Unlink Facebook ID from Account A
  • Link Device ID A to Account B
  • Link Facebook ID to Account B

Am I correct?

Yep that’s correct if you want to do it all on the client side. If you do this logic on the server (as an RPC), then you can delete Account A without having to do the whole link fake ID process.

1 Like