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.