parse-community / parse-community/Parse-SDK-dotNET

ParseClient.Instance.GetCurrentUser() returns null when closing and restarting the app

Open
#366 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
C#
Stars
335
Forks
258
PR merge metrics
No merged PRs in 30d

Description

New Issue Checklist

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.