public async void InitLinkAccount()
{
var accessToken = AuthenticationService.Instance.AccessToken;
Debug.Log("Access token: " + accessToken);
if (accessToken == string.Empty)
{
Debug.LogError("Access token is null or empty. Cannot link account.");
return;
}
if(PlayerPrefs.GetInt("IsAnonymous") == 0)
{
Debug.LogError("Account is already linked.");
return;
}
if(!AuthenticationService.Instance.IsSignedIn)
{
Debug.LogError("User is not signed in.");
return;
}
await LinkWithUnityAsync(accessToken);
}
async Task LinkWithUnityAsync(string accessToken)
{
try
{
if (AuthenticationService.Instance == null)
{
Debug.LogError("AuthenticationService is not initialized.");
return;
}
await AuthenticationService.Instance.LinkWithUnityAsync(accessToken);
PlayerPrefs.SetInt("IsAnonymous", 0);
PlayerPrefs.Save();
Debug.Log("Link is successful.");
}
catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked)
{
Debug.LogError("This user is already linked with another account. Log in instead.");
// Optionally notify the user via UI.
}
catch (AuthenticationException ex)
{
Debug.LogError($"Authentication error: {ex.ErrorCode} - {ex.Message}");
// Optionally notify the user via UI.
}
catch (RequestFailedException ex)
{
Debug.LogError($"Request failed: {ex.ErrorCode} - {ex.Message}");
// Optionally notify the user via UI.
}
catch (Exception ex)
{
Debug.LogError($"An unexpected error occurred: {ex.Message}");
// Optionally notify the user via UI.
}
}
hey im trying to link my account inside the game after i signed in anonymous but this error show to me : i call my funtion inside the game from setting but give me : [Authentication]: Request failed: 401, {"detail":"unable to validate token","details":[],"status":401,"title":"PERMISSION_DENIED"}, request-id: cf8e5105-0918-4160-80be-7c908ac04538
i call my funtion InitLinkAccount inside tha game and all the thing is connect perfectly but this issue show to me and i can solve it .