Files
payload/test/versions/globals/Autosave.ts
Jacob Fletcher 1fc9c47f20 feat(next): supports relative preview URLs (#9755)
Similar to #9746. When deploying to Vercel, preview deployment URLs are
dynamically generated. This breaks `admin.preview` within those
deployments because there is no mechanism by which we can detect and set
that URL within Payload. Although Vercel provides various environment
variables at our disposal, they provide no concrete identifier for
exactly which URL is being currently previewed (you can access the same
deployment from a number of different URLs).

The fix is to support relative `admin.preview` URLs, that way Payload
can prepend the application's top-level domain dynamically at
render-time in order to create a fully qualified URL. So when you visit
a Vercel preview deployment, for example, that deployment's unique URL
is used as the preview redirect, instead of the application's
root/production domain. Note: this does not fix multi-tenancy
single-domain setups, as those still require a static top-level domain
for each tenant.
2024-12-04 17:01:09 -05:00

47 lines
758 B
TypeScript

import type { GlobalConfig } from 'payload'
import { autoSaveGlobalSlug } from '../slugs.js'
const AutosaveGlobal: GlobalConfig = {
slug: autoSaveGlobalSlug,
access: {
read: ({ req: { user } }) => {
if (user) {
return true
}
return {
or: [
{
_status: {
equals: 'published',
},
},
{
_status: {
exists: false,
},
},
],
}
},
},
fields: [
{
name: 'title',
type: 'text',
localized: true,
required: true,
},
],
label: 'Autosave Global',
versions: {
drafts: {
autosave: true,
},
max: 20,
},
}
export default AutosaveGlobal