Skip to content

Commit 0c5321e

Browse files
authored
chore: temporarily revert 10597 (#10718)
Temporarily reverts 10597 to fix plugin-oauth
1 parent 9a87699 commit 0c5321e

38 files changed

+220
-45
lines changed

packages/next/src/exports/utilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export const mergeHeaders = _mergeHeaders
2323

2424
/**
2525
* @deprecated
26-
* This function is not needed anymore for public usage. CORS headers are applied by default to response.
26+
* Use:
27+
* ```ts
28+
* import { headersWithCors } from 'payload'
2729
* ```
2830
*/
2931
export const headersWithCors = _headersWithCors

packages/payload/src/auth/endpoints/access.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@ import { status as httpStatus } from 'http-status'
22

33
import type { PayloadHandler } from '../../config/types.js'
44

5+
import { headersWithCors } from '../../utilities/headersWithCors.js'
56
import { accessOperation } from '../operations/access.js'
67

78
export const accessHandler: PayloadHandler = async (req) => {
9+
const headers = headersWithCors({
10+
headers: new Headers(),
11+
req,
12+
})
13+
814
try {
915
const results = await accessOperation({
1016
req,
1117
})
1218

1319
return Response.json(results, {
20+
headers,
1421
status: httpStatus.OK,
1522
})
1623
} catch (e: unknown) {
@@ -19,6 +26,7 @@ export const accessHandler: PayloadHandler = async (req) => {
1926
error: e,
2027
},
2128
{
29+
headers,
2230
status: httpStatus.INTERNAL_SERVER_ERROR,
2331
},
2432
)

packages/payload/src/auth/endpoints/forgotPassword.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { status as httpStatus } from 'http-status'
33
import type { PayloadHandler } from '../../config/types.js'
44

55
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
6+
import { headersWithCors } from '../../utilities/headersWithCors.js'
67
import { forgotPasswordOperation } from '../operations/forgotPassword.js'
78

89
export const forgotPasswordHandler: PayloadHandler = async (req) => {
@@ -32,6 +33,10 @@ export const forgotPasswordHandler: PayloadHandler = async (req) => {
3233
message: t('general:success'),
3334
},
3435
{
36+
headers: headersWithCors({
37+
headers: new Headers(),
38+
req,
39+
}),
3540
status: httpStatus.OK,
3641
},
3742
)
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PayloadHandler } from '../../config/types.js'
22

33
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
4+
import { headersWithCors } from '../../utilities/headersWithCors.js'
45
import { initOperation } from '../operations/init.js'
56

67
export const initHandler: PayloadHandler = async (req) => {
@@ -9,5 +10,13 @@ export const initHandler: PayloadHandler = async (req) => {
910
req,
1011
})
1112

12-
return Response.json({ initialized })
13+
return Response.json(
14+
{ initialized },
15+
{
16+
headers: headersWithCors({
17+
headers: new Headers(),
18+
req,
19+
}),
20+
},
21+
)
1322
}

packages/payload/src/auth/endpoints/login.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { status as httpStatus } from 'http-status'
33
import type { PayloadHandler } from '../../config/types.js'
44

55
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
6+
import { headersWithCors } from '../../utilities/headersWithCors.js'
67
import { isNumber } from '../../utilities/isNumber.js'
78
import { generatePayloadCookie } from '../cookies.js'
89
import { loginOperation } from '../operations/login.js'
@@ -46,8 +47,11 @@ export const loginHandler: PayloadHandler = async (req) => {
4647
...result,
4748
},
4849
{
49-
headers: new Headers({
50-
'Set-Cookie': cookie,
50+
headers: headersWithCors({
51+
headers: new Headers({
52+
'Set-Cookie': cookie,
53+
}),
54+
req,
5155
}),
5256
status: httpStatus.OK,
5357
},

packages/payload/src/auth/endpoints/logout.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { status as httpStatus } from 'http-status'
33
import type { PayloadHandler } from '../../config/types.js'
44

55
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
6+
import { headersWithCors } from '../../utilities/headersWithCors.js'
67
import { generateExpiredPayloadCookie } from '../cookies.js'
78
import { logoutOperation } from '../operations/logout.js'
89

@@ -14,12 +15,18 @@ export const logoutHandler: PayloadHandler = async (req) => {
1415
req,
1516
})
1617

18+
const headers = headersWithCors({
19+
headers: new Headers(),
20+
req,
21+
})
22+
1723
if (!result) {
1824
return Response.json(
1925
{
2026
message: t('error:logoutFailed'),
2127
},
2228
{
29+
headers,
2330
status: httpStatus.BAD_REQUEST,
2431
},
2532
)
@@ -31,9 +38,7 @@ export const logoutHandler: PayloadHandler = async (req) => {
3138
cookiePrefix: req.payload.config.cookiePrefix,
3239
})
3340

34-
const headers = new Headers({
35-
'Set-Cookie': expiredCookie,
36-
})
41+
headers.set('Set-Cookie', expiredCookie)
3742

3843
return Response.json(
3944
{

packages/payload/src/auth/endpoints/me.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { status as httpStatus } from 'http-status'
33
import type { PayloadHandler } from '../../config/types.js'
44

55
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
6+
import { headersWithCors } from '../../utilities/headersWithCors.js'
67
import { extractJWT } from '../extractJWT.js'
78
import { meOperation } from '../operations/me.js'
89

@@ -26,6 +27,10 @@ export const meHandler: PayloadHandler = async (req) => {
2627
message: req.t('authentication:account'),
2728
},
2829
{
30+
headers: headersWithCors({
31+
headers: new Headers(),
32+
req,
33+
}),
2934
status: httpStatus.OK,
3035
},
3136
)

packages/payload/src/auth/endpoints/refresh.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import { status as httpStatus } from 'http-status'
33
import type { PayloadHandler } from '../../config/types.js'
44

55
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
6+
import { headersWithCors } from '../../utilities/headersWithCors.js'
67
import { generatePayloadCookie } from '../cookies.js'
78
import { refreshOperation } from '../operations/refresh.js'
89

910
export const refreshHandler: PayloadHandler = async (req) => {
1011
const collection = getRequestCollection(req)
1112
const { t } = req
1213

13-
const headers = new Headers()
14+
const headers = headersWithCors({
15+
headers: new Headers(),
16+
req,
17+
})
1418

1519
const result = await refreshOperation({
1620
collection,

packages/payload/src/auth/endpoints/registerFirstUser.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { status as httpStatus } from 'http-status'
33
import type { PayloadHandler } from '../../config/types.js'
44

55
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
6+
import { headersWithCors } from '../../utilities/headersWithCors.js'
67
import { generatePayloadCookie } from '../cookies.js'
78
import { registerFirstUserOperation } from '../operations/registerFirstUser.js'
89

@@ -43,8 +44,11 @@ export const registerFirstUserHandler: PayloadHandler = async (req) => {
4344
user: result.user,
4445
},
4546
{
46-
headers: new Headers({
47-
'Set-Cookie': cookie,
47+
headers: headersWithCors({
48+
headers: new Headers({
49+
'Set-Cookie': cookie,
50+
}),
51+
req,
4852
}),
4953
status: httpStatus.OK,
5054
},

packages/payload/src/auth/endpoints/resetPassword.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { status as httpStatus } from 'http-status'
33
import type { PayloadHandler } from '../../config/types.js'
44

55
import { getRequestCollection } from '../../utilities/getRequestEntity.js'
6+
import { headersWithCors } from '../../utilities/headersWithCors.js'
67
import { generatePayloadCookie } from '../cookies.js'
78
import { resetPasswordOperation } from '../operations/resetPassword.js'
89

@@ -37,8 +38,11 @@ export const resetPasswordHandler: PayloadHandler = async (req) => {
3738
...result,
3839
},
3940
{
40-
headers: new Headers({
41-
'Set-Cookie': cookie,
41+
headers: headersWithCors({
42+
headers: new Headers({
43+
'Set-Cookie': cookie,
44+
}),
45+
req,
4246
}),
4347
status: httpStatus.OK,
4448
},

0 commit comments

Comments
 (0)