Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

payload-admin-bar

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

payload-admin-bar

An admin bar for React apps using Payload CMS

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Payload Admin Bar

An admin bar for React apps using Payload as a headless CMS.

Installation

$ npm i payload-admin-bar
$ # or
$ yarn add payload-admin-bar

Basic Usage

import { PayloadAdminBar } from "payload-admin-bar";

export const App = () => {
  return (
    <PayloadAdminBar
      cmsURL="https://cms.website.com"
      collection="pages"
      id="12345"
    />
  );
};

Checks for authentication with Payload CMS by hitting the /me route. If authenticated, renders an admin bar with simple controls to do the following:

  • Navigate to the admin dashboard
  • Navigate to the currently logged-in user's account
  • Edit the current collection
  • Create a new collection of the same type
  • Logout
  • Indicate and exit preview mode

The admin bar ships with very little style and is fully customizable.

Dynamic props

With client-side routing, we need to update the admin bar with a new collection type and document id on each route change. This will depend on your app's specific setup, but here are a some common examples:

NextJS

For NextJS apps using dynamic-routes, use getStaticProps:

export const getStaticProps = async ({ params: { slug } }) => {
  const props = {};

  const pageReq = await fetch(`https://cms.website.com/api/pages?where[slug][equals]=${slug}&depth=1`);
  const pageData = await pageReq.json();

  if (pageReq.ok) {
    const { docs } = pageData;
    const [doc] = docs;

    props = {
      ...doc,
      collection: 'pages',
      collectionLabels: {
        singular: 'page',
        plural: 'pages',
      }
    };
  }

  return props;
}

Now your app can forward these props onto the admin bar. Something like this:

import { PayloadAdminBar } from 'payload-admin-bar';

export const App = (appProps) => {
  const {
    pageProps: {
      collection,
      collectionLabels,
      id
    }
  } = appProps;

  return (
    <PayloadAdminBar
      {...{
        cmsURL: 'https://cms.website.com',
        collection,
        collectionLabels,
        id
      }}
    />
  )
}

Props

PropertyTypeRequiredDefaultDescription
cmsURLstringtruehttp://localhost:8000serverURL as defined in your Payload config
adminPathstringfalse/adminroutes as defined in your Payload config
apiPathstringfalse/apiroutes as defined in your Payload config
collectionstringtrueundefinedSlug of your collection
collectionLabels{ singular?: string, plural?: string }falseundefinedLabels of your collection
idstringtrueundefinedid of the document
logoReactElementfalseundefinedCustom logo
classNames{ logo?: string, user?: string, controls?: string, create?: string, logout?: string, edit?: string, preview?: string }falseundefinedCustom class names, one for each rendered element
logoProps{[key: string]?: unknown}falseundefinedCustom props
userProps{[key: string]?: unknown}falseundefinedCustom props
divProps{[key: string]?: unknown}falseundefinedCustom props
createProps{[key: string]?: unknown}falseundefinedCustom props
logoutProps{[key: string]?: unknown}falseundefinedCustom props
editProps{[key: string]?: unknown}falseundefinedCustom props
previewProps{[key: string]?: unknown}falseundefinedCustom props
styleCSSPropertiesfalseundefinedCustom inline style
unstyledbooleanfalseundefinedIf true, renders no inline style
onAuthChange(user: PayloadMeUser) => voidfalseundefinedFired on each auth change
devModebooleanfalseundefinedIf true, fakes authentication (useful when dealing with SameSite cookies)
previewbooleanfalseundefinedIf true, renders an exit button with your onPreviewExit handler)
onPreviewExitfunctionfalseundefinedCallback for the preview button onClick event)

Keywords

FAQs

Package last updated on 24 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc