Fix race condition when updating multiple refresh tokens at the same time

This commit is contained in:
Konstantin Wohlwend 2025-09-09 13:54:03 -07:00
parent 0f1ac3d686
commit 65a5bbf422

View File

@ -141,18 +141,18 @@ export const connectedAccountAccessTokenCrudHandlers = createLazyProxy(() => cre
});
if (tokenSet.refreshToken) {
// remove the old token, add the new token to the DB
await prisma.oAuthToken.deleteMany({
where: {
refreshToken: token.refreshToken,
},
// mark the old token as invalid, add the new token to the DB
const oldToken = token;
await prisma.oAuthToken.update({
where: { id: oldToken.id },
data: { isValid: false },
});
await prisma.oAuthToken.create({
data: {
tenancyId: auth.tenancy.id,
refreshToken: tokenSet.refreshToken,
oauthAccountId: token.projectUserOAuthAccount.id,
scopes: token.scopes,
oauthAccountId: oldToken.projectUserOAuthAccount.id,
scopes: oldToken.scopes,
}
});
}