Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #3002 #3003

Merged
merged 2 commits into from
Mar 1, 2024
Merged

fix: #3002 #3003

merged 2 commits into from
Mar 1, 2024

Conversation

Lenghak
Copy link
Collaborator

@Lenghak Lenghak commented Feb 28, 2024

Description

Please see some more information in the #3002 .

Copy link

changeset-bot bot commented Feb 28, 2024

🦋 Changeset detected

Latest commit: 74c1c04

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@udecode/plate-cloud Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 1, 2024 10:13am

zbeyens
zbeyens previously approved these changes Feb 28, 2024
@Lenghak Lenghak marked this pull request as ready for review February 29, 2024 01:04
@Lenghak
Copy link
Collaborator Author

Lenghak commented Mar 1, 2024

[Update: Fri - March 1st, 2024]:

TL;DR

Use CSR (client side rendering) for editor and its plugin to resolve the issue since the package @portive/client is not accessible for SSR which will try to run the code on the server.

For portive cloud API_KEY exposed on the client as the result of using full CSR, please visit: https://www.portive.com/docs/auth/intro#about-using-auth-tokens

Details

I have just forked the plate-next-template in Codesandbox to test out the plate-cloud behavior. After comparing the Next.Js code with Astro, I have come to a few conclusions.

In my project, which is based on Astro, I am implementing SSR (Server-Side Rendering) to render the editor on the client. This means that the configuration and plugins run on the server along with the HTML before shipping some JS to the client to initialize the editor. Each time I run the command from the plate component, I always remove 'use-client' from the code and rely on the .astro file to specify where the code will render.

---
import RootLayout from "@/common/layouts/root-layout.astro";
import WriteEditor from "@/modules/write/composites/write-editor";
---

<RootLayout title="Le-Insight | Write">
  <WriteEditor client:load />
</RootLayout>

However, the @portive/client package is not accessible on the server, causing some errors related to commonJs and esm, regardless of my already configured esm setting in tsconfig.

After conducting some simple inspections that I missed the last time before creating this PR, I have decided to render the editor with its plugins on the client-side.

---
import RootLayout from "@/common/layouts/root-layout.astro";
import WriteEditor from "@/modules/write/composites/write-editor";
---

<RootLayout title="Le-Insight | Write">
  <WriteEditor client:only="react" />
</RootLayout>

Everything works as expected, rendering this PR POINTLESS. (My sincere apologies for my immature knowledge)

However, we are still facing another problem since our API key for Portive Cloud is exposed on the client-side. The solution provided by Portive Cloud is to use @portive/auth as an additional tool to generate an AUTH_TOKEN instead of using the exposed API_KEY on the client. Please see the summary below:

createCloudPlugin({
  options: {
    authToken: async () => {
      const response = await fetch("https://mysite.com/api/get-auth", {
        method: "POST",
      })
      const json = await response.json()
      return json.authToken
    },
  },
})

For more information, please visit: https://www.portive.com/docs/auth/intro#about-using-auth-tokens

To the maintainer: Regarding this PR, you can consider closing it since my solution of changing the import does not actually fix the problem for everyone's project. Thank you.

@zbeyens zbeyens merged commit 9763f35 into udecode:main Mar 1, 2024
2 of 3 checks passed
@zbeyens
Copy link
Member

zbeyens commented Mar 1, 2024

Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants