fix: verify view is inaccessible (#8557)

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

Cleans up the way we redirect and where it happens.

## Improvements
- When you verify, the admin panel will display a toast when it
redirects you to the login route. This is contextually helpful as to
what is happening.
- Removes dead code path, as we always set the _verifiedToken to null
after it is used.

## `handleAdminPage` renamed to `getRouteInfo`
This function no longer handles routing. It kicks that responsibility
back up to the initPage function.

## `isAdminAuthRoute` renamed to `isPublicAdminRoute`
This was inversely named as it determines if a given route is public.
Also simplifies deterministic logic here.

## `redirectUnauthenticatedUser` argument
This is no longer used or needed. We can determine these things by using
the `isPublicAdminRoute` function.

## View Style fixes
- Reset Password
- Forgot Password
- Unauthorized
This commit is contained in:
Jarrod Flesch
2024-10-07 14:20:07 -04:00
committed by GitHub
parent 2a1321c813
commit 1b63ad4cb3
66 changed files with 417 additions and 377 deletions

View File

@@ -482,7 +482,7 @@ describe('access control', () => {
serverURL,
})
await expect(page.locator('.next-error-h1')).toBeVisible()
await expect(page.locator('.unauthorized')).toBeVisible()
await page.goto(logoutURL)
await page.waitForURL(logoutURL)
@@ -500,6 +500,7 @@ describe('access control', () => {
test('should block admin access to non-admin user', async () => {
const adminURL = `${serverURL}/admin`
const unauthorizedURL = `${serverURL}/admin/unauthorized`
await page.goto(adminURL)
await page.waitForURL(adminURL)
@@ -527,9 +528,9 @@ describe('access control', () => {
])
await page.goto(adminURL)
await page.waitForURL(adminURL)
await page.waitForURL(unauthorizedURL)
await expect(page.locator('.next-error-h1')).toBeVisible()
await expect(page.locator('.unauthorized')).toBeVisible()
})
})