[解決] useEffect supabase getUser in Next.js

[解決] useEffect supabase getUser in Next.js

  useEffect(() => {
    supabase.auth.getUser().then((res) => {
      setUserId(res.data.user?.id)
    })
    .catch((err) => {
      console.error(err)
    })
  }, [])

or

const hogehoge = async (e: FormEvent<HTMLFormElement>) => {
  .
  .
  .
  await (await supabase.auth.getUser()).data.user?.id
}

ref
https://supabase.com/docs/reference/javascript/auth-getuser