chore!: adjusts auth hydration from server (#7545)

Fixes https://github.com/payloadcms/payload/issues/6823

Allows the server to initialize the AuthProvider via props. Renames
`HydrateClientUser` to `HydrateAuthProvider`. It now only hydrates the
permissions as the user can be set from props. Permissions can be
initialized from props, but still need to be hydrated for some pages as
access control can be specific to docs/lists etc.

**BREAKING CHANGE**
- Renames exported `HydrateClientUser` to `HydrateAuthProvider`
This commit is contained in:
Jarrod Flesch
2024-08-07 11:10:53 -04:00
committed by GitHub
parent 4a20a63563
commit e905675a05
19 changed files with 190 additions and 109 deletions

View File

@@ -158,7 +158,7 @@ describe('auth', () => {
test('should have up-to-date user in `useAuth` hook', async () => {
await page.goto(url.account)
await page.waitForURL(url.account)
await expect(page.locator('#users-api-result')).toHaveText('')
await expect(page.locator('#users-api-result')).toHaveText('Hello, world!')
await expect(page.locator('#use-auth-result')).toHaveText('Hello, world!')
const field = page.locator('#field-custom')
await field.fill('Goodbye, world!')

View File

@@ -22,7 +22,7 @@
* - specify locales to show
*/
import type { Page } from '@playwright/test'
import type { BrowserContext, Page } from '@playwright/test'
import { expect, test } from '@playwright/test'
import path from 'path'
@@ -40,6 +40,7 @@ import {
initPageConsoleErrorCatch,
saveDocAndAssert,
selectTableRow,
throttleTest,
} from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
@@ -86,6 +87,8 @@ const waitForAutoSaveToRunAndComplete = async (page: Page) => {
await waitForAutoSaveToComplete(page)
}
let context: BrowserContext
describe('versions', () => {
let page: Page
let url: AdminUrlUtil
@@ -100,7 +103,7 @@ describe('versions', () => {
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({ dirname }))
const context = await browser.newContext()
context = await browser.newContext()
page = await context.newPage()
initPageConsoleErrorCatch(page)
@@ -317,14 +320,14 @@ describe('versions', () => {
await saveDocAndAssert(page, '#action-save-draft')
const savedDocURL = page.url()
await page.goto(`${savedDocURL}/versions`)
await page.waitForURL(new RegExp(`${savedDocURL}/versions`))
await page.waitForURL(`${savedDocURL}/versions`)
const row2 = page.locator('tbody .row-2')
const versionID = await row2.locator('.cell-id').textContent()
await page.goto(`${savedDocURL}/versions/${versionID}`)
await page.waitForURL(new RegExp(`${savedDocURL}/versions/${versionID}`))
await page.waitForURL(`${savedDocURL}/versions/${versionID}`)
await page.locator('.restore-version__button').click()
await page.locator('button:has-text("Confirm")').click()
await page.waitForURL(new RegExp(savedDocURL))
await page.waitForURL(savedDocURL)
await expect(page.locator('#field-title')).toHaveValue('v1')
})
@@ -417,9 +420,7 @@ describe('versions', () => {
const spanishTitle = 'spanish title'
const newDescription = 'new description'
await page.goto(autosaveURL.create)
// gets redirected from /create to /slug/id due to autosave
await page.waitForURL(new RegExp(`${autosaveURL.edit('')}`))
await wait(500)
await waitForAutoSaveToComplete(page)
const titleField = page.locator('#field-title')
await expect(titleField).toBeEnabled()
await titleField.fill(englishTitle)
@@ -483,9 +484,7 @@ describe('versions', () => {
test('collection — autosave should only update the current document', async () => {
await page.goto(autosaveURL.create)
// gets redirected from /create to /slug/id due to autosave
await page.waitForURL(new RegExp(`${autosaveURL.edit('')}`))
await wait(500)
await waitForAutoSaveToComplete(page)
await expect(page.locator('#field-title')).toBeEnabled()
await page.locator('#field-title').fill('first post title')
await expect(page.locator('#field-description')).toBeEnabled()
@@ -493,8 +492,6 @@ describe('versions', () => {
await saveDocAndAssert(page)
await waitForAutoSaveToComplete(page) // Make sure nothing is auto-saving before next steps
await page.goto(autosaveURL.create)
// gets redirected from /create to /slug/id due to autosave
await page.waitForURL(new RegExp(`${autosaveURL.edit('')}`))
await waitForAutoSaveToComplete(page) // Make sure nothing is auto-saving before next steps
await wait(500)
await expect(page.locator('#field-title')).toBeEnabled()