Search code examples
c#androidblazor.net-8.0blazor-hybrid

How do I store user data in a Blazor Hybrid App


I'm developing a Blazor Hybrid App for Android using .NET8 and C# in Visual Studio.

What is best practice or even the intended way to persistently store user data for the app, that can be loaded after restarting the app or the phone? Like e.g. strings and booleans from user input or settings the user made in my app.


Solution

  • I suppose you are using maui for the mobile part. there is a native approach using the namespace Microsoft.Maui.Storage

    await SecureStorage.Default.SetAsync("oauth_token", "secret-oauth-token-value");
    

    you can follow this guide to have a good aproach it is a 5min read:

    https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/storage/secure-storage?view=net-maui-8.0&tabs=android

    it also depend of how sensitive is your data, for a more secure approach read this: https://developer.android.com/privacy-and-security/security-tips