From 680ed1dec866cae396acbed5fa67e608dbdf6ccd Mon Sep 17 00:00:00 2001 From: Jarrod Flesch <30633324+JarrodMFlesch@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:38:32 -0400 Subject: [PATCH] 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. --- docs/admin/overview.mdx | 31 ++++++++++++++++++- .../next/src/utilities/initPage/shared.ts | 1 + packages/next/src/views/Document/index.tsx | 3 +- .../next/src/views/Root/getViewFromConfig.tsx | 2 +- .../src/auth/operations/forgotPassword.ts | 2 +- packages/payload/src/config/defaults.ts | 1 + packages/payload/src/config/schema.ts | 1 + packages/payload/src/config/types.ts | 2 ++ 8 files changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/admin/overview.mdx b/docs/admin/overview.mdx index 4d649b578..df2f5fea2 100644 --- a/docs/admin/overview.mdx +++ b/docs/admin/overview.mdx @@ -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) | | `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) | -| `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 @@ -88,3 +88,32 @@ Users in the admin panel have access to choosing between light mode and dark mod ### 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. + +### 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' + } + }, +}) +``` diff --git a/packages/next/src/utilities/initPage/shared.ts b/packages/next/src/utilities/initPage/shared.ts index c311a3c91..c09058b8c 100644 --- a/packages/next/src/utilities/initPage/shared.ts +++ b/packages/next/src/utilities/initPage/shared.ts @@ -8,6 +8,7 @@ const authRouteKeys: (keyof SanitizedConfig['admin']['routes'])[] = [ 'forgot', 'inactivity', 'unauthorized', + 'reset', ] export const isAdminRoute = (route: string, adminRoute: string) => { diff --git a/packages/next/src/views/Document/index.tsx b/packages/next/src/views/Document/index.tsx index cc83a778d..c5530cacb 100644 --- a/packages/next/src/views/Document/index.tsx +++ b/packages/next/src/views/Document/index.tsx @@ -1,6 +1,5 @@ import type { EditViewComponent } from 'payload/config' -import type { AdminViewComponent, ServerSideEditViewProps } from 'payload/types' -import type { AdminViewProps } from 'payload/types' +import type { AdminViewComponent, AdminViewProps, ServerSideEditViewProps } from 'payload/types' import { DocumentHeader } from '@payloadcms/ui/elements/DocumentHeader' import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser' diff --git a/packages/next/src/views/Root/getViewFromConfig.tsx b/packages/next/src/views/Root/getViewFromConfig.tsx index c0c92d329..5fb2247ca 100644 --- a/packages/next/src/views/Root/getViewFromConfig.tsx +++ b/packages/next/src/views/Root/getViewFromConfig.tsx @@ -26,7 +26,7 @@ const baseClasses = { } type OneSegmentViews = { - [K in keyof SanitizedConfig['admin']['routes']]: AdminViewComponent + [K in Exclude]: AdminViewComponent } const oneSegmentViews: OneSegmentViews = { diff --git a/packages/payload/src/auth/operations/forgotPassword.ts b/packages/payload/src/auth/operations/forgotPassword.ts index 68ed0784e..0e20aa23f 100644 --- a/packages/payload/src/auth/operations/forgotPassword.ts +++ b/packages/payload/src/auth/operations/forgotPassword.ts @@ -108,7 +108,7 @@ export const forgotPasswordOperation = async (incomingArgs: Arguments): Promise< : `${protocol}//${req.headers.get('host')}` let html = `${req.t('authentication:youAreReceivingResetPassword')} - ${serverURL}${config.routes.admin}/reset/${token} + ${serverURL}${config.routes.admin}/${config.admin.routes.reset}/${token} ${req.t('authentication:youDidNotRequestPassword')}` if (typeof collectionConfig.auth.forgotPassword.generateEmailHTML === 'function') { diff --git a/packages/payload/src/config/defaults.ts b/packages/payload/src/config/defaults.ts index e4d1b021f..eead72c8e 100644 --- a/packages/payload/src/config/defaults.ts +++ b/packages/payload/src/config/defaults.ts @@ -18,6 +18,7 @@ export const defaults: Omit = { inactivity: '/logout-inactivity', login: '/login', logout: '/logout', + reset: '/reset', unauthorized: '/unauthorized', }, }, diff --git a/packages/payload/src/config/schema.ts b/packages/payload/src/config/schema.ts index 3e49d23c0..8ba704a62 100644 --- a/packages/payload/src/config/schema.ts +++ b/packages/payload/src/config/schema.ts @@ -90,6 +90,7 @@ export default joi.object({ inactivity: joi.string(), login: joi.string(), logout: joi.string(), + reset: joi.string(), unauthorized: joi.string(), }), user: joi.string(), diff --git a/packages/payload/src/config/types.ts b/packages/payload/src/config/types.ts index 137510c2e..b9ae77549 100644 --- a/packages/payload/src/config/types.ts +++ b/packages/payload/src/config/types.ts @@ -564,6 +564,8 @@ export type Config = { login?: string /** The route for the logout page. */ logout?: string + /** The route for the reset password page. */ + reset?: string /** The route for the unauthorized page. */ unauthorized?: string }