Universally clearing persistence

My app has several pages and many components defined with

persistence=True,
persistence_type='session',

I have implemented a simple authentication system using GitHub - russellromney/dash-auth-flow: Batteries-included authentication flow with Dash. (thanks @russellthehippo). So if a user logs out and new user logs in to the same browser tab, the session is still the same and items selected by the previous user persist.

Is there a way to completely reset the session whenever a user logs out (or in) to these clear persistent values? The Explicitly clearing saved data example just showed how to clear or reset one specifically within a callback and I have dozens.

1 Like

Very, very old but…

This is something that I am able to use to clear the persistence directly:

app.clientside_callback(
    """function () {
        const keys = Object.keys(localStorage)
        for (let key of keys) {
            if (String(key).includes('_dash_persistence')) {
                localStorage.removeItem(key)
            }
        }
        return ''
    }""",
    Output('persistenceClear','children'), ### placeholder for clearing
    ##Inputs to reset
)

thanks for this one too. I can use this. I have login and logout in my app, but even after the user logs out, their final selections still appear in the controls with persistence set, since the “session” is still active. I will let you know if I get this improvement implemented.

I have another bug that’s even older that I’m hoping is fixed already but this reminds me to give it another try.

1 Like

I got my search working properly with search_value and thankful your persistence suggestion which got me to explore solving this two years later.

Going back to clearing persistence, if the Inputs are supposed to be the Inputs to reset, how do we initiate executing the clientside_callback when we need it? I would think the outputs would be what we wanted cleared and the Input would be our trigger to clear things. I want to clear the persistence in all my controls when a user has logged out. Since the logout occurs after clicking a Logout URL, what would you recommend for initiating whatever is necessary to trigger the clear. Sorry if I am thinking too much like a regular callback.

The inputs were what triggers it, it can be whatever you want.

For your need, on logout, the layout clicks a button that clears the persistence.

The clientside callback is interacting with the webpage and making the alterations, the output is just a placeholder because you can’t have a callback with no output.