unlayer / react-email-editor

Drag-n-Drop Email Editor Component for React.js
https://unlayer.com/embed
MIT License
4.51k stars 728 forks source link

image export failing #389

Open geikobogdan opened 5 months ago

geikobogdan commented 5 months ago

I have my apiKey and project id, but when I try to execute imageExport func I received 401. Attached screenshots with request details (request headers/url, payload). Code:

import { Editor } from "react-email-editor/dist/types"

const EmailEditorNoSSR = dynamic(() => import("react-email-editor").then((mod) => mod.default), { ssr: false })

const projectId = 11111 //your project id

export const EmailBuilderModal: FC<EmailBuilderProps> = ({ open, setOpen }) => {
  const emailEditorRef = useRef<EditorRef | null>(null)

  const onReady = (editor: Editor | null) => {
    if (editor) {
      emailEditorRef.current = {
        editor: editor,
        exportHtml: editor.exportHtml.bind(editor),
      }
      setIsLoading(true)
    }
  }

  const saveImage = async () => {
    if (emailEditorRef.current && emailEditorRef.current.editor) {
      emailEditorRef.current.editor.exportImage(({ design }) => {
        console.log(design, "design")
      }) // 401 error
    } 
  }

  return (
          <EmailEditorNoSSR
              projectId={projectId}
              ref={emailEditorRef}
              onReady={onReady}
            />
         )
})
Screenshot 2024-03-21 at 13 11 47 Screenshot 2024-03-21 at 13 13 18 Screenshot 2024-03-21 at 13 13 32