chore(next): scaffolds access routes (#4562)
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
PAYLOAD_SECRET=ls3nd09adff9cmlq71j
|
||||
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
|
||||
DATABASE_URI=mongodb://127.0.0.1/payloadtests
|
||||
|
||||
@@ -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 })
|
||||
6
packages/dev/src/app/(payload)/api/access/route.ts
Normal file
6
packages/dev/src/app/(payload)/api/access/route.ts
Normal 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 })
|
||||
@@ -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 })
|
||||
@@ -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',
|
||||
// },
|
||||
// })
|
||||
// },
|
||||
})
|
||||
|
||||
22
packages/next/src/routes/[collection]/access.ts
Normal file
22
packages/next/src/routes/[collection]/access.ts
Normal 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)
|
||||
}
|
||||
19
packages/next/src/routes/access.ts
Normal file
19
packages/next/src/routes/access.ts
Normal 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)
|
||||
}
|
||||
13
packages/next/src/routes/globals/[global]/access.ts
Normal file
13
packages/next/src/routes/globals/[global]/access.ts
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user