Make sure login is done or not in Xamarin.forms

Please help me how are we going to check xamarin.forms if login has been done or not.

When we open the application, we check if the login was completed or not, if the login was not completed, it should go to the login page, otherwise it should go to the main page. If we log out, then only he should go to the login page

Same as for facebook and gmail login

please help me in i m new for xamarin.forms in xamarin.forms we cannot use local storage also how to solve this problem.

+3


source to share


3 answers


Finally I got a response from this solution

App.Current.Properties["IsLoggedIn"] = true

      



https://github.com/conceptdev/xamarin-forms-samples/tree/master/LoginDemo

We can fix this problem by setting using IsLoggedIn

intrue

+2


source


Use application properties in .forms, the data is stored .
The saved data is restored automatically when you start the application, but first you need to create it and it is important to save strong> them.

Example for integer value (from my app):

In the starting code:

if (!Application.Current.Properties.ContainsKey("iBenutzerSuchParameter"))  // Key don't exist
  { Application.Current.Properties["iBenutzerSuchParameter"] = 0; } // create it an fill a value
// overtake the setting in a global variable and convert it
   GV.iBenutzerSuchParameter = Convert.ToInt32(Application.Current.Properties["iBenutzerSuchParameter"]);

      



Save the property directly:

await Application.Current.SavePropertiesAsync(); 

      

So ... if you really want to keep the "login state" persistent and reload it every time the application starts (meaning the user only needs to login once ) in your live "), you need to:
Define and create a key to save the state in your start code (if it doesn't already exist -> see my example code)
Maybe store the value for the "not registered" state and store the properties the first time
Show your login page
Check if successful:
If yes, change the key to "login" and save properties.

+1


source


There are 3 options:

  • You can save it to your local database
  • You can save it to App.Current.Properties
  • You can save it in each platform's own api, all 3 platforms have an api to save settings
+1


source







All Articles