Cannot read properties of undefined (reading 'indexOf')

Viewed 427

enter image description here

I want to save a collection in firebase name like when a use like a post I want to save it into the firebase firestore

2 Answers

Do you have this imported?

import { useSession } from "next-auth/react";

Should the code look like this later? ; ) I follow the same tutorial. I was having problems with it too. I don't know how I solved this problem. Try my solution first. If that doesn't work, I can send you some extra stuff (that might have solved it).

const likePost = async () => {
    if (hasLiked) {
        await deleteDoc(doc(db, "posts", id, "likes", session.user.uid));
    } else {
        await setDoc(doc(db, "posts", id, "likes", session.user.uid), {
            username: session.user.username,
        });
    }
};
const likePost = async () => {     
        await setDoc(doc(db, 'posts', id, 'likes', id), {
            username: session.user.name,
        })
    };

because de seesion.user.uid is undefined, i use id and its work

Related