fix: allows navigation to reset-pw route, adds customization for route (#6778)

Fixes https://github.com/payloadcms/payload/issues/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.
This commit is contained in:
Jarrod Flesch
2024-06-14 12:38:32 -04:00
committed by GitHub
parent ddc3ab534e
commit 680ed1dec8
8 changed files with 38 additions and 5 deletions

View File

@@ -45,7 +45,7 @@ All options for the Admin panel are defined in your base Payload config file.
| `components` | Component overrides that affect the entirety of the Admin panel. [More](/docs/admin/components) | | `components` | Component overrides that affect the entirety of the Admin panel. [More](/docs/admin/components) |
| `webpack` | Customize the Webpack config that's used to generate the Admin panel. [More](/docs/admin/webpack) | | `webpack` | Customize the Webpack config that's used to generate the Admin panel. [More](/docs/admin/webpack) |
| `vite` | Customize the Vite config that's used to generate the Admin panel. [More](/docs/admin/vite) | | `vite` | Customize the Vite config that's used to generate the Admin panel. [More](/docs/admin/vite) |
| `routes` | Replace built-in Admin Panel routes with your own custom routes. I.e. `{ logout: '/custom-logout', inactivity: 'custom-inactivity' }` | | `routes` | Replace built-in Admin Panel routes with your own custom routes. [More](/docs/admin/overview#custom-admin-panel-routes) |
### The Admin User Collection ### The Admin User Collection
@@ -88,3 +88,32 @@ Users in the admin panel have access to choosing between light mode and dark mod
### Restricting user access ### Restricting user access
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. 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.
### Custom admin panel routes
You can configure custom routes in the admin panel for the following routes:
| Option | Default route |
| ----------------- | ----------------------- |
| `account` | `/account` |
| `createFirstUser` | `/create-first-user` |
| `forgot` | `/forgot` |
| `inactivity` | `/logout-inactivity` |
| `login` | `/login` |
| `logout` | `/logout` |
| `reset` | `/reset` |
| `unauthorized` | `/unauthorized` |
`payload.config.js`:
```ts
import { buildConfig } from 'payload/config'
const config = buildConfig({
admin: {
routes: {
admin: '/custom-admin-route'
}
},
})
```

View File

@@ -8,6 +8,7 @@ const authRouteKeys: (keyof SanitizedConfig['admin']['routes'])[] = [
'forgot', 'forgot',
'inactivity', 'inactivity',
'unauthorized', 'unauthorized',
'reset',
] ]
export const isAdminRoute = (route: string, adminRoute: string) => { export const isAdminRoute = (route: string, adminRoute: string) => {

View File

@@ -1,6 +1,5 @@
import type { EditViewComponent } from 'payload/config' import type { EditViewComponent } from 'payload/config'
import type { AdminViewComponent, ServerSideEditViewProps } from 'payload/types' import type { AdminViewComponent, AdminViewProps, ServerSideEditViewProps } from 'payload/types'
import type { AdminViewProps } from 'payload/types'
import { DocumentHeader } from '@payloadcms/ui/elements/DocumentHeader' import { DocumentHeader } from '@payloadcms/ui/elements/DocumentHeader'
import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser' import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'

View File

@@ -26,7 +26,7 @@ const baseClasses = {
} }
type OneSegmentViews = { type OneSegmentViews = {
[K in keyof SanitizedConfig['admin']['routes']]: AdminViewComponent [K in Exclude<keyof SanitizedConfig['admin']['routes'], 'reset'>]: AdminViewComponent
} }
const oneSegmentViews: OneSegmentViews = { const oneSegmentViews: OneSegmentViews = {

View File

@@ -108,7 +108,7 @@ export const forgotPasswordOperation = async (incomingArgs: Arguments): Promise<
: `${protocol}//${req.headers.get('host')}` : `${protocol}//${req.headers.get('host')}`
let html = `${req.t('authentication:youAreReceivingResetPassword')} let html = `${req.t('authentication:youAreReceivingResetPassword')}
<a href="${serverURL}${config.routes.admin}/reset/${token}">${serverURL}${config.routes.admin}/reset/${token}</a> <a href="${serverURL}${config.routes.admin}/${config.admin.routes.reset}/${token}">${serverURL}${config.routes.admin}/${config.admin.routes.reset}/${token}</a>
${req.t('authentication:youDidNotRequestPassword')}` ${req.t('authentication:youDidNotRequestPassword')}`
if (typeof collectionConfig.auth.forgotPassword.generateEmailHTML === 'function') { if (typeof collectionConfig.auth.forgotPassword.generateEmailHTML === 'function') {

View File

@@ -18,6 +18,7 @@ export const defaults: Omit<Config, 'db' | 'editor' | 'secret'> = {
inactivity: '/logout-inactivity', inactivity: '/logout-inactivity',
login: '/login', login: '/login',
logout: '/logout', logout: '/logout',
reset: '/reset',
unauthorized: '/unauthorized', unauthorized: '/unauthorized',
}, },
}, },

View File

@@ -90,6 +90,7 @@ export default joi.object({
inactivity: joi.string(), inactivity: joi.string(),
login: joi.string(), login: joi.string(),
logout: joi.string(), logout: joi.string(),
reset: joi.string(),
unauthorized: joi.string(), unauthorized: joi.string(),
}), }),
user: joi.string(), user: joi.string(),

View File

@@ -564,6 +564,8 @@ export type Config = {
login?: string login?: string
/** The route for the logout page. */ /** The route for the logout page. */
logout?: string logout?: string
/** The route for the reset password page. */
reset?: string
/** The route for the unauthorized page. */ /** The route for the unauthorized page. */
unauthorized?: string unauthorized?: string
} }