Firebase/auth currently in version 9 stores by default the session locally inside indexedDB. But I can't find a method within firebase to retrieve the local session when loading the application.
onAuthStateChanged takes time to get the auth ready when it should be possible to retrieve the "saved current user session".
auth.onAuthStateChanged(function (userData) {
if (userData) {
// User is signed in.
} else {
// No user is signed in.
}
});
Is there a method to access the local current user directly without accessing manually to the indexedDB? rather than dumpling the indexedDB like in this gist, or sending the user to localStorage myself?
You are probably looking for this:
import { getAuth } from "firebase/auth";
const auth = getAuth();
const user = auth.currentUser; // null if no user
You can find more information in the documentation