Revert "fix: issues creating the first user (#5986)"
This reverts commit 0ede95f375.
This commit is contained in:
@@ -6,16 +6,16 @@ import { useComponentMap } from '@payloadcms/ui/providers/ComponentMap'
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
export const CreateFirstUserFields: React.FC<{
|
export const CreateFirstUserFields: React.FC<{
|
||||||
baseAuthFieldMap: FieldMap
|
createFirstUserFieldMap: FieldMap
|
||||||
userSlug: string
|
userSlug: string
|
||||||
}> = ({ baseAuthFieldMap, userSlug }) => {
|
}> = ({ createFirstUserFieldMap, userSlug }) => {
|
||||||
const { getFieldMap } = useComponentMap()
|
const { getFieldMap } = useComponentMap()
|
||||||
|
|
||||||
const fieldMap = getFieldMap({ collectionSlug: userSlug })
|
const fieldMap = getFieldMap({ collectionSlug: userSlug })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RenderFields
|
<RenderFields
|
||||||
fieldMap={[...(baseAuthFieldMap || []), ...(fieldMap || [])]}
|
fieldMap={[...(createFirstUserFieldMap || []), ...(fieldMap || [])]}
|
||||||
operation="create"
|
operation="create"
|
||||||
path=""
|
path=""
|
||||||
readOnly={false}
|
readOnly={false}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageRe
|
|||||||
},
|
},
|
||||||
} = initPageResult
|
} = initPageResult
|
||||||
|
|
||||||
const baseAuthFields: Field[] = [
|
const fields: Field[] = [
|
||||||
{
|
{
|
||||||
name: 'email',
|
name: 'email',
|
||||||
type: 'email',
|
type: 'email',
|
||||||
@@ -52,29 +52,16 @@ export const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageRe
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const ssrAuthFields = [...baseAuthFields]
|
|
||||||
|
|
||||||
const WithServerSideProps: WithServerSidePropsType = ({ Component, ...rest }) => {
|
const WithServerSideProps: WithServerSidePropsType = ({ Component, ...rest }) => {
|
||||||
return <WithServerSidePropsGeneric Component={Component} payload={payload} {...rest} />
|
return <WithServerSidePropsGeneric Component={Component} payload={payload} {...rest} />
|
||||||
}
|
}
|
||||||
|
|
||||||
const userFieldSchema = config.collections.find((c) => c.slug === userSlug)
|
const createFirstUserFieldMap = mapFields({
|
||||||
ssrAuthFields.push(...userFieldSchema.fields)
|
|
||||||
|
|
||||||
const formState = await buildStateFromSchema({
|
|
||||||
fieldSchema: ssrAuthFields,
|
|
||||||
operation: 'create',
|
|
||||||
preferences: {
|
|
||||||
fields: undefined
|
|
||||||
},
|
|
||||||
req,
|
|
||||||
})
|
|
||||||
|
|
||||||
const baseAuthFieldMap = mapFields({
|
|
||||||
WithServerSideProps,
|
WithServerSideProps,
|
||||||
config,
|
config,
|
||||||
fieldSchema: baseAuthFields,
|
fieldSchema: fields,
|
||||||
i18n,
|
i18n,
|
||||||
|
parentPath: userSlug,
|
||||||
}).map((field) => {
|
}).map((field) => {
|
||||||
// Transform field types for the password and confirm-password fields
|
// Transform field types for the password and confirm-password fields
|
||||||
if (field.name === 'password') {
|
if (field.name === 'password') {
|
||||||
@@ -96,6 +83,13 @@ export const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageRe
|
|||||||
return field
|
return field
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const formState = await buildStateFromSchema({
|
||||||
|
fieldSchema: fields,
|
||||||
|
operation: 'create',
|
||||||
|
preferences: { fields: {} },
|
||||||
|
req,
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<h1>{req.t('general:welcome')}</h1>
|
<h1>{req.t('general:welcome')}</h1>
|
||||||
@@ -107,7 +101,10 @@ export const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageRe
|
|||||||
redirect={adminRoute}
|
redirect={adminRoute}
|
||||||
validationOperation="create"
|
validationOperation="create"
|
||||||
>
|
>
|
||||||
<CreateFirstUserFields baseAuthFieldMap={baseAuthFieldMap} userSlug={userSlug} />
|
<CreateFirstUserFields
|
||||||
|
createFirstUserFieldMap={createFirstUserFieldMap}
|
||||||
|
userSlug={userSlug}
|
||||||
|
/>
|
||||||
<FormSubmit>{req.t('general:create')}</FormSubmit>
|
<FormSubmit>{req.t('general:create')}</FormSubmit>
|
||||||
</Form>
|
</Form>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export const Auth: React.FC<Props> = (props) => {
|
|||||||
name="password"
|
name="password"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<ConfirmPassword disabled={readOnly} name="confirm-password" />
|
<ConfirmPassword disabled={readOnly} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export const ResetPassword: React.FC<AdminViewProps> = ({ initPageResult, params
|
|||||||
name="password"
|
name="password"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<ConfirmPassword name="confirm-password" />
|
<ConfirmPassword />
|
||||||
<HiddenInput forceUsePathFromProps name="token" value={token} />
|
<HiddenInput forceUsePathFromProps name="token" value={token} />
|
||||||
<FormSubmit>{i18n.t('authentication:resetPassword')}</FormSubmit>
|
<FormSubmit>{i18n.t('authentication:resetPassword')}</FormSubmit>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { Description, FormField, Validate } from 'payload/types'
|
import type { FormField } from 'payload/types'
|
||||||
|
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback } from 'react'
|
||||||
|
|
||||||
import type { FormFieldBase } from '../shared/index.js'
|
|
||||||
|
|
||||||
import { FieldError } from '../../forms/FieldError/index.js'
|
import { FieldError } from '../../forms/FieldError/index.js'
|
||||||
import { FieldLabel } from '../../forms/FieldLabel/index.js'
|
import { FieldLabel } from '../../forms/FieldLabel/index.js'
|
||||||
import { useFormFields } from '../../forms/Form/context.js'
|
import { useFormFields } from '../../forms/Form/context.js'
|
||||||
@@ -12,36 +10,13 @@ import { useField } from '../../forms/useField/index.js'
|
|||||||
import { useTranslation } from '../../providers/Translation/index.js'
|
import { useTranslation } from '../../providers/Translation/index.js'
|
||||||
import { fieldBaseClass } from '../shared/index.js'
|
import { fieldBaseClass } from '../shared/index.js'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
export type ConfirmPasswordFieldProps = FormFieldBase & {
|
|
||||||
autoComplete?: string
|
export type ConfirmPasswordFieldProps = {
|
||||||
className?: string
|
|
||||||
description?: Description
|
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
label?: string
|
|
||||||
name: string
|
|
||||||
path?: string
|
|
||||||
required?: boolean
|
|
||||||
style?: React.CSSProperties
|
|
||||||
validate?: Validate
|
|
||||||
width?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ConfirmPassword: React.FC<ConfirmPasswordFieldProps> = (props) => {
|
export const ConfirmPassword: React.FC<ConfirmPasswordFieldProps> = (props) => {
|
||||||
const {
|
const { disabled } = props
|
||||||
name,
|
|
||||||
CustomError,
|
|
||||||
CustomLabel,
|
|
||||||
autoComplete,
|
|
||||||
className,
|
|
||||||
disabled,
|
|
||||||
errorProps,
|
|
||||||
label,
|
|
||||||
labelProps,
|
|
||||||
path: pathFromProps,
|
|
||||||
required,
|
|
||||||
style,
|
|
||||||
width,
|
|
||||||
} = props
|
|
||||||
|
|
||||||
const password = useFormFields<FormField>(([fields]) => fields.password)
|
const password = useFormFields<FormField>(([fields]) => fields.password)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@@ -61,8 +36,11 @@ export const ConfirmPassword: React.FC<ConfirmPasswordFieldProps> = (props) => {
|
|||||||
[password, t],
|
[password, t],
|
||||||
)
|
)
|
||||||
|
|
||||||
const { formProcessing, path, setValue, showError, value } = useField({
|
const path = 'confirm-password'
|
||||||
path: pathFromProps || name,
|
|
||||||
|
const { setValue, showError, value } = useField({
|
||||||
|
disableFormData: true,
|
||||||
|
path,
|
||||||
validate,
|
validate,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -80,9 +58,9 @@ export const ConfirmPassword: React.FC<ConfirmPasswordFieldProps> = (props) => {
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
disabled={formProcessing || disabled}
|
disabled={!!disabled}
|
||||||
id={`field-${path.replace(/\./g, '__')}`}
|
id="field-confirm-password"
|
||||||
name={path}
|
name="confirm-password"
|
||||||
onChange={setValue}
|
onChange={setValue}
|
||||||
type="password"
|
type="password"
|
||||||
value={(value as string) || ''}
|
value={(value as string) || ''}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ const EmailField: React.FC<EmailFieldProps> = (props) => {
|
|||||||
|
|
||||||
const { path, setValue, showError, value } = useField({
|
const { path, setValue, showError, value } = useField({
|
||||||
path: pathFromContext || pathFromProps || name,
|
path: pathFromContext || pathFromProps || name,
|
||||||
validate: typeof validate === 'function' ? memoizedValidate : undefined,
|
validate: memoizedValidate,
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -216,31 +216,29 @@ export default buildConfigWithDefaults({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
onInit: async (payload) => {
|
onInit: async (payload) => {
|
||||||
if (process.env.SKIP_ON_INIT !== 'true') {
|
await payload.create({
|
||||||
await payload.create({
|
collection: 'users',
|
||||||
collection: 'users',
|
data: {
|
||||||
data: {
|
custom: 'Hello, world!',
|
||||||
custom: 'Hello, world!',
|
email: devUser.email,
|
||||||
email: devUser.email,
|
password: devUser.password,
|
||||||
password: devUser.password,
|
},
|
||||||
},
|
})
|
||||||
})
|
|
||||||
|
|
||||||
await payload.create({
|
await payload.create({
|
||||||
collection: 'api-keys',
|
collection: 'api-keys',
|
||||||
data: {
|
data: {
|
||||||
apiKey: uuid(),
|
apiKey: uuid(),
|
||||||
enableAPIKey: true,
|
enableAPIKey: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
await payload.create({
|
await payload.create({
|
||||||
collection: 'api-keys',
|
collection: 'api-keys',
|
||||||
data: {
|
data: {
|
||||||
apiKey: uuid(),
|
apiKey: uuid(),
|
||||||
enableAPIKey: true,
|
enableAPIKey: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
import type { Page } from '@playwright/test'
|
import type { Page } from '@playwright/test'
|
||||||
|
|
||||||
import { expect, test } from '@playwright/test'
|
import { expect, test } from '@playwright/test'
|
||||||
import { devUser } from 'credentials.js'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { wait } from 'payload/utilities'
|
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
import { v4 as uuid } from 'uuid'
|
|
||||||
|
|
||||||
import type { PayloadTestSDK } from '../helpers/sdk/index.js'
|
import type { PayloadTestSDK } from '../helpers/sdk/index.js'
|
||||||
import type { Config } from './payload-types.js'
|
import type { Config } from './payload-types.js'
|
||||||
|
|
||||||
import { initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers.js'
|
import { initPageConsoleErrorCatch, login, saveDocAndAssert } from '../helpers.js'
|
||||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
||||||
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
|
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
|
||||||
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
|
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
|
||||||
@@ -21,37 +18,25 @@ const dirname = path.dirname(filename)
|
|||||||
|
|
||||||
let payload: PayloadTestSDK<Config>
|
let payload: PayloadTestSDK<Config>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Auth
|
||||||
|
* create first user
|
||||||
|
* unlock
|
||||||
|
* log out
|
||||||
|
*/
|
||||||
|
|
||||||
const { beforeAll, describe } = test
|
const { beforeAll, describe } = test
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}
|
}
|
||||||
|
|
||||||
const createFirstUser = async ({ page, serverURL }: { page: Page; serverURL: string }) => {
|
|
||||||
await page.goto(serverURL + '/admin/create-first-user')
|
|
||||||
await page.locator('#field-email').fill(devUser.email)
|
|
||||||
await page.locator('#field-password').fill(devUser.password)
|
|
||||||
await page.locator('#field-confirm-password').fill(devUser.password)
|
|
||||||
await page.locator('#field-custom').fill('Hello, world!')
|
|
||||||
|
|
||||||
await wait(500)
|
|
||||||
|
|
||||||
await page.locator('.form-submit > button').click()
|
|
||||||
|
|
||||||
await expect
|
|
||||||
.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT })
|
|
||||||
.not.toContain('create-first-user')
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('auth', () => {
|
describe('auth', () => {
|
||||||
let page: Page
|
let page: Page
|
||||||
let url: AdminUrlUtil
|
let url: AdminUrlUtil
|
||||||
let serverURL: string
|
let serverURL: string
|
||||||
let apiURL: string
|
let apiURL: string
|
||||||
|
|
||||||
// Allows for testing create-first-user
|
|
||||||
process.env.SKIP_ON_INIT = 'true'
|
|
||||||
|
|
||||||
beforeAll(async ({ browser }) => {
|
beforeAll(async ({ browser }) => {
|
||||||
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({ dirname }))
|
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({ dirname }))
|
||||||
apiURL = `${serverURL}/api`
|
apiURL = `${serverURL}/api`
|
||||||
@@ -61,22 +46,11 @@ describe('auth', () => {
|
|||||||
page = await context.newPage()
|
page = await context.newPage()
|
||||||
initPageConsoleErrorCatch(page)
|
initPageConsoleErrorCatch(page)
|
||||||
|
|
||||||
await createFirstUser({ page, serverURL })
|
//await delayNetwork({ context, page, delay: 'Slow 4G' })
|
||||||
|
|
||||||
await payload.create({
|
await login({
|
||||||
collection: 'api-keys',
|
page,
|
||||||
data: {
|
serverURL,
|
||||||
apiKey: uuid(),
|
|
||||||
enableAPIKey: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await payload.create({
|
|
||||||
collection: 'api-keys',
|
|
||||||
data: {
|
|
||||||
apiKey: uuid(),
|
|
||||||
enableAPIKey: true,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -383,11 +383,9 @@ describe('fields - relationship', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
await page.goto(url.create)
|
await page.goto(url.create)
|
||||||
// wait for relationship options to load
|
|
||||||
const relationFilterOptionsReq = page.waitForResponse(/api\/relation-filter-true/)
|
|
||||||
// select relationshipMany field that relies on siblingData field above
|
// select relationshipMany field that relies on siblingData field above
|
||||||
await page.locator('#field-relationshipManyFiltered .rs__control').click()
|
await page.locator('#field-relationshipManyFiltered .rs__control').click()
|
||||||
await relationFilterOptionsReq
|
|
||||||
|
|
||||||
const options = page.locator('#field-relationshipManyFiltered .rs__menu')
|
const options = page.locator('#field-relationshipManyFiltered .rs__menu')
|
||||||
await expect(options).toContainText('truth')
|
await expect(options).toContainText('truth')
|
||||||
|
|||||||
Reference in New Issue
Block a user