fix: on password reset, delete all refresh tokens
This commit is contained in:
parent
a6dd112e4a
commit
b71da7dcc9
@ -25,6 +25,11 @@ await tap.test('PUT /users/reset-password', async (t) => {
|
|||||||
return userExample
|
return userExample
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
sinon.stub(prisma, 'refreshToken').value({
|
||||||
|
deleteMany: async () => {
|
||||||
|
return { count: 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
const response = await application.inject({
|
const response = await application.inject({
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url: '/users/reset-password',
|
url: '/users/reset-password',
|
||||||
|
@ -39,7 +39,7 @@ export const putResetPasswordUser: FastifyPluginAsync = async (fastify) => {
|
|||||||
user?.temporaryExpirationToken != null &&
|
user?.temporaryExpirationToken != null &&
|
||||||
user.temporaryExpirationToken.getTime() > Date.now()
|
user.temporaryExpirationToken.getTime() > Date.now()
|
||||||
if (user == null || !isValidTemporaryToken) {
|
if (user == null || !isValidTemporaryToken) {
|
||||||
throw fastify.httpErrors.badRequest('"tempToken" is invalid')
|
throw fastify.httpErrors.badRequest('`temporaryToken` is invalid.')
|
||||||
}
|
}
|
||||||
const hashedPassword = await bcrypt.hash(password, 12)
|
const hashedPassword = await bcrypt.hash(password, 12)
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
@ -52,6 +52,11 @@ export const putResetPasswordUser: FastifyPluginAsync = async (fastify) => {
|
|||||||
temporaryExpirationToken: null
|
temporaryExpirationToken: null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
await prisma.refreshToken.deleteMany({
|
||||||
|
where: {
|
||||||
|
userId: user.id
|
||||||
|
}
|
||||||
|
})
|
||||||
reply.statusCode = 200
|
reply.statusCode = 200
|
||||||
return 'The new password has been saved!'
|
return 'The new password has been saved!'
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user