mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Fix race condition when updating multiple refresh tokens at the same time
This commit is contained in:
parent
0f1ac3d686
commit
65a5bbf422
@ -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,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user