sayinmehmet47
sayinmehmet47

Reputation: 561

Image in NextJS does not allow template literals inside src when deploying on vercel

I have a userdropdown menu that I want to show the picture of the client that authenticated. I use nextAuth to authenticate. I can see the picture of the user and name of the user turns well with useSession().

enter image description here

I show the picture of the user in localhost without problem. Here how I show it with Image tag.

  <li className="py-1 px-3 hover:underline leading-8 flex">
              <Image
                width={40}
                height={40}
                className="mr-3"
                src={status === "authenticated" ? session.user.image : profile}
                alt="img"
              />
              <span className="ml-3">User</span>
            </li>

session.user.image turn that

https://lh3.googleusercontent.com/a-/AOh14GjUcorAI3kntYm5-R2g5r0gBl9VSNY8pL9Fs4Ar0g=s96-c

But when I sent it for production to vercel, it throw error and does no work like in localhost. Here the error

enter image description here

My app link is that https://netflix-clone47.vercel.app/

Upvotes: 0

Views: 1138

Answers (1)

Paiman Rasoli
Paiman Rasoli

Reputation: 1214

first check if you had the domain for images in next.config.js:

moduel.exports = {
  images : {
    domains : ['lh3.googleusercontent.com']
 }
 }

then check if session is exist by using question mark(?):

          <Image
            width={40}
            height={40}
            className="mr-3"
            src={status === "authenticated" ? session?.user?.image : profile}
            alt="img"
          />

Upvotes: 1

Related Questions