https://supabase.com/ logo
Join Discord
Powered by
# help
  • f

    frubalu

    07/27/2021, 5:45 PM
    question: your code looks more or less like this, right?
    Copy code
    const fetchGames = async () => {
        if (!user) return;
    
        return await supabase.from('users_games').select().eq('user_id', user.id);
      };
    
      useEffect(() => {
        (async () => {
          const res = await fetchGames();
          console.log({ res });
        })();
      }, []);
  • f

    Flyken

    07/27/2021, 5:45 PM
    i needed to do a
    if(users) console.log
    though
  • f

    Flyken

    07/27/2021, 5:45 PM
    yea , i copied it
  • f

    frubalu

    07/27/2021, 5:45 PM
    cause it doesn't seem like it's even getting past that
    if (!user) return
    line
  • f

    frubalu

    07/27/2021, 5:45 PM
    which makes sense why it'd return undefined
  • f

    frubalu

    07/27/2021, 5:46 PM
    what/where is
    user
    being stored, in a
    useState()
    or something?
  • f

    Flyken

    07/27/2021, 5:46 PM
    ignore the games state
  • f

    Flyken

    07/27/2021, 5:46 PM
    its unused
  • f

    frubalu

    07/27/2021, 5:47 PM
    ok, so you're pulling this from the supabase Auth module. I haven't used it yet, but i get the idea
  • f

    Flyken

    07/27/2021, 5:47 PM
    its basically just an easy auth context
  • f

    frubalu

    07/27/2021, 5:47 PM
    if you console log user right above that
    if (!user)
    check, do you see a user?
  • f

    Flyken

    07/27/2021, 5:47 PM
    null
  • f

    frubalu

    07/27/2021, 5:48 PM
    there ya go, it's returning out of your
    fetchGames()
    function early
  • f

    frubalu

    07/27/2021, 5:48 PM
    so you don't have a user signed in
  • f

    Flyken

    07/27/2021, 5:50 PM
    so
  • f

    Flyken

    07/27/2021, 5:50 PM
    do i just check if user exists first?
  • f

    Flyken

    07/27/2021, 5:50 PM
    like
  • f

    Flyken

    07/27/2021, 5:50 PM
    it sounds stupid
  • f

    Flyken

    07/27/2021, 5:50 PM
    but
  • f

    frubalu

    07/27/2021, 5:51 PM
    well you've gotta have a user logged in somehow, not sure how you're handling that
  • f

    frubalu

    07/27/2021, 5:51 PM
    otherwise you won't know what
    user.id
    to query against
  • f

    Flyken

    07/27/2021, 5:51 PM
    user exists
  • f

    Flyken

    07/27/2021, 5:51 PM
    just not right away
  • f

    Flyken

    07/27/2021, 5:51 PM
    idk whats going on but its one of those things where its not populated until like
  • f

    Flyken

    07/27/2021, 5:51 PM
    idk 3phemtoseconds after render
  • f

    frubalu

    07/27/2021, 5:52 PM
    ok so maybe change your useEffect in this way:
    Copy code
    useEffect(() => {
        if (user) {
          (async () => {
            const res = await fetchGames();
            console.log({ res });
         })();
        }
      }, [user]);
  • s

    Scott P

    07/27/2021, 5:52 PM
    ^ just what I was going to suggest. I'd also
    console.log(user)
    first (before the
    if (user)
    check) as well and see what shows up on each render
  • f

    Flyken

    07/27/2021, 5:53 PM
    AAYYYEEE
  • f

    Flyken

    07/27/2021, 5:53 PM
    welp
  • f

    Flyken

    07/27/2021, 5:53 PM
    theres my email :l
1...456...316Latest