Next.js Discord

Discord Forum

Image faled to parse src

Answered
Madeiran sardinella posted this in #help-forum
Open in Discord
Madeiran sardinellaOP
Hello guys, just started learning NextJS and i'm following an youtube tutorial on creating a blog and I wanted to display the blog post's author profile image using the <Image> tag but I'm getting an error and I'm using next-auth wth Discord's oAuth

Error: Failed to parse src "4d1c8cdeb79bf9689c1b899ece04dca6" on `next/image`, if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)


next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'cdn.discordapp.com'
      }
    ],
  }
}

module.exports = nextConfig


<Image
  src={post.creator.image}
  alt={post.creator.name}
  width={40}
  height={40}
  className="object-contain rounded-full"
/>


const PromptSchema = new Schema({
  creator: {
    type: Schema.Types.ObjectId,
    ref: "User",
  },
  prompt: {
    type: String,
    required: [true, "Prompt is required!"],
  },
  tag: {
    type: String,
    required: [true, "Tag is required!"],
  }
});
Answered by riský
you should look at the discord docs on how to format the url with the image hash: https://discord.com/developers/docs/reference#image-formatting-cdn-endpoints
View full answer

12 Replies

Answer
Madeiran sardinellaOP
Should I change this in the next.config.js file? Like add pathname:
in the src of Image
Madeiran sardinellaOP
Interesting, the image is showing in the navbar however and it's done the same way except the src is just session?.user?.image
next-auth is probably constructing the url for you there
Madeiran sardinellaOP
Oooh makes sense
Thank you
Madeiran sardinellaOP
@riský sorry for tagging, but how can I construct the url 🥲
you can use template string
something like: https://cdn.discordapp.com/avatars/${post.creator.id}/${post.creator.image}.png
Madeiran sardinellaOP
Okay, I'll give it a try, thanks!

p.s. things in php and laravel are a whole lot different from here :D