parse-community / parse-community/Parse-SDK-dotNET
ParseClient.Instance.GetCurrentUser() returns null when closing and restarting the app
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 335
- Forks
- 258
- PR merge metrics
- No merged PRs in 30d
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest versions of Parse Server and the Parse .NET SDK.
Hello and first of all thank you for your outstanding work!
I'm building a cross-platform app for Android and iOS using Xamarin.Forms.
The issue I'm running into is that ParseClient.Instance.GetCurrentUser() returns null if I close and restart my app.
I initialize the ParseClient in the following way:
public partial class App : Application
{
public App()
{
MetadataMutator metadataMutator = new MetadataMutator
{
EnvironmentData = new EnvironmentData { OSVersion = Environment.OSVersion.ToString(), Platform = Device.RuntimePlatform, TimeZone = TimeZoneInfo.Local.StandardName },
HostManifestData = new HostManifestData
{
Version = this.GetType().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion,
Name = this.GetType().Assembly.GetName().Name,
ShortVersion = this.GetType().Assembly.GetName().Version.ToString(),
Identifier = AppDomain.CurrentDomain.FriendlyName
}
};
ParseClient parseClient = new ParseClient(new ServerConnectionData
{
ApplicationID = Constants.ApplicationId,
Key = Constants.Key,
ServerURI = Constants.ServerUri
},
new LateInitializedMutableServiceHub { MetadataController = metadataMutator },
metadataMutator);
parseClient.Publicize();
Console.WriteLine(String.Format("Is currentUser null BEFORE hardcoded login? {0}", ParseClient.Instance.GetCurrentUser() == null));
if (ParseClient.Instance.GetCurrentUser() == null)
{
ParseClient.Instance
.LogInAsync(username: "Test", password: "password")
.Wait();
}
Console.WriteLine(String.Format("Is currentUser null AFTER hardcoded login? {0}", ParseClient.Instance.GetCurrentUser() == null));
}
}
When I start the app for the first time, the outputs are:
Is currentUser null BEFORE hardcoded login? True
Is currentUser null AFTER hardcoded login? False
And when I close the app and restart it the outputs are again:
Is currentUser null BEFORE hardcoded login? True
Is currentUser null AFTER hardcoded login? False
Expected behaviour would be that the logged in user stays logged in when the app is closed and restarted. So the following output would be expected when the app is started for the second time:
Is currentUser null BEFORE hardcoded login? False
Is currentUser null AFTER hardcoded login? False
In my actual App, the user credentials are not hardcoded - Logging in is done on a Login Page where users enter their username and password. Users having to freshly log in every time they start the app would be fatal.
Please help me with this issue, I tried all initialization variants of ParseClient I could find and days of search did not bring me any further either. If this kind of persistence can not be provided, this inconvenience for end users would make parse-dotNET unusable for probably not only my app but every Xamarin.Forms app in which users can sign up and log in.
The probably only relevant NuGet Packages I use are:
NETStandard.Library 2.0.3
Parse 2.0.0-develop-1
Xamarin.Forms 5.0.0.2515
I connect to Parse on back4app.com with Parse Version 4.5.0.
ServerUri = "https://parseapi.back4app.com/";
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the ParseClient initialization and GetCurrentUser call in the App constructor, then reproduce the first-launch and restart sequences described in the issue. Trace how the logged-in user is stored and restored across application restarts; done means GetCurrentUser returns the logged-in user before the second login attempt.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- authentication, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100