Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
tssma opened this issue Nov 10, 2022 · 0 comments
Open
4 tasks done
Labels

Comments

@tssma
Copy link

tssma commented Nov 10, 2022

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/";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants