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

(Enchancement) Support Local Storage & Async for IUserRepository #192

Open
derekwelton opened this issue Feb 8, 2023 · 1 comment
Open

Comments

@derekwelton
Copy link

Here are my 2 request:

  1. IUserRepository needs to support async. If I want my repository to be in the browser's local storage or in a SQL Lite database, async methods need to be supported
  2. Support Blazor applications by adding a "LocalStorageUserRepository". With the updated 4.0 release, its been difficult to use this library in a blazor web assembly application. In 3.7, I was able to create my own ways, but finding it more difficult in 4.0. For example, I was able to get a Refresh my tokens by just passing in the ID Token and Refresh Token. I'm not able to do this now as I have to go through the IUserRepository.

One solution that would help is you currently have a FilerUserRepository. Here is an example of using LocalStorage In the browser.

  • This is using the Blazored.LocalStorage Nuget Package
  • it uses your "UserDal" class for storing
  • Note that LocalStorage requires async, so I had to force them to be sync instad of async.
public class LocalStorageUserRepository : IUserRepository
{
    private readonly ILocalStorageService _localStorage;

    public LocalStorageUserRepository(ILocalStorageService localStorage)
    {
        _localStorage = localStorage;
    }

    public bool UserExists()
    {
        var task = _localStorage.ContainKeyAsync("firebaseauth");
        return task.GetAwaiter().GetResult();
    }

    public (UserInfo userInfo, FirebaseCredential credential) ReadUser()
    {
        var task = _localStorage.GetItemAsync<UserDal>("firebaseauth");
        var user = task.Result;

        return (user.UserInfo, user.Credential);
    }


    public void SaveUser(User user)
    {
        var authUser = new UserDal(user.Info, user.Credential);
        var task = _localStorage.SetItemAsync("firebaseauth", authUser);
        task.GetAwaiter().GetResult();
    }

    public void DeleteUser()
    {
        
        var task = _localStorage.RemoveItemAsync("firebaseauth");
        task.GetAwaiter().GetResult();
    }
}
@bezysoftware
Copy link
Collaborator

That's something that would require a bigger rewrite, since the repository code if now used (AFAIK) in some constructors and properties (getters / setters). So introducing async would right now be a lot of work which I don't really have capacity for

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

No branches or pull requests

2 participants