I'm a potato and I forgot how to keep the user log...
# help
b
I'm a potato and I forgot how to keep the user logged in correctly...
n
Hello @barry! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
b
Copy code
js
import { User } from "@supabase/supabase-js";
import { useEffect, useState } from "react";
import supabase from "./supabase";

export default function useUser() {
  const [user, setUser] = useState<User | null>(supabase.auth.user());

  useEffect(() => {
    const ubsub = supabase.auth.onAuthStateChange((event, session) => {
      console.log(event, session);
      if (session) {
        setUser(session.user);
      } else {
        setUser(null);
      }
    });
  }, []);

  return [user];
}
Am I completely wrong or?
Fixed it.
n
Thread was archived by @barry. Anyone can send a message to unarchive it.
barry (2022-04-16)