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.