Skip to content

Commit 76fc27a

Browse files
committed
feat(basic-example): Add basic-example project
1 parent da224a0 commit 76fc27a

38 files changed

+3671
-174
lines changed

examples/basic/.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Payload
2+
DATABASE_URI=postgres://postgres:<password>@127.0.0.1:5432/your-database-name
3+
PAYLOAD_SECRET=YOUR_SECRET_HERE
4+
5+
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
6+
7+
# Auth.js
8+
AUTH_SECRET=YOUR_SECRET_HERE
9+
AUTH_GITHUB_ID=YOUR_GITHUB_ID
10+
AUTH_GITHUB_SECRET=YOUR_GITHUB_SECRET

examples/basic/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
/.idea/*
10+
!/.idea/runConfigurations
11+
12+
# testing
13+
/coverage
14+
15+
# next.js
16+
/.next/
17+
/out/
18+
19+
# production
20+
/build
21+
22+
# misc
23+
.DS_Store
24+
*.pem
25+
26+
# debug
27+
npm-debug.log*
28+
yarn-debug.log*
29+
yarn-error.log*
30+
31+
# local env files
32+
.env*.local
33+
34+
# vercel
35+
.vercel
36+
37+
# typescript
38+
*.tsbuildinfo
39+
next-env.d.ts
40+
41+
.env
42+
43+
/media

examples/basic/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Basic Example

examples/basic/eslint.config.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { dirname } from 'path'
2+
import { fileURLToPath } from 'url'
3+
import { FlatCompat } from '@eslint/eslintrc'
4+
5+
const __filename = fileURLToPath(import.meta.url)
6+
const __dirname = dirname(__filename)
7+
8+
const compat = new FlatCompat({
9+
baseDirectory: __dirname,
10+
})
11+
12+
const eslintConfig = [
13+
...compat.extends('next/core-web-vitals', 'next/typescript'),
14+
{
15+
rules: {
16+
'@typescript-eslint/ban-ts-comment': 'warn',
17+
'@typescript-eslint/no-empty-object-type': 'warn',
18+
'@typescript-eslint/no-explicit-any': 'warn',
19+
'@typescript-eslint/no-unused-vars': [
20+
'warn',
21+
{
22+
vars: 'all',
23+
args: 'after-used',
24+
ignoreRestSiblings: false,
25+
argsIgnorePattern: '^_',
26+
varsIgnorePattern: '^_',
27+
destructuredArrayIgnorePattern: '^_',
28+
caughtErrorsIgnorePattern: '^(_|ignore)',
29+
},
30+
],
31+
},
32+
},
33+
]
34+
35+
export default eslintConfig

examples/basic/next.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { withPayload } from "@payloadcms/next/withPayload";
2+
3+
/** @type {import('next').NextConfig} */
4+
const nextConfig = {};
5+
6+
export default withPayload(nextConfig);

examples/basic/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "basic-example",
3+
"version": "1.0.0",
4+
"description": "A basic example of Payload CMS using payload-authjs plugin",
5+
"private": true,
6+
"type": "module",
7+
"scripts": {
8+
"build": "cross-env NODE_OPTIONS=--no-deprecation next build",
9+
"dev": "cross-env NODE_OPTIONS=--no-deprecation next dev",
10+
"devsafe": "rm -rf .next && cross-env NODE_OPTIONS=--no-deprecation next dev",
11+
"generate:importmap": "cross-env NODE_OPTIONS=--no-deprecation payload generate:importmap",
12+
"generate:types": "cross-env NODE_OPTIONS=--no-deprecation payload generate:types",
13+
"lint": "cross-env NODE_OPTIONS=--no-deprecation next lint",
14+
"payload": "cross-env NODE_OPTIONS=--no-deprecation payload",
15+
"start": "cross-env NODE_OPTIONS=--no-deprecation next start"
16+
},
17+
"dependencies": {
18+
"@payloadcms/db-postgres": "^3.19.0",
19+
"@payloadcms/next": "^3.19.0",
20+
"@payloadcms/richtext-lexical": "^3.19.0",
21+
"cross-env": "^7.0.3",
22+
"graphql": "^16.10.0",
23+
"next": "15.1.6",
24+
"next-auth": "5.0.0-beta.25",
25+
"payload": "^3.19.0",
26+
"react": "19.0.0",
27+
"react-dom": "19.0.0",
28+
"sharp": "0.32.6",
29+
"payload-authjs": "workspace:*"
30+
},
31+
"devDependencies": {
32+
"@eslint/eslintrc": "^3.2.0",
33+
"@types/node": "^22.10.10",
34+
"@types/react": "19.0.8",
35+
"@types/react-dom": "19.0.3",
36+
"eslint": "^9.19.0",
37+
"eslint-config-next": "15.1.6",
38+
"typescript": "5.7.3"
39+
},
40+
"engines": {
41+
"node": "^18.20.2 || >=20.9.0"
42+
}
43+
}

examples/basic/project.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
3+
"sourceRoot": "examples/basic/src",
4+
"projectType": "application",
5+
"targets": {}
6+
}

examples/basic/src/_middleware.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import NextAuth from "next-auth";
2+
import { authConfig } from "./auth.config";
3+
4+
const { auth: middleware } = NextAuth(authConfig);
5+
export default middleware;
6+
7+
export const config = {
8+
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
9+
};
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { signIn } from "@/auth";
2-
3-
export function SignInButton() {
4-
return (
5-
<form
6-
action={async () => {
7-
"use server";
8-
await signIn();
9-
}}
10-
>
11-
<button type="submit">Sign In</button>
12-
</form>
13-
);
14-
}
1+
import { signIn } from "@/auth";
2+
3+
export function SignInButton() {
4+
return (
5+
<form
6+
action={async () => {
7+
"use server";
8+
await signIn("github");
9+
}}
10+
>
11+
<button type="submit">Sign In</button>
12+
</form>
13+
);
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use client";
2+
3+
import type { CollectionSlug } from "payload";
4+
5+
export function SignOutButton({
6+
userCollectionSlug = "users",
7+
}: {
8+
userCollectionSlug?: CollectionSlug;
9+
}) {
10+
return (
11+
<button
12+
type="button"
13+
onClick={async () => {
14+
await fetch(`/api/${userCollectionSlug}/logout`, {
15+
method: "POST",
16+
headers: {
17+
"Content-Type": "application/json",
18+
},
19+
}).then(() => {
20+
window.location.reload();
21+
});
22+
}}
23+
>
24+
Sign Out
25+
</button>
26+
);
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
html,
2+
body {
3+
font-family: "Roboto", "Inter", sans-serif;
4+
}
5+
6+
main {
7+
max-width: 37.5rem;
8+
margin-top: 5rem;
9+
margin-bottom: 5rem;
10+
margin-left: auto;
11+
margin-right: auto;
12+
}
13+
14+
button {
15+
cursor: pointer;
16+
background: #ededed;
17+
padding: 10px 25px;
18+
border-radius: 10px;
19+
border: 2px solid #ccc;
20+
}
21+
22+
pre {
23+
background: #ededed;
24+
padding: 15px;
25+
border-radius: 10px;
26+
overflow: auto;
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "./globals.scss";
2+
3+
export default function RootLayout({ children }: { children: React.ReactNode }) {
4+
return (
5+
<html lang="en">
6+
<body>{children}</body>
7+
</html>
8+
);
9+
}

examples/basic/src/app/(app)/page.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { auth } from "@/auth";
2+
import { getPayloadUser } from "payload-authjs";
3+
import { SignInButton } from "./_components/SignInButton";
4+
import { SignOutButton } from "./_components/SignOutButton";
5+
6+
const Page = async () => {
7+
const session = await auth();
8+
const payloadUser = await getPayloadUser();
9+
10+
return (
11+
<main>
12+
{payloadUser ? <SignOutButton /> : <SignInButton />}
13+
<br />
14+
<h3>Auth.js Session</h3>
15+
<pre>{JSON.stringify(session?.user, null, 2)}</pre>
16+
<br />
17+
<h3>Payload CMS User</h3>
18+
<pre>{JSON.stringify(payloadUser, null, 2)}</pre>
19+
</main>
20+
);
21+
};
22+
23+
export default Page;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { handlers } from "@/auth";
2+
3+
export const { GET, POST } = handlers;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
2+
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
3+
import type { Metadata } from 'next'
4+
5+
import config from '@payload-config'
6+
import { NotFoundPage, generatePageMetadata } from '@payloadcms/next/views'
7+
import { importMap } from '../importMap'
8+
9+
type Args = {
10+
params: Promise<{
11+
segments: string[]
12+
}>
13+
searchParams: Promise<{
14+
[key: string]: string | string[]
15+
}>
16+
}
17+
18+
export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
19+
generatePageMetadata({ config, params, searchParams })
20+
21+
const NotFound = ({ params, searchParams }: Args) =>
22+
NotFoundPage({ config, params, searchParams, importMap })
23+
24+
export default NotFound
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
2+
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
3+
import type { Metadata } from 'next'
4+
5+
import config from '@payload-config'
6+
import { RootPage, generatePageMetadata } from '@payloadcms/next/views'
7+
import { importMap } from '../importMap'
8+
9+
type Args = {
10+
params: Promise<{
11+
segments: string[]
12+
}>
13+
searchParams: Promise<{
14+
[key: string]: string | string[]
15+
}>
16+
}
17+
18+
export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
19+
generatePageMetadata({ config, params, searchParams })
20+
21+
const Page = ({ params, searchParams }: Args) =>
22+
RootPage({ config, params, searchParams, importMap })
23+
24+
export default Page
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { SignInWithAuthjsButton as SignInWithAuthjsButton_06d0cb594d8f6ba2ac35015f930c882e } from 'payload-authjs/components'
2+
3+
export const importMap = {
4+
"payload-authjs/components#SignInWithAuthjsButton": SignInWithAuthjsButton_06d0cb594d8f6ba2ac35015f930c882e
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
2+
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
3+
import config from '@payload-config'
4+
import '@payloadcms/next/css'
5+
import {
6+
REST_DELETE,
7+
REST_GET,
8+
REST_OPTIONS,
9+
REST_PATCH,
10+
REST_POST,
11+
REST_PUT,
12+
} from '@payloadcms/next/routes'
13+
14+
export const GET = REST_GET(config)
15+
export const POST = REST_POST(config)
16+
export const DELETE = REST_DELETE(config)
17+
export const PATCH = REST_PATCH(config)
18+
export const PUT = REST_PUT(config)
19+
export const OPTIONS = REST_OPTIONS(config)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
2+
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
3+
import config from '@payload-config'
4+
import '@payloadcms/next/css'
5+
import { GRAPHQL_PLAYGROUND_GET } from '@payloadcms/next/routes'
6+
7+
export const GET = GRAPHQL_PLAYGROUND_GET(config)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
2+
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
3+
import config from '@payload-config'
4+
import { GRAPHQL_POST, REST_OPTIONS } from '@payloadcms/next/routes'
5+
6+
export const POST = GRAPHQL_POST(config)
7+
8+
export const OPTIONS = REST_OPTIONS(config)

examples/basic/src/app/(payload)/custom.scss

Whitespace-only changes.

0 commit comments

Comments
 (0)