Next.js Discord

Discord Forum

How I can use getDownloadUrl in _document nextjs file?

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I am trying to get image url to set in _document file of next.js. I doing this:

import { storage } from "@/firebase";
import { getDownloadURL, list, ref } from "firebase/storage";
import { Html, Head, Main, NextScript } from "next/document";
import Image from "next/image";
import { useEffect, useState } from "react";

export default function Document() {
  const [url, setUrl] = useState("");
  const reference = ref(storage, "media/images/logo.jpg");

  useEffect(() => {
    try {
      getDownloadURL(reference)
        .then((response) => {
          console.log(response);
          setUrl(response);
        })
        .catch((error) => {
          console.log(error);
        });
    } catch (e) {
      console.log(e);
    }
  }, [reference, url]);

  return (
    <Html lang="en">
      <Head />
      <body>
        <Image src={url} alt="logo" />
        <Main />
        <NextScript />
      </body>
    </Html>
  );
}


But I do not get error or any message. What I am doing wrong?

0 Replies