mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
fix(db): read the checks a write relies on in the transaction that writes
On Postgres a check read before a transaction, or outside one, no longer holds at the write that follows: the pool runs other requests' writes in between. Moved into the unit of work that writes: - the last-admin guard of an admin's role edit and of an account deletion (deleteUserCompletely takes a precondition run in its transaction) - the login lockout guards of the auth settings save and the SSO settings save - the first-account check of an SSO sign-up, which starts over as an ordinary sign-up when another account won - the OAuth client caps, the token cap and the mail intake limits - the year check before a vacay year is opened, and the label name check of a rename A password sign-up that loses the last use of an invite is now refused, as the SSO sign-up already was, and a reset link is burned by one conditional update, so two resets with one link cannot both change the password.
This commit is contained in:
@@ -110,10 +110,12 @@ export class PasswordResetTokensRepository extends TrekRepository<PasswordResetT
|
||||
/**
|
||||
* `UPDATE password_reset_tokens SET consumed_at = CURRENT_TIMESTAMP WHERE
|
||||
* id = ?` (AU41, `resetPassword` — burns the token being used, first
|
||||
* statement inside the password-change transaction).
|
||||
* statement inside the password-change transaction), and only while the
|
||||
* token is unused: whether this call burned it. Two resets with one link
|
||||
* at once both read it unused, and only one of them may go on.
|
||||
*/
|
||||
async markConsumed(id: number): Promise<void> {
|
||||
async markConsumed(id: number): Promise<boolean> {
|
||||
const platform = this.getEntityManager().getPlatform();
|
||||
await this.nativeUpdate({ id }, { consumed_at: currentTimestamp(platform) });
|
||||
return (await this.nativeUpdate({ id, consumed_at: null }, { consumed_at: currentTimestamp(platform) })) === 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user