Hello,
I have a problem, everytime i am trying to login after switching a profile, it creates a new user everytime, instead of fetching the session token and relogging into that user. this is happening everytime since the last 4 days. i have no errors, the authentication just doesnt fetch the player from the existing session token, which comes out as false and it logs and creates a new user everytime i stop and play the login in the editor. Before 4 days, it was working absolutely fine.
Can anyone help!! any help would be greatly appreciated.
Thanks in advance
Well, its pretty basic one from the unity auth. But here it is.
The code that is reffering to the manager script:
[SerializeField] private Button googleBtn;
[SerializeField] private Button anonymousBtn;
private void Start()
{
googleBtn.onClick.AddListener(async () =>
{
await AuthenticationManager.Instance.SwitchProfile(“google”);
});
anonymousBtn.onClick.AddListener(async () =>
{
await AuthenticationManager.Instance.SwitchProfile(“Anonymous”);
//Debug.Log(AuthenticationService.Instance.SessionTokenExists);
await AuthenticationManager.Instance.SignInAnonymouslyAsync();
});
}
The code being referred to:
private async void InitializeAsync()
{
try
{
await UnityServices.InitializeAsync();
SetupEvents();
}
catch (Exception e)
{
Debug.LogException(e);
}
}
public async Task SwitchProfile(string profile)
{
AuthenticationService.Instance.SwitchProfile(profile);
Debug.Log(AuthenticationService.Instance.Profile);
Debug.Log(AuthenticationService.Instance.SessionTokenExists);
await Task.Delay(1);
}
public async Task SignInAnonymouslyAsync()
{
try
{
await AuthenticationService.Instance.SignInAnonymouslyAsync();
Debug.Log(“Sign in anonymously succeeded!”);
Debug.Log($“PlayerID: {AuthenticationService.Instance.PlayerId}”);
}
catch (AuthenticationException ex)
{
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
Debug.LogException(ex);
}
}
It works fine for the default script, even fetches the token for that, but as soon as i switch the profile to anything random, the session token is not getting stored or it says invalid token and clears it altogether
You have to sign out the current account before switching a profile as far as I remember the docs.
Other than that I’d be careful with the button callbacks. Is there anything stopping a user from spamming the button tap-tap-tap-tap? Because this might also lead to issues. Sometimes these buttons even accidentally trigger multiple times on touchscreens because, well, touching is greasy stuff.
Make sure to disable the button while operations are “in progress” or when the button is not in a state to be used.
Your SwitchProfile method is also odd. It doesn’t await SwitchProfile but follows it up with a Task.Delay(1) which is either 1 ms or 1 tick, so practically nothing. This may happen to work at times and not at others depending on the reaction time of the services and the latency from your location to those servers.
yes, this is just a test script i made for testing.
I am disabling the buttons with a canvas overlay with sort order 10.
I even tried the ui samples from the authentication. i switched the profile there. switched he profile to random and anonymous, signed in, signed out, chked the session token, either it failed to fetch the session token, or if it finds one then this is the error i am getting:
[Authentication]: Request failed: 401, {“detail”:“The session token is not valid.”,“details”:[ ],“status”:401,“title”:“INVALID_SESSION_TOKEN”}, request-id: 025c72e8-02ac-4829-9ff3-017865fffa00
UnityEngine.Logger:Log (string,object)
i believe the error started to occor only after i upgraded the authentication package from the package manager, for now, i dont seem to find any problem with the code, becaz i am using the default docs for the login, logout, and switching profile after initializing the docs, it works ok for the default profile, but cant seem to work for any other profiles. the problem is if i am using the clones manager, it creates a new account everytime, since it cannot login using the existing session token for the profile. i cant seem to find a solution for the last 4 days.
it would rather be a great help if u can try the switching profile at ur end, and just check, if everything is working at ur end. and can u please share the authentication package version you are using. i believe i was using 2.9 or 3.0 and it was working fine until then.
Thank you.
i have been stuck at this error for the past 4 days. and i tried every possible combination i could think of, cant seem to figure out what i am doing wrong here. i believe the error only started to occur after i upgraded the auth package, and thus i tried and tested it after creating a new account and creating multiple new projects, just for testing the authentication stuff
Okay… I solved it for now.
I was having the problem when using unity editor version 6 preview, 2022.3.29f1 LTS, 2022.3.20f1 LTS using authentication package 3.3.1
now i switched to unity editor 2021.3.38f1 and installed authentication package 2.7.4 and the issue is somehow resolved for now. still don’t know what i was doing wrong. might be the core or the auth package.
anyways thanks for the help. Appreciated.