fix: local req missing url headers (#6126)

Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
This commit is contained in:
James Mikrut
2024-04-29 16:40:59 -04:00
committed by GitHub
parent b6631f4778
commit d8c3127b09
2 changed files with 23 additions and 1 deletions

View File

@@ -51,7 +51,7 @@ const attachFakeURLProperties = (req: PayloadRequestWithData) => {
// @ts-expect-error // @ts-expect-error
if (!req.origin) req.origin = getURLObject().origin if (!req.origin) req.origin = getURLObject().origin
// @ts-expect-error // @ts-expect-error
if (!req?.url) req.url = getURLObject().url if (!req?.url) req.url = getURLObject().href
} }
type CreateLocalReq = ( type CreateLocalReq = (
@@ -84,6 +84,8 @@ export const createLocalReq: CreateLocalReq = async (
} }
} }
// @ts-expect-error
if (!req.headers) req.headers = new Headers()
req.context = getRequestContext(req, context) req.context = getRequestContext(req, context)
req.payloadAPI = req?.payloadAPI || 'local' req.payloadAPI = req?.payloadAPI || 'local'
req.payload = payload req.payload = payload

View File

@@ -730,5 +730,25 @@ describe('Auth', () => {
expect(authenticated.token).toBeTruthy() expect(authenticated.token).toBeTruthy()
}) })
it('should forget and reset password', async () => {
const forgot = await payload.forgotPassword({
collection: 'users',
data: {
email: 'dev@payloadcms.com',
},
})
const reset = await payload.resetPassword({
collection: 'users',
overrideAccess: true,
data: {
password: 'test',
token: forgot,
},
})
expect(reset.user.email).toStrictEqual('dev@payloadcms.com')
})
}) })
}) })