nextload/payload.config.ts
tobias 90f1750945
All checks were successful
continuous-integration/drone/push Build is passing
Deny access if no roles
2024-07-06 19:49:50 +02:00

85 lines
2.3 KiB
TypeScript

import path from 'path'
import { en } from 'payload/i18n/en'
import {
AlignFeature,
BlockquoteFeature,
BlocksFeature,
BoldFeature,
ChecklistFeature,
HeadingFeature,
IndentFeature,
InlineCodeFeature,
ItalicFeature,
lexicalEditor,
LinkFeature,
OrderedListFeature,
ParagraphFeature,
RelationshipFeature,
UnorderedListFeature,
UploadFeature,
} from '@payloadcms/richtext-lexical'
import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { buildConfig } from 'payload/config'
import sharp from 'sharp'
import { fileURLToPath } from 'url'
import Media from '@payload/collections/Media'
import Authors from '@payload/collections/Authors'
import Posts from '@payload/collections/Posts'
import Users from '@payload/collections/Users'
import Pages from '@payload/collections/Pages'
import { COLLECTION_SLUG_PAGE, COLLECTION_SLUG_POST } from '@/app/(payload)/collections/config'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export default buildConfig({
collections: [Users, Posts, Authors, Media, Pages],
admin: {
autoLogin: {
email: 'admin@nextload.test',
password: 'test',
prefillOnly: true,
},
livePreview: {
url: ({ data, locale, collectionConfig }) =>
`${process.env.BASE_URL}/${collectionConfig?.slug || ''}/preview${data.path}${
locale ? `?locale=${locale.code}` : ''
}`,
collections: [COLLECTION_SLUG_PAGE, COLLECTION_SLUG_POST],
},
},
editor: lexicalEditor(),
secret: process.env.PAYLOAD_SECRET || '',
typescript: {
outputFile: path.resolve(dirname, 'types/payload-types.ts'),
},
db: mongooseAdapter({
url: process.env.MONGODB_URI || '',
}),
async onInit(payload) {
const existingUsers = await payload.find({
collection: 'users',
limit: 2,
})
if (existingUsers.docs.length === 0 || existingUsers.docs.length === 1) {
await payload.create({
collection: 'users',
data: {
email: 'admin@nextload.test',
password: 'test',
roles: ['admin'],
},
})
}
},
// Sharp is now an optional dependency -
// if you want to resize images, crop, set focal point, etc.
// make sure to install it and pass it to the config.
// This is temporary - we may make an adapter pattern
// for this before reaching 3.0 stable
sharp,
})