Skip to content

Commit 7292220

Browse files
authored
chore(examples): updates auth example to latest (#10090)
The auth example was still on `v3.0.0-beta.24`, was missing its users collection config, and was not yet using the component paths pattern established here: #7246. This updates to latest and fixes these issues. This example can still use further improvements and housekeeping which will come in future PRs.
1 parent dd3c2eb commit 7292220

File tree

20 files changed

+5092
-6761
lines changed

20 files changed

+5092
-6761
lines changed

examples/auth/.env.example

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# NOTE: Change port of `PAYLOAD_PUBLIC_SITE_URL` if front-end is running on another server
2-
PAYLOAD_PUBLIC_SITE_URL=http://localhost:3000
3-
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
1+
# Database connection string
2+
DATABASE_URI=mongodb://127.0.0.1/payload-draft-preview-example
3+
4+
# Used to encrypt JWT tokens
5+
PAYLOAD_SECRET=YOUR_SECRET_HERE
6+
7+
# Used to configure CORS, format links and more. No trailing slash
48
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
5-
DATABASE_URI=mongodb://127.0.0.1/payload-example-auth
6-
PAYLOAD_SECRET=PAYLOAD_AUTH_EXAMPLE_SECRET_KEY
9+
10+
# Used to share cookies across subdomains
711
COOKIE_DOMAIN=localhost

examples/auth/.eslintignore

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/auth/.eslintrc.cjs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
module.exports = {
2-
extends: ['plugin:@next/next/core-web-vitals', '@payloadcms'],
3-
ignorePatterns: ['**/payload-types.ts'],
4-
overrides: [
5-
{
6-
extends: ['plugin:@typescript-eslint/disable-type-checked'],
7-
files: ['*.js', '*.cjs', '*.json', '*.md', '*.yml', '*.yaml'],
8-
},
9-
],
10-
parserOptions: {
11-
project: ['./tsconfig.json'],
12-
tsconfigRootDir: __dirname,
13-
},
142
root: true,
3+
extends: ['@payloadcms'],
154
}

examples/auth/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build
22
dist
33
node_modules
4-
package - lock.json.env
4+
package-lock.json
5+
.env

examples/auth/.swcrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "https://json.schemastore.org/swcrc",
3+
"sourceMaps": true,
4+
"jsc": {
5+
"target": "esnext",
6+
"parser": {
7+
"syntax": "typescript",
8+
"tsx": true,
9+
"dts": true
10+
},
11+
"transform": {
12+
"react": {
13+
"runtime": "automatic",
14+
"pragmaFrag": "React.Fragment",
15+
"throwIfNamespace": true,
16+
"development": false,
17+
"useBuiltins": true
18+
}
19+
}
20+
},
21+
"module": {
22+
"type": "es6"
23+
}
24+
}

examples/auth/README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22

33
This [Payload Auth Example](https://github.com/payloadcms/payload/tree/main/examples/auth) demonstrates how to implement [Payload Authentication](https://payloadcms.com/docs/authentication/overview) into all types of applications. Follow the [Quick Start](#quick-start) to get up and running quickly.
44

5-
**IMPORTANT—This example includes a fully integrated Next.js App Router front-end that runs on the same server as Payload.** If you are working on an application running on an entirely separate server, the principals are generally the same. To learn more about this, [check out how Payload can be used in its various headless capacities](https://payloadcms.com/blog/the-ultimate-guide-to-using-nextjs-with-payload).
6-
75
## Quick Start
86

9-
To spin up this example locally, follow these steps:
7+
To spin up this example locally, follow the steps below:
108

119
1. Clone this repo
12-
1. `cd` into this directory and run `pnpm i --ignore-workspace`\*, `yarn`, or `npm install`
13-
14-
> \*If you are running using pnpm within the Payload Monorepo, the `--ignore-workspace` flag is needed so that pnpm generates a lockfile in this example's directory despite the fact that one exists in root.
10+
1. Navigate into the project directory and install dependencies using your preferred package manager:
1511

16-
1. `cp .env.example .env` to copy the example environment variables
12+
- `pnpm i --ignore-workspace`\*, `yarn`, or `npm install`
1713

18-
> Adjust `PAYLOAD_PUBLIC_SITE_URL` in the `.env` if your front-end is running on a separate domain or port.
14+
> \*NOTE: The --ignore-workspace flag is needed if you are running this example within the Payload monorepo to avoid workspace conflicts.
1915
20-
1. `pnpm dev`, `yarn dev` or `npm run dev` to start the server
21-
- Press `y` when prompted to seed the database
22-
1. `open http://localhost:3000` to access the home page
23-
1. `open http://localhost:3000/admin` to access the admin panel
24-
- Login with email `demo@payloadcms.com` and password `demo`
16+
1. Start the server:
17+
- Depending on your package manager, run `pnpm dev`, `yarn dev` or `npm run dev`
18+
- When prompted, type `y` then `enter` to seed the database with sample data
19+
1. Access the application:
20+
- Open your browser and navigate to `http://localhost:3000` to access the homepage.
21+
- Open `http://localhost:3000/admin` to access the admin panel.
22+
1. Login:
2523

26-
That's it! Changes made in `./src` will be reflected in your app. See the [Development](#development) section for more details.
24+
- Use the following credentials to log into the admin panel:
25+
> `Email: demo@payloadcms.com` > `Password: demo`
2726
2827
## How it works
2928

examples/auth/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.
5+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

examples/auth/package.json

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,39 @@
33
"version": "1.0.0",
44
"description": "Payload authentication example.",
55
"license": "MIT",
6+
"type": "module",
67
"main": "dist/server.js",
78
"scripts": {
8-
"build": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts NODE_OPTIONS=--no-deprecation next build",
9-
"dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts && pnpm seed && cross-env NODE_OPTIONS=--no-deprecation next dev",
10-
"generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema",
11-
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
12-
"lint": "cross-env NODE_OPTIONS=--no-deprecation next lint",
13-
"lint:fix": "eslint --fix --ext .ts,.tsx src",
14-
"payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload",
9+
"build": "cross-env NODE_OPTIONS=--no-deprecation next build",
10+
"dev": "cross-env NODE_OPTIONS=--no-deprecation && pnpm seed && next dev",
11+
"generate:importmap": "cross-env NODE_OPTIONS=--no-deprecation payload generate:importmap",
12+
"generate:schema": "payload-graphql generate:schema",
13+
"generate:types": "cross-env NODE_OPTIONS=--no-deprecation payload generate:types",
14+
"payload": "cross-env NODE_OPTIONS=--no-deprecation payload",
1515
"seed": "npm run payload migrate:fresh",
1616
"start": "cross-env NODE_OPTIONS=--no-deprecation next start"
1717
},
1818
"dependencies": {
19-
"@payloadcms/db-mongodb": "3.0.0-beta.24",
20-
"@payloadcms/next": "3.0.0-beta.24",
21-
"@payloadcms/richtext-slate": "3.0.0-beta.24",
22-
"@payloadcms/ui": "3.0.0-beta.24",
19+
"@payloadcms/db-mongodb": "latest",
20+
"@payloadcms/next": "latest",
21+
"@payloadcms/richtext-slate": "latest",
22+
"@payloadcms/ui": "latest",
2323
"cross-env": "^7.0.3",
24-
"next": "14.3.0-canary.68",
25-
"payload": "3.0.0-beta.24",
26-
"react": "^18.2.0",
27-
"react-dom": "^18.2.0",
24+
"next": "^15.0.0",
25+
"payload": "latest",
26+
"react": "19.0.0",
27+
"react-dom": "19.0.0",
2828
"react-hook-form": "^7.51.3"
2929
},
3030
"devDependencies": {
31-
"@next/eslint-plugin-next": "^13.1.6",
32-
"@payloadcms/eslint-config": "^1.1.1",
33-
"@swc/core": "^1.4.14",
34-
"@swc/types": "^0.1.6",
35-
"@types/node": "^20.11.25",
36-
"@types/react": "^18.2.64",
37-
"@types/react-dom": "^18.2.21",
38-
"dotenv": "^16.4.5",
31+
"@payloadcms/graphql": "latest",
32+
"@swc/core": "^1.6.13",
33+
"@types/ejs": "^3.1.5",
34+
"@types/react": "19.0.1",
35+
"@types/react-dom": "19.0.1",
3936
"eslint": "^8.57.0",
40-
"tsx": "^4.7.1",
41-
"typescript": "5.4.4"
37+
"eslint-config-next": "^15.0.0",
38+
"tsx": "^4.16.2",
39+
"typescript": "5.5.2"
4240
}
4341
}

0 commit comments

Comments
 (0)