chore(next): scaffolds access routes (#4562)

This commit is contained in:
Jacob Fletcher
2023-12-20 01:14:19 -05:00
committed by GitHub
parent af88fb8af4
commit a6d7852903
8 changed files with 82 additions and 0 deletions

View File

@@ -1,2 +1,3 @@
PAYLOAD_SECRET=ls3nd09adff9cmlq71j
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
DATABASE_URI=mongodb://127.0.0.1/payloadtests

View File

@@ -0,0 +1,6 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY it because it could be re-written at any time. */
import { access } from '@payloadcms/next/routes/[collection]/access'
import config from 'payload-config'
export const GET = (request, context) => access({ config, collection: context.params.collection })

View File

@@ -0,0 +1,6 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY it because it could be re-written at any time. */
import { access } from '@payloadcms/next/routes/access'
import config from 'payload-config'
export const GET = access({ config })

View File

@@ -0,0 +1,6 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY it because it could be re-written at any time. */
import { access } from '@payloadcms/next/routes/globals/[global]/access'
import config from 'payload-config'
export const GET = (request, context) => access({ config, global: context.params.global })

View File

@@ -14,4 +14,13 @@ export default buildConfig({
// }),
// editor: lexicalEditor({}),
secret: process.env.PAYLOAD_SECRET,
// onInit: async (payload) => {
// await payload.create({
// collection: 'users',
// data: {
// email: 'dev@payloadcms.com',
// password: 'test',
// },
// })
// },
})

View File

@@ -0,0 +1,22 @@
import type { SanitizedConfig } from 'payload/types'
import { createPayloadRequest } from '../../createPayloadRequest'
import { docAccess } from 'payload/dist/collections/operations/docAccess'
export const access = ({ config }: { config: Promise<SanitizedConfig>; collection?: string }) =>
async function (request: Request, { params }: { params: { collection: string } }) {
const req = await createPayloadRequest({ request, config })
const collectionConfig = await config.then((config) =>
config.collections.find((collection) => collection.slug === params.collection),
)
const accessRes = await docAccess({
id: params.collection,
req: {
...req,
collection: {
config: collectionConfig,
},
},
})
return Response.json(accessRes)
}

View File

@@ -0,0 +1,19 @@
import type { SanitizedConfig } from 'payload/types'
import { getAccessResults } from 'payload/auth'
import { createPayloadRequest } from '../createPayloadRequest'
export const access = ({
config,
}: {
config: Promise<SanitizedConfig>
collection?: string
global?: string
}) =>
async function (
request: Request,
{ params }: { params: { collection: string; global: string } },
) {
const req = await createPayloadRequest({ request, config })
const accessRes = await getAccessResults({ req })
return Response.json(accessRes)
}

View File

@@ -0,0 +1,13 @@
import type { SanitizedConfig } from 'payload/types'
import { createPayloadRequest } from '../../../createPayloadRequest'
import { docAccess } from 'payload/dist/globals/operations/docAccess'
export const access = ({ config }: { config: Promise<SanitizedConfig>; global?: string }) =>
async function (request: Request, { params }: { params: { global: string } }) {
const req = await createPayloadRequest({ request, config })
const globalConfig = await config.then((res) =>
res.globals.find((global) => global.slug === params.global),
)
const accessRes = await docAccess({ req, globalConfig })
return Response.json(accessRes)
}