Skip to content

Commit 1b63ad4

Browse files
fix: verify view is inaccessible (#8557)
Fixes #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
1 parent 2a1321c commit 1b63ad4

File tree

66 files changed

+415
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+415
-375
lines changed

packages/graphql/src/resolvers/auth/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export function login(collection: Collection): any {
1919

2020
const result = await loginOperation(options)
2121
const cookie = generatePayloadCookie({
22-
collectionConfig: collection.config,
23-
payload: context.req.payload,
22+
collectionAuthConfig: collection.config.auth,
23+
cookiePrefix: context.req.payload.config.cookiePrefix,
2424
token: result.token,
2525
})
2626

packages/graphql/src/resolvers/auth/logout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export function logout(collection: Collection): any {
1313

1414
const result = await logoutOperation(options)
1515
const expiredCookie = generateExpiredPayloadCookie({
16-
collectionConfig: collection.config,
17-
payload: context.req.payload,
16+
collectionAuthConfig: collection.config.auth,
17+
config: context.req.payload.config,
18+
cookiePrefix: context.req.payload.config.cookiePrefix,
1819
})
1920
context.headers['Set-Cookie'] = expiredCookie
2021
return result

packages/graphql/src/resolvers/auth/refresh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export function refresh(collection: Collection): any {
1414

1515
const result = await refreshOperation(options)
1616
const cookie = generatePayloadCookie({
17-
collectionConfig: collection.config,
18-
payload: context.req.payload,
17+
collectionAuthConfig: collection.config.auth,
18+
cookiePrefix: context.req.payload.config.cookiePrefix,
1919
token: result.refreshedToken,
2020
})
2121
context.headers['Set-Cookie'] = cookie

packages/graphql/src/resolvers/auth/resetPassword.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export function resetPassword(collection: Collection): any {
2323

2424
const result = await resetPasswordOperation(options)
2525
const cookie = generatePayloadCookie({
26-
collectionConfig: collection.config,
27-
payload: context.req.payload,
26+
collectionAuthConfig: collection.config.auth,
27+
cookiePrefix: context.req.payload.config.cookiePrefix,
2828
token: result.token,
2929
})
3030
context.headers['Set-Cookie'] = cookie
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.form-header {
2+
display: flex;
3+
flex-direction: column;
4+
gap: calc(var(--base) * .5);
5+
margin-bottom: var(--base);
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
3+
import './index.scss'
4+
5+
const baseClass = 'form-header'
6+
7+
type Props = {
8+
description?: React.ReactNode | string
9+
heading: string
10+
}
11+
export function FormHeader({ description, heading }: Props) {
12+
if (!heading) {
13+
return null
14+
}
15+
16+
return (
17+
<div className={baseClass}>
18+
<h1>{heading}</h1>
19+
{Boolean(description) && <p>{description}</p>}
20+
</div>
21+
)
22+
}

packages/next/src/routes/rest/auth/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export const login: CollectionRouteHandler = async ({ collection, req }) => {
2929
})
3030

3131
const cookie = generatePayloadCookie({
32-
collectionConfig: collection.config,
33-
payload: req.payload,
32+
collectionAuthConfig: collection.config.auth,
33+
cookiePrefix: req.payload.config.cookiePrefix,
3434
token: result.token,
3535
})
3636

packages/next/src/routes/rest/auth/logout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export const logout: CollectionRouteHandler = async ({ collection, req }) => {
3030
}
3131

3232
const expiredCookie = generateExpiredPayloadCookie({
33-
collectionConfig: collection.config,
34-
payload: req.payload,
33+
collectionAuthConfig: collection.config.auth,
34+
config: req.payload.config,
35+
cookiePrefix: req.payload.config.cookiePrefix,
3536
})
3637

3738
headers.set('Set-Cookie', expiredCookie)

packages/next/src/routes/rest/auth/refresh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export const refresh: CollectionRouteHandler = async ({ collection, req }) => {
2020

2121
if (result.setCookie) {
2222
const cookie = generatePayloadCookie({
23-
collectionConfig: collection.config,
24-
payload: req.payload,
23+
collectionAuthConfig: collection.config.auth,
24+
cookiePrefix: req.payload.config.cookiePrefix,
2525
token: result.refreshedToken,
2626
})
2727

packages/next/src/routes/rest/auth/registerFirstUser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const registerFirstUser: CollectionRouteHandler = async ({ collection, re
2828
})
2929

3030
const cookie = generatePayloadCookie({
31-
collectionConfig: collection.config,
32-
payload: req.payload,
31+
collectionAuthConfig: collection.config.auth,
32+
cookiePrefix: req.payload.config.cookiePrefix,
3333
token: result.token,
3434
})
3535

0 commit comments

Comments
 (0)