I'm trying to access the current logged in user's data in Xamarin.Forms but there seems to be no answer online, I'm not trying to get the device's owner data, just the data about the user currently logged in to the app and using it such as its Id etc to query the user's Favorites and related data.
My app gets the user's identity from an ASP.NET CORE / .NET 5 API using Identity and JWT Tokens.
I know how to do it in ASP.NET CORE but I don't know how to access that information in Xamarin.Forms.
Thank you so much for your help !
CodePudding user response:
Assuming that you have a sign-in page, where the user enters his credentials that you send to your API and get a response, you can do two things.
- Return the user id along with the token and save it in the storage, e.g. by using the Preferences.
- Decode the JWT token and get the user id from there How to decode JWT Token