diff --git a/packages/pds/src/api/com/atproto/server/updateEmail.ts b/packages/pds/src/api/com/atproto/server/updateEmail.ts index e0f9d9bc078..b3e4564bc98 100644 --- a/packages/pds/src/api/com/atproto/server/updateEmail.ts +++ b/packages/pds/src/api/com/atproto/server/updateEmail.ts @@ -35,9 +35,8 @@ export default function (server: Server, ctx: AppContext) { await ctx.db.transaction(async (dbTxn) => { const accntSrvce = ctx.services.account(dbTxn) - if (token) { - await accntSrvce.deleteEmailToken(did, 'update_email') - } + await accntSrvce.deleteAllEmailTokens(did) + if (user.email !== email) { try { await accntSrvce.updateEmail(did, email) diff --git a/packages/pds/src/services/account/index.ts b/packages/pds/src/services/account/index.ts index f52ef9d9bb7..add3550e5e7 100644 --- a/packages/pds/src/services/account/index.ts +++ b/packages/pds/src/services/account/index.ts @@ -546,6 +546,13 @@ export class AccountService { .executeTakeFirst() } + async deleteAllEmailTokens(did: string) { + await this.db.db + .deleteFrom('email_token') + .where('did', '=', did) + .executeTakeFirst() + } + async assertValidToken( did: string, purpose: EmailTokenPurpose,