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;
}