=>
generatePageMetadata({ config, params, searchParams })
-const Page = ({ params, searchParams }: Args) => RootPage({ config, params, searchParams })
+const Page = ({ params, searchParams }: Args) =>
+ RootPage({ config, importMap, params, searchParams })
export default Page
diff --git a/examples/auth/src/app/(payload)/admin/importMap.js b/examples/auth/src/app/(payload)/admin/importMap.js
new file mode 100644
index 00000000000..628c80f502c
--- /dev/null
+++ b/examples/auth/src/app/(payload)/admin/importMap.js
@@ -0,0 +1,5 @@
+import { BeforeLogin as BeforeLogin_8a7ab0eb7ab5c511aba12e68480bfe5e } from '@/components/BeforeLogin'
+
+export const importMap = {
+ '@/components/BeforeLogin#BeforeLogin': BeforeLogin_8a7ab0eb7ab5c511aba12e68480bfe5e,
+}
diff --git a/examples/auth/src/app/(payload)/layout.tsx b/examples/auth/src/app/(payload)/layout.tsx
index cfcc0bcb0c3..d75f6b2371e 100644
--- a/examples/auth/src/app/(payload)/layout.tsx
+++ b/examples/auth/src/app/(payload)/layout.tsx
@@ -1,16 +1,32 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
-import configPromise from '@payload-config'
+import type { ServerFunctionClient } from 'payload'
+
import '@payloadcms/next/css'
-import { RootLayout } from '@payloadcms/next/layouts'
+import config from '@payload-config'
+import { handleServerFunctions, RootLayout } from '@payloadcms/next/layouts'
import React from 'react'
+import { importMap } from './admin/importMap.js'
import './custom.scss'
type Args = {
children: React.ReactNode
}
-const Layout = ({ children }: Args) => {children}
+const serverFunction: ServerFunctionClient = async function (args) {
+ 'use server'
+ return handleServerFunctions({
+ ...args,
+ config,
+ importMap,
+ })
+}
+
+const Layout = ({ children }: Args) => (
+
+ {children}
+
+)
export default Layout
diff --git a/examples/auth/src/collections/Users.ts b/examples/auth/src/collections/Users.ts
index 96a8831d0f9..c02b1a5ec20 100644
--- a/examples/auth/src/collections/Users.ts
+++ b/examples/auth/src/collections/Users.ts
@@ -1,13 +1,62 @@
import type { CollectionConfig } from 'payload/types'
+import { admins } from './access/admins'
+import adminsAndUser from './access/adminsAndUser'
+import { anyone } from './access/anyone'
+import { checkRole } from './access/checkRole'
+import { loginAfterCreate } from './hooks/loginAfterCreate'
+import { protectRoles } from './hooks/protectRoles'
+
export const Users: CollectionConfig = {
slug: 'users',
+ auth: {
+ tokenExpiration: 28800, // 8 hours
+ cookies: {
+ sameSite: 'none',
+ secure: true,
+ domain: process.env.COOKIE_DOMAIN,
+ },
+ },
admin: {
useAsTitle: 'email',
},
- auth: true,
+ access: {
+ read: adminsAndUser,
+ create: anyone,
+ update: adminsAndUser,
+ delete: admins,
+ admin: ({ req: { user } }) => checkRole(['admin'], user),
+ },
+ hooks: {
+ afterChange: [loginAfterCreate],
+ },
fields: [
- // Email added by default
- // Add more fields as needed
+ {
+ name: 'firstName',
+ type: 'text',
+ },
+ {
+ name: 'lastName',
+ type: 'text',
+ },
+ {
+ name: 'roles',
+ type: 'select',
+ hasMany: true,
+ saveToJWT: true,
+ hooks: {
+ beforeChange: [protectRoles],
+ },
+ options: [
+ {
+ label: 'Admin',
+ value: 'admin',
+ },
+ {
+ label: 'User',
+ value: 'user',
+ },
+ ],
+ },
],
}
diff --git a/examples/auth/src/components/BeforeLogin/index.tsx b/examples/auth/src/components/BeforeLogin/index.tsx
index 5108a4fef6c..8d1613a06f5 100644
--- a/examples/auth/src/components/BeforeLogin/index.tsx
+++ b/examples/auth/src/components/BeforeLogin/index.tsx
@@ -1,6 +1,6 @@
import React from 'react'
-const BeforeLogin: React.FC = () => {
+export const BeforeLogin: React.FC = () => {
if (process.env.PAYLOAD_PUBLIC_SEED === 'true') {
return (
@@ -13,5 +13,3 @@ const BeforeLogin: React.FC = () => {
}
return null
}
-
-export default BeforeLogin
diff --git a/examples/auth/src/payload-types.ts b/examples/auth/src/payload-types.ts
index 66fdedb6792..c6140c0f1fd 100644
--- a/examples/auth/src/payload-types.ts
+++ b/examples/auth/src/payload-types.ts
@@ -7,16 +7,53 @@
*/
export interface Config {
+ auth: {
+ users: UserAuthOperations;
+ };
collections: {
users: User;
+ 'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration;
};
+ collectionsJoins: {};
+ collectionsSelect: {
+ users: UsersSelect | UsersSelect;
+ 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect;
+ 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect;
+ 'payload-migrations': PayloadMigrationsSelect | PayloadMigrationsSelect;
+ };
+ db: {
+ defaultIDType: string;
+ };
globals: {};
+ globalsSelect: {};
locale: null;
user: User & {
collection: 'users';
};
+ jobs: {
+ tasks: unknown;
+ workflows: unknown;
+ };
+}
+export interface UserAuthOperations {
+ forgotPassword: {
+ email: string;
+ password: string;
+ };
+ login: {
+ email: string;
+ password: string;
+ };
+ registerFirstUser: {
+ email: string;
+ password: string;
+ };
+ unlock: {
+ email: string;
+ password: string;
+ };
}
/**
* This interface was referenced by `Config`'s JSON-Schema
@@ -38,6 +75,24 @@ export interface User {
lockUntil?: string | null;
password?: string | null;
}
+/**
+ * This interface was referenced by `Config`'s JSON-Schema
+ * via the `definition` "payload-locked-documents".
+ */
+export interface PayloadLockedDocument {
+ id: string;
+ document?: {
+ relationTo: 'users';
+ value: string | User;
+ } | null;
+ globalSlug?: string | null;
+ user: {
+ relationTo: 'users';
+ value: string | User;
+ };
+ updatedAt: string;
+ createdAt: string;
+}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-preferences".
@@ -72,6 +127,63 @@ export interface PayloadMigration {
updatedAt: string;
createdAt: string;
}
+/**
+ * This interface was referenced by `Config`'s JSON-Schema
+ * via the `definition` "users_select".
+ */
+export interface UsersSelect {
+ firstName?: T;
+ lastName?: T;
+ roles?: T;
+ updatedAt?: T;
+ createdAt?: T;
+ email?: T;
+ resetPasswordToken?: T;
+ resetPasswordExpiration?: T;
+ salt?: T;
+ hash?: T;
+ loginAttempts?: T;
+ lockUntil?: T;
+}
+/**
+ * This interface was referenced by `Config`'s JSON-Schema
+ * via the `definition` "payload-locked-documents_select".
+ */
+export interface PayloadLockedDocumentsSelect {
+ document?: T;
+ globalSlug?: T;
+ user?: T;
+ updatedAt?: T;
+ createdAt?: T;
+}
+/**
+ * This interface was referenced by `Config`'s JSON-Schema
+ * via the `definition` "payload-preferences_select".
+ */
+export interface PayloadPreferencesSelect {
+ user?: T;
+ key?: T;
+ value?: T;
+ updatedAt?: T;
+ createdAt?: T;
+}
+/**
+ * This interface was referenced by `Config`'s JSON-Schema
+ * via the `definition` "payload-migrations_select".
+ */
+export interface PayloadMigrationsSelect {
+ name?: T;
+ batch?: T;
+ updatedAt?: T;
+ createdAt?: T;
+}
+/**
+ * This interface was referenced by `Config`'s JSON-Schema
+ * via the `definition` "auth".
+ */
+export interface Auth {
+ [k: string]: unknown;
+}
declare module 'payload' {
diff --git a/examples/auth/src/payload.config.ts b/examples/auth/src/payload.config.ts
index b52d2a295f6..e6f1a51cae7 100644
--- a/examples/auth/src/payload.config.ts
+++ b/examples/auth/src/payload.config.ts
@@ -2,28 +2,21 @@ import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { slateEditor } from '@payloadcms/richtext-slate'
import { fileURLToPath } from 'node:url'
import path from 'path'
-import { buildConfig } from 'payload/config'
+import { buildConfig } from 'payload'
import { Users } from './collections/Users'
-import BeforeLogin from './components/BeforeLogin'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export default buildConfig({
admin: {
components: {
- beforeLogin: [BeforeLogin],
+ beforeLogin: ['@/components/BeforeLogin#BeforeLogin'],
},
},
collections: [Users],
- cors: [
- process.env.PAYLOAD_PUBLIC_SERVER_URL || '',
- process.env.PAYLOAD_PUBLIC_SITE_URL || '',
- ].filter(Boolean),
- csrf: [
- process.env.PAYLOAD_PUBLIC_SERVER_URL || '',
- process.env.PAYLOAD_PUBLIC_SITE_URL || '',
- ].filter(Boolean),
+ cors: [process.env.NEXT_PUBLIC_SERVER_URL || ''].filter(Boolean),
+ csrf: [process.env.NEXT_PUBLIC_SERVER_URL || ''].filter(Boolean),
db: mongooseAdapter({
url: process.env.DATABASE_URI || '',
}),
diff --git a/examples/auth/tsconfig.json b/examples/auth/tsconfig.json
index 02d944fdeb8..0c6f225a40b 100644
--- a/examples/auth/tsconfig.json
+++ b/examples/auth/tsconfig.json
@@ -23,10 +23,25 @@
}
],
"paths": {
- "@/*": ["./src/*"],
- "@payload-config": ["src/payload.config.ts"]
- }
+ "@/*": [
+ "./src/*"
+ ],
+ "@payload-config": [
+ "src/payload.config.ts"
+ ],
+ "@payload-types": [
+ "src/payload-types.ts"
+ ]
+ },
+ "target": "ES2022",
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
- "exclude": ["node_modules"]
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ ".next/types/**/*.ts"
+ ],
+ "exclude": [
+ "node_modules"
+ ]
}
diff --git a/examples/custom-components/src/app/(payload)/layout.tsx b/examples/custom-components/src/app/(payload)/layout.tsx
index 7f8698e1380..d75f6b2371e 100644
--- a/examples/custom-components/src/app/(payload)/layout.tsx
+++ b/examples/custom-components/src/app/(payload)/layout.tsx
@@ -1,8 +1,8 @@
+/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
+/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
import type { ServerFunctionClient } from 'payload'
import '@payloadcms/next/css'
-/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
-/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
import config from '@payload-config'
import { handleServerFunctions, RootLayout } from '@payloadcms/next/layouts'
import React from 'react'