Logging in before items are set in localStorage – JS

I am trying to make an app with firebase but when I click log in, it does everything except setting the localStorage items. Tried awaiting and everything else I could think of

signInWithEmailAndPassword(auth, email, password)
            .then(async (userCredential) => {
                const user = userCredential.user;
                localStorage.setItem("access_token", user.stsTokenManager.accessToken);
                localStorage.setItem("uid", user.uid);

                const devices = collection(db, "users", user.uid, "devices");
                const devicesSnap = await getDocs(devices);
                if(devicesSnap.docs.length >= 1) {
                    localStorage.setItem("first_charger", devicesSnap.docs[0].id);
                    localStorage.setItem("first_charger_name", devicesSnap.docs[0].data().deviceName + "/" + devicesSnap.docs[0].id);
                    const formattedChargers = formatChargers(devicesSnap.docs);
                    setChargers(formattedChargers);
                } else {
                    setChargers([]);
                }

                const cars = collection(db, "users", localStorage.getItem("uid"), "vehicles");
                const carsSnap = await getDocs(cars);
                if(carsSnap.docs.length >= 1) {
                    const formattedCars = formatCars(carsSnap.docs);
                    setCars(formattedCars);
                } else {
                    setCars([]);
                }

                setLoading(false);
                setLoggedIn(true);
            })
            .catch((error) => {
                console.log(error);
            });