Skip to content

Commit 680ed1d

Browse files
fix: allows navigation to reset-pw route, adds customization for route (#6778)
Fixes #6745 Fixes the inability to navigate to the reset password route. Adds the ability to customize the route and docs for all customizable admin panel routes.
1 parent ddc3ab5 commit 680ed1d

File tree

8 files changed

+38
-5
lines changed

8 files changed

+38
-5
lines changed

docs/admin/overview.mdx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ All options for the Admin panel are defined in your base Payload config file.
4545
| `components` | Component overrides that affect the entirety of the Admin panel. [More](/docs/admin/components) |
4646
| `webpack` | Customize the Webpack config that's used to generate the Admin panel. [More](/docs/admin/webpack) |
4747
| `vite` | Customize the Vite config that's used to generate the Admin panel. [More](/docs/admin/vite) |
48-
| `routes` | Replace built-in Admin Panel routes with your own custom routes. I.e. `{ logout: '/custom-logout', inactivity: 'custom-inactivity' }` |
48+
| `routes` | Replace built-in Admin Panel routes with your own custom routes. [More](/docs/admin/overview#custom-admin-panel-routes) |
4949

5050
### The Admin User Collection
5151

@@ -88,3 +88,32 @@ Users in the admin panel have access to choosing between light mode and dark mod
8888
### Restricting user access
8989

9090
If you would like to restrict which users from a single Collection can access the Admin panel, you can use the `admin` access control function. [Click here](/docs/access-control/overview#admin) to learn more.
91+
92+
### Custom admin panel routes
93+
94+
You can configure custom routes in the admin panel for the following routes:
95+
96+
| Option | Default route |
97+
| ----------------- | ----------------------- |
98+
| `account` | `/account` |
99+
| `createFirstUser` | `/create-first-user` |
100+
| `forgot` | `/forgot` |
101+
| `inactivity` | `/logout-inactivity` |
102+
| `login` | `/login` |
103+
| `logout` | `/logout` |
104+
| `reset` | `/reset` |
105+
| `unauthorized` | `/unauthorized` |
106+
107+
`payload.config.js`:
108+
109+
```ts
110+
import { buildConfig } from 'payload/config'
111+
112+
const config = buildConfig({
113+
admin: {
114+
routes: {
115+
admin: '/custom-admin-route'
116+
}
117+
},
118+
})
119+
```

packages/next/src/utilities/initPage/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const authRouteKeys: (keyof SanitizedConfig['admin']['routes'])[] = [
88
'forgot',
99
'inactivity',
1010
'unauthorized',
11+
'reset',
1112
]
1213

1314
export const isAdminRoute = (route: string, adminRoute: string) => {

packages/next/src/views/Document/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { EditViewComponent } from 'payload/config'
2-
import type { AdminViewComponent, ServerSideEditViewProps } from 'payload/types'
3-
import type { AdminViewProps } from 'payload/types'
2+
import type { AdminViewComponent, AdminViewProps, ServerSideEditViewProps } from 'payload/types'
43

54
import { DocumentHeader } from '@payloadcms/ui/elements/DocumentHeader'
65
import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'

packages/next/src/views/Root/getViewFromConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const baseClasses = {
2626
}
2727

2828
type OneSegmentViews = {
29-
[K in keyof SanitizedConfig['admin']['routes']]: AdminViewComponent
29+
[K in Exclude<keyof SanitizedConfig['admin']['routes'], 'reset'>]: AdminViewComponent
3030
}
3131

3232
const oneSegmentViews: OneSegmentViews = {

packages/payload/src/auth/operations/forgotPassword.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const forgotPasswordOperation = async (incomingArgs: Arguments): Promise<
108108
: `${protocol}//${req.headers.get('host')}`
109109

110110
let html = `${req.t('authentication:youAreReceivingResetPassword')}
111-
<a href="${serverURL}${config.routes.admin}/reset/${token}">${serverURL}${config.routes.admin}/reset/${token}</a>
111+
<a href="${serverURL}${config.routes.admin}/${config.admin.routes.reset}/${token}">${serverURL}${config.routes.admin}/${config.admin.routes.reset}/${token}</a>
112112
${req.t('authentication:youDidNotRequestPassword')}`
113113

114114
if (typeof collectionConfig.auth.forgotPassword.generateEmailHTML === 'function') {

packages/payload/src/config/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const defaults: Omit<Config, 'db' | 'editor' | 'secret'> = {
1818
inactivity: '/logout-inactivity',
1919
login: '/login',
2020
logout: '/logout',
21+
reset: '/reset',
2122
unauthorized: '/unauthorized',
2223
},
2324
},

packages/payload/src/config/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default joi.object({
9090
inactivity: joi.string(),
9191
login: joi.string(),
9292
logout: joi.string(),
93+
reset: joi.string(),
9394
unauthorized: joi.string(),
9495
}),
9596
user: joi.string(),

packages/payload/src/config/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ export type Config = {
564564
login?: string
565565
/** The route for the logout page. */
566566
logout?: string
567+
/** The route for the reset password page. */
568+
reset?: string
567569
/** The route for the unauthorized page. */
568570
unauthorized?: string
569571
}

0 commit comments

Comments
 (0)