User does not stay logged in

Hey, I’m trying to make it so that when a user is logged in, restarts the application, I can have the user logged in automatically again, but I can’t seem to get it working.

Backendless.UserService.LoggedInUserObjectId() (and to that extend, Backendless.UserService.CurrentUser ) are always empty/null.

After logging in, I call Backendless.UserService.IsValidLoginAsync(); which returns true, so that seems to go well.

The stayLoggedIn argument is also set to true : Backendless.UserService.LoginAsync(username, password, true);

Cookie based authorization and Enable session timeout (at 2592000 seconds) are enabled as well.

.Am I missing something? Logging is works fine in itself tho.

Backendless Version (3.x / 5.x, Online / Managed / Pro )

Latest version that comes with the free plan.

Client SDK (REST / Android / Objective-C / Swift / JS )

I’m using Unity/C# with the latest .NET SDK from .NET-SDK/Projects/BackendlessUnitySDK/UnityPackage at master · Backendless/.NET-SDK · GitHub and I am following the following example: Backendless Login API - Backendless SDK for .NET API Documentation

Unity 2021.1.26f1

Application ID

CB5F0D27-C339-A133-FFFF-06A6F3EC8700

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

Once I logged in with a user, the second time the user is always logged in (if the session is not expired) after the application is restarted

Actual Behavior

The user/loggedInObjectID is always null and doesn’t persist, so I can’t automatically log in a user a second time.

Be descriptive: “it doesn’t work” does not describe what the behavior actually is – instead, say “the request returns a 400 error with message XXX”. Copy and paste your logs, and include any URLs.

Reproducible Test Case

The following code is used and reproduces the issue:

		public async Task<IUser> Login(string username, string password)
		{
			if (!backendlessManager.Initialized)
			{
				backendlessManager.Initialize();

				await UniTask.WaitUntil(() => backendlessManager.Initialized);
			}

			string loggedInUserObjectID = Backendless.UserService.LoggedInUserObjectId();

			if (string.IsNullOrWhiteSpace(loggedInUserObjectID))
			{
				Debug.Log("No user logged in. Attempting to log in..");
				BackendlessUser user = await Backendless.UserService.LoginAsync(username, password, true);

				loggedInUserObjectID = user.ObjectId;
			}

			bool loggedInUser = await Backendless.UserService.IsValidLoginAsync();
			if (loggedInUser)
			{
				Debug.Log("Valid login! YAY!");
			}

			CurrentUser = await Backendless.Data.Of<BackendlessData.Users>().FindByIdAsync(loggedInUserObjectID, 2);

			return CurrentUser;
		}

Hello @Joey_Fladderak

Thanks for posting this.
I just created an internal ticket BKNDLSS-26899 to check this behaviour and our engineer will take a look into it as soon as possible.

Regards, Vlad

Hello, @Joey_Fladderak.

We examined your problem, the problem was really there, it has already been fixed.
Changes will be added to nugget-package with the next release of the .NET-SDK.

Best Regards, Nikita.

Hi @Nikita_Fedorishchev,

That’s great news! Any indication when this next release is planned?

Additionally, as I am new to backendless. Do you guys also update the Unity package on Github?

Regarding the date of the planned release (for nugget packages), I cannot tell you for sure yet.

Best Regards, Nikita.

Hi @Nikita_Fedorishchev,

I was wondering if this fix was included in the 6.2.3.0 Unity Package on Github? Because if I use the following line, with stayLoggedIn set to true, I am unable to log in on Android. Also within the Unity Editor the user does not stay logged in, but I am able to properly log in.

Backendless.UserService.LoginAsync(username, password, true);

Hello @Joey_Fladderak

I’ve created an internal ticket BKNDLSS-28752 to investigate this question.

Regards

1 Like

Is there any ETA on this? I am currently working on the backend(less) features of our app, that will go live in September.

I will need to create a workaround if this is not fixed by then.

Hi @Joey_Fladderak

I believe it will be fixed on this month, once it’s released we notify you here

Regards, Vlad

1 Like

Hello, @Joey_Fladderak.

Sorry for such a long wait.
The problem was fixed a long time ago. And it works in .NET environment.
However, when running the app in Unity, it would clean up its local files, which turned out to be why stayLoggedIn didn’t work in Unity.
We have released a new version of unitypackage(6.2.4.0). Import it into your project, everything should work now.

Best Regards, Nikita.

Thanks @Nikita_Fedorishchev

So far it seems to be working. I seem to encounter another issue, but I will open a new topic for that.