Compare commits

...

2 Commits

Author SHA1 Message Date
Alessio Gravili
aca8811081 simplify 2025-04-25 16:39:39 +02:00
Alessio Gravili
cc09cd990a chore: reproduce postgres bug when updating currently logged-in user 2025-04-25 16:13:03 +02:00
2 changed files with 42 additions and 0 deletions

View File

@@ -33,6 +33,23 @@ export default buildConfigWithDefaults({
admin: {
useAsTitle: 'custom',
},
hooks: {
afterChange: [
async ({ req, doc, operation }) => {
if (operation === 'update') {
// This afterChange hook is required to reproduce the "should update user with afterChange hook while logged in with same user" test
await req.payload.create({
collection: 'relationsCollection',
depth: 0,
overrideAccess: true,
data: {
rel: doc?.id,
},
})
}
},
],
},
auth: {
cookies: {
domain: undefined,

View File

@@ -1045,5 +1045,30 @@ describe('Auth', () => {
expect(emailValidation('user@-example.com', mockContext)).toBe('validation:emailAddress')
expect(emailValidation('user@example-.com', mockContext)).toBe('validation:emailAddress')
})
it('should update user with afterChange hook while logged in with same user', async () => {
// Reproduces a bug where updating the user causes payload to hang on postgres.
const { user } = await payload.login({
collection: slug,
data: {
email: 'dev@payloadcms.com',
password: 'test',
},
})
const updatedUser = await payload.update({
collection: slug,
where: {
id: {
equals: user.id,
},
},
data: {
email: user.email,
},
})
expect(updatedUser.docs).toHaveLength(1)
expect(updatedUser?.docs?.[0]?.email).toStrictEqual(user.email)
})
})
})