Jobs – Queuing a new job in payload

Jobs are stored in the Payload database in the payload-jobs collection, and you can decide to keep a running list of all jobs, or configure Payload to delete the job when it has been successfully executed. Queuing a new job In order to queue a job, you can use the payload.jobs.queue function. Here’s how you’d… Continue reading Jobs – Queuing a new job in payload

Using useRouter for Conditional Rendering in Next.js

The useRouter hook from Next.js allows you to access route info inside your components. You can use it for conditional rendering based on the current route. Why Use useRouter? Sometimes, you want to hide/show content depending on the route—like hiding a header on the login page import { useRouter } from ‘next/router’; export default function… Continue reading Using useRouter for Conditional Rendering in Next.js

Restricting Page Access with Middleware in Payload CMS

Payload CMS allows you to use middleware to control access to certain routes or pages. Why Use Middleware? To restrict frontend or admin page access based on authentication or roles, without manually adding logic inside every component or route. Example import { NextFunction, Request, Response } from ‘express’; export const restrictPageAccess = (req: Request, res:… Continue reading Restricting Page Access with Middleware in Payload CMS

Creating Public APIs Without Login in Payload CMS

You can expose APIs in Payload CMS without requiring authentication by adjusting access control in collections or using middleware. Why Do This? Useful for public-facing endpoints like blogs, events, or product listings where login is not needed. Collection Config access: {   read: () => true, }, Custom Middleware export const allowPublicAPI = (req, res,… Continue reading Creating Public APIs Without Login in Payload CMS

Defining Relations in Collections

Relations in Payload CMS allow one collection to reference another, creating links between different sets of data. The most common types of relationships include: One-to-One (A single reference to another document) One-to-Many (A field can reference multiple documents) Many-to-Many (Multiple documents can reference multiple other documents) To define a relation, use the relationship field type… Continue reading Defining Relations in Collections

Implementing Multi-Tenancy in Payload CMS

Multi-tenancy in Payload CMS allows managing multiple tenants (clients, organizations) within a single CMS instance. Setting Up Multi-Tenancy Define a tenant field to associate content with different tenants: const Posts = {  slug: ‘posts’,  fields: [   { name: ‘tenant’, type: ‘text’, required: true },   { name: ‘title’, type: ‘text’, required: true },  ],  access: {… Continue reading Implementing Multi-Tenancy in Payload CMS

Custom Field Types in Payload CMS

Payload CMS allows the creation of custom field types to meet specific project requirements beyond the built-in options. Creating a Custom Field Type A custom field can be created by defining a new field type in the collection schema: const CustomField = {   name: ‘customText’,   type: ‘text’,   admin: {     placeholder:… Continue reading Custom Field Types in Payload CMS

Version Control in Payload CMS

Version control in Payload CMS allows you to track changes made to content over time, enabling content rollback, auditing, and better collaboration. This feature ensures that previous versions of content can be restored if needed. Implementing Version Control Payload CMS provides built-in versioning that can be enabled at the collection level: const Posts = {… Continue reading Version Control in Payload CMS

Implementing Server-Side Rendering (SSR) with Payload CMS in Next.js

To fetch Payload CMS data at build time (SSG) and at request time (SSR) in Next.js. Steps: Set Up a Payload CMS Collection payload.config.ts: ts Copy Edit const Articles: CollectionConfig = { slug: ‘articles’, fields: [ { name: ‘title’, type: ‘text’, required: true, }, { name: ‘content’, type: ‘richText’, }, ], }; export default Articles;… Continue reading Implementing Server-Side Rendering (SSR) with Payload CMS in Next.js