Skip to content

Commit 3c40241

Browse files
authored
fix(next): forgot password basePath was not respected (#16084)
Fixes #16082 Disables autoLogin for the `base-path` suite as it is not possible to test this with auto login enabled --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1213836723510261
1 parent 8530b45 commit 3c40241

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

packages/next/src/views/ForgotPassword/ForgotPasswordForm/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { FormProps } from '@payloadcms/ui'
44
import type { FormState, PayloadRequest } from 'payload'
55

66
import { EmailField, Form, FormSubmit, TextField, useConfig, useTranslation } from '@payloadcms/ui'
7-
import { email, text } from 'payload/shared'
7+
import { email, formatAdminURL, text } from 'payload/shared'
88
import React, { useState } from 'react'
99

1010
import { FormHeader } from '../../../elements/FormHeader/index.js'
@@ -14,7 +14,7 @@ export const ForgotPasswordForm: React.FC = () => {
1414

1515
const {
1616
admin: { user: userSlug },
17-
routes: { api },
17+
routes: { api: apiRoute },
1818
} = config
1919

2020
const { t } = useTranslation()
@@ -65,7 +65,10 @@ export const ForgotPasswordForm: React.FC = () => {
6565

6666
return (
6767
<Form
68-
action={`${api}/${userSlug}/forgot-password`}
68+
action={formatAdminURL({
69+
apiRoute,
70+
path: `/${userSlug}/forgot-password`,
71+
})}
6972
handleResponse={handleResponse}
7073
initialState={initialState}
7174
method="POST"

test/base-path/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { BASE_PATH } from './shared.js'
66
process.env.NEXT_BASE_PATH = BASE_PATH
77

88
export default buildConfigWithDefaults({
9+
admin: {
10+
autoLogin: false,
11+
},
912
collections: [
1013
Posts,
1114
{

test/base-path/e2e.spec.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import type { Page } from '@playwright/test'
22

33
import { expect, test } from '@playwright/test'
44
import path from 'path'
5+
import { wait } from 'payload/shared'
56
import { fileURLToPath } from 'url'
67

8+
import { login } from '../__helpers/e2e/auth/login.js'
9+
import { goToListDoc } from '../__helpers/e2e/goToListDoc.js'
710
import {
811
ensureCompilationIsDone,
912
initPageConsoleErrorCatch,
1013
saveDocAndAssert,
1114
} from '../__helpers/e2e/helpers.js'
1215
import { AdminUrlUtil } from '../__helpers/shared/adminUrlUtil.js'
13-
import { goToListDoc } from '../__helpers/e2e/goToListDoc.js'
1416
import { initPayloadE2ENoConfig } from '../__helpers/shared/initPayloadE2ENoConfig.js'
1517
import { TEST_TIMEOUT_LONG } from '../playwright.config.js'
1618
import { BASE_PATH } from './shared.js'
@@ -39,17 +41,36 @@ test.describe('Base Path', () => {
3941
initPageConsoleErrorCatch(page)
4042

4143
await ensureCompilationIsDone({
44+
noAutoLogin: true,
4245
page,
4346
serverURL,
4447
})
4548
})
4649

50+
test('should submit forgot-password form with correct basePath in action', async () => {
51+
await page.goto(`${url.admin}/forgot`)
52+
53+
// Verify the form action includes the basePath prefix
54+
await expect(async () => {
55+
const formAction = await page.locator('form').getAttribute('action')
56+
expect(formAction).toContain('/cms/api/users/forgot-password')
57+
}).toPass()
58+
59+
// Fill in the email field and submit
60+
await page.locator('#field-email').fill('dev@payloadcms.com')
61+
await page.locator('button[type="submit"]').click()
62+
63+
// Verify success state renders — proves the POST went to the correct URL
64+
await expect(page.locator('.form-header h1')).toHaveText('Email Sent')
65+
})
66+
4767
test('should navigate to posts collection by clicking nav link', async () => {
4868
// Navigate to the admin dashboard
69+
await login({ page, serverURL })
4970
await page.goto(url.admin)
5071

5172
// click first dashboard card
52-
await page.locator('.dashboard__card-list .card').first().click()
73+
await page.locator('.collections__card-list .card').first().click()
5374

5475
// should navigate to basePath url
5576
await expect.poll(() => page.url()).toContain('/cms/admin/collections/posts')

0 commit comments

Comments
 (0)