score:3

Accepted answer

it appears to be a bug in reactfire. see https://github.com/firebaseextended/reactfire/discussions/228.

a possible workaround is mentioned there suggesting to call the following function immediately after signing out:

export const clearfirestorecache = () => {
  const map = globalthis['_reactfirepreloadedobservables'];
  array.from(map.keys()).foreach(
    (key) => key.includes('firestore') && map.delete(key),
  );
};

score:0

i finally fixed it when i added a routing system (react-router-dom) . index.ts

<themeprovider theme={apptheme}>
    <firebaseappprovider firebaseconfig={firebaseconfig}>
      <snackbarprovider maxsnack={6}>
        <suspensewithperf fallback={<loader/>} traceid={'web-initial-loading'}>
          <hashrouter>
              <route path={'/signin'}>
                <signin/>
              </route>
              <route path={'/dashboard'}>
                <dashboard/>
              </route>
          </hashrouter>
        </suspensewithperf>
      </snackbarprovider>
    </firebaseappprovider>
  </themeprovider>

and i added a redirect to dashboard on login and a redirect on signin on logout.

i will have to find a way to handle auto signout if not loggedin while on a secured page. but from what i understand, we cannot rely directly on useauth or for more complex routing than showing a component. if you make call that needs to be authenticated to work, you better use a real routing system.

edit to automatically redirect to sign in page and remember where you were you can replace

<route path={'/dashboard'}>
    <dashboard/>
</route>

with

{
    user
        ? <> // all secured routes
            <route path={'/dashboard'}>
                <dashboard />
            </route>
        </>
        : <redirect to={`/signin redirectpath=${history.location.pathname}`} />
}

where user is the useuser() hook.

score:0

as per thomas hammerl's answer above, it appears to be a bug in reactfire. see https://github.com/firebaseextended/reactfire/discussions/228.

i ran into this issue while upgrading to firebase 9, but reloading the page after the user signs out was the fix for me:

signout(getauth())
  .then(() => {
     window.location.reload();
  })
  .catch((e) => {
     // handle error eg
     console.log(e.message);
  });

this was suggested in the discussion by epodol as a temporary workaround, hopefully the issue can be fixed in the library soon.


Related Query

More Query from same tag