next.jscontent-management-systempayload-cms

How to show sign up page in Payload CMS admin dashboard?


I am using Payload CMS with Next.js and Mongodb to create an E-commerce website, using Payload CMS to manage content and connect databases. But I am facing a problem with the admin dashboard provided by Payload CMS, i set the admin dashboard to /sell endpoint and then navigated to that endpoint I only found a sign-in page with no welcome sign-up option which prevented me from finding my collections in the database

this is my payload.config.ts file

import { webpackBundler } from '@payloadcms/bundler-webpack';
import { mongooseAdapter } from '@payloadcms/db-mongodb';
import { slateEditor } from '@payloadcms/richtext-slate';
import dotenv from 'dotenv';
import path from 'path';
import { buildConfig } from 'payload/config';
import { Users } from './collections/Users';

dotenv.config({
    path: path.resolve(__dirname, '../.env')
});

export default buildConfig({
    serverURL: process.env.NEXT_PUBLICK_SERVER_URL || '',
    collections: [Users],
    routes: {
        admin: '/sell'
    },
    admin: {
        user: 'users',
        bundler: webpackBundler(),
        meta: {
            titleSuffix: '- Shopvista',
            favicon: '/favicon.ico',
            ogImage: '/thumbnail.jpg'
        }
    },
    rateLimit: {
        max: 2000,
    },
    db: mongooseAdapter({
        url: process.env.MONGODB_URL!,
    }),
    editor: slateEditor({}),
    typescript: {
        outputFile: path.resolve(__dirname, 'payload-types.ts')
    }, 
})

and this is my users collection

import { Access, CollectionConfig } from 'payload/types'

const adminsAndUser: Access = ({ req: { user } }) => {
  if (user.role === 'admin') return true

  return {
    id: {
      equals: user.id,
    },
  }
}

export const Users: CollectionConfig = {
  slug: 'users',
  auth: true,
  access: {
    read: adminsAndUser,
    create: () => true,
    update: ({ req }) => req.user.role === 'admin',
    delete: ({ req }) => req.user.role === 'admin',
    
  },
  admin: {
    hidden: ({ user }) => user.role !== 'admin',
    defaultColumns: ['id'],
  },
  fields: [
    {
      name: 'role',
      defaultValue: 'user',
      required: true,

      type: 'select',
      options: [
        { label: 'Admin', value: 'admin' },
        { label: 'User', value: 'user' },
      ],
    },
  ],
}

What am I doing wrong?


Solution

  • If you are seeing the admin sign in page, and NOT the create-first-user page, it must be that there is already a user in your users collection. You can manually delete the user from your collection with mongodb Compass or another DB tool, then browse to /sell again. It should redirect you to the page to the form for creating the first user.

    I'm wondering where your first user came from. Since I don't see that in onInit, maybe there is something in your "scripts" package.json that is running a seed before starting the server unless you connected to an existing database with existing users.