Skip to content

User becomes null after a while #228

Open
@poochie89

Description

@poochie89

I have a maui app and in the class below to perform the Token refresh, but after a while, the user will be null
How can i prevent the app from loosing the User object? Is there something super basic I am missing?
This is on Windows

builder.Services.AddSingleton(new FirebaseAuthClient(new FirebaseAuthConfig()
{

    ApiKey = "*****",
    AuthDomain = AppConfig.FirebaseAuth,
    Providers = new FirebaseAuthProvider[]
    {
        new EmailProvider()
    },
    
    UserRepository = new FileUserRepository("EvolveFootballUser")
}));



    public class FirebaseDatabaseClient
    {
        public FirebaseAuthClient AuthClient { get; set; }
        public FirebaseClient DatabaseClient { get; private set; }
        public UserService UserService { get; set; }


        public FirebaseDatabaseClient(FirebaseAuthClient authClient, UserService userService)
        {
            AuthClient = authClient;
            UserService = userService;

            DatabaseClient = new FirebaseClient(
               AppConfig.FireBaseDatabase,
               new FirebaseOptions
               {
                   AuthTokenAsyncFactory = () => LoginAsync()
               });
        }


        /// <summary>
        /// Retrieves (and refreshes if necessary) the current user's Firebase ID token.
        /// </summary>
        private async Task<string> LoginAsync()
        {
            if (AuthClient.User == null)
                throw new UnauthorizedAccessException("User is not authenticated.");

            // This forces a token refresh if the current one is expired or near expiry.
            var token = await AuthClient.User.GetIdTokenAsync();

            return token;
        }

    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions