Connecting to 3rd party data sources from within Live Preview #13889
Unanswered
jessecoleman
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
My team is integrating Payload into our existing NextJS application, and have gotten over most of the major hurdles so far. I'm currently trying to build out a few collection live previews, and running into a hitch with accessing certain user/auth fields from within the live preview context.
We're trying to use payload to edit a subset of fields on an entity that already exists within our own database, and need to merge the object from our BE with the one in Payload. To do this, I am using
afterRead
to augment the payload document with data fetched from our BE. Additionally, we're bypassing Payload's built in auth to use our existing Auth0 sessions instead. So far so good, we can get data from the database, using the Auth0 session cookie inside Payload on the server to access our external DB securely.Since live preview runs inside an iframe and uses
window.postMessage
, the rendering environment doesn't have access to auth cookies. And it seems like the data passed viapostMessage
doesn't bring along virtual fields set byafterRead
. So there's seemingly no way to get our external DB data into the live preview, which we need to do to be able to display the components correctly. Is there some hook or lifecycle event I'm missing that would allow me to get the data into live preview?Below is our auth strategy, which allows us to read from the request cookies set by our Auth0 tenant, and then access the user from within Payload. This user is attached to the
req
object for any requests made from the host, but then within the iFrame,req.user
isnull
, as the docs indicate that thereq
object is mocked out.And here's one of my collection hooks, that adds a
title
field from our external db.Beta Was this translation helpful? Give feedback.
All reactions