Skip to content

Commit

Permalink
Clear email tokens on email update - entryway (#2130)
Browse files Browse the repository at this point in the history
delete email tokens on email update
  • Loading branch information
dholms authored Feb 3, 2024
1 parent 4127d0f commit 346d04d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/pds/src/api/com/atproto/server/updateEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions packages/pds/src/services/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 346d04d

Please sign in to comment.