Hi!
I’m trying to put some features in my game, like change password and add username & password when the player is using another provider. But I don’t want to show the add button when the player already have username & password OR i only want to show the change password button when user had username.
I tried to check if PlayerInfo.Username isn’t empty, works when I login with Username but when i login with Google and this account already had username & password the Username property is empty.
To get if user already linked with apple or google, this works very well.
public bool IsLinkedAtGoogle()
{
var playerInfo = AuthenticationService.Instance.PlayerInfo;
if (playerInfo != null &&
playerInfo.Identities.Count > 0 &&
playerInfo.Identities.Any(i => i.TypeId.Contains("google")))
{
return true;
}
return false;
}
public bool IsLinkedAtApple()
{
var playerInfo = AuthenticationService.Instance.PlayerInfo;
if (playerInfo != null &&
playerInfo.Identities.Count > 0 &&
playerInfo.Identities.Any(i => i.TypeId.Contains("apple")))
{
return true;
}
return false;
}
Someone can help me with this “check”?
Thanks!
What I found is that some of these properties are not available or outdated unless you specifically request them with an async call. Something like GetPlayerInfoAsync (can’t recall what it was exactly) and then this will fill in those fields if the sign-in was “automatic” by using SignInAnonymouslyAsync.
If that’s not it, I have a hunch that Username property may be specific to the Username/Password style of sign in and isn’t used by any other ID provider. These may have to be obtained through ID provider specific calls, and there’s a chance this is not part of the Unity Service API but rather requires making those webrequests yourself using the provider’s API.
Firstly thanks for the answer CodeSmile.
I already tried to GetPlayerInfo after I authenticate with Google but without success unfortunally.
Probably I’ll check the identifiers using Cloud Code because there we had this info:

I don’t like the idea to call a Cloud Code service only because of that, but if there’s no other way, let’s go anyway.
EDIT —
If anyone needs to do this and there really is no other way, I solved this creating this script on Cloud Code:
const _ = require("lodash-4.17");
const { PlayerAuthenticationApi } = require("@unity-services/player-auth-1.0");
module.exports = async ({ params, context, logger }) => {
const { projectId, playerId, accessToken } = context;
const cloudAuthApi = new PlayerAuthenticationApi(context);
let result = await cloudAuthApi.getPlayer(playerId, projectId);
if (result.data != null && result.data.usernamepassword)
return true;
return false;
};
1 Like