Skip to content

Commit

Permalink
Remove all email tokens on email change (#2132)
Browse files Browse the repository at this point in the history
remove all email tokens regardless of whether token was used to change email
  • Loading branch information
devinivy authored Feb 3, 2024
1 parent b6b854a commit dd021b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions packages/pds/src/account-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,14 @@ export class AccountManager {
)
}

async updateEmail(opts: { did: string; email: string; token?: string }) {
const { did, email, token } = opts
if (token) {
await this.db.transaction((dbTxn) =>
Promise.all([
account.updateEmail(dbTxn, did, email),
emailToken.deleteAllEmailTokens(dbTxn, did),
]),
)
} else {
return account.updateEmail(this.db, did, email)
}
async updateEmail(opts: { did: string; email: string }) {
const { did, email } = opts
await this.db.transaction((dbTxn) =>
Promise.all([
account.updateEmail(dbTxn, did, email),
emailToken.deleteAllEmailTokens(dbTxn, did),
]),
)
}

async resetPassword(opts: { password: string; token: string }) {
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/api/com/atproto/server/updateEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function (server: Server, ctx: AppContext) {
}

try {
await ctx.accountManager.updateEmail({ did, email, token })
await ctx.accountManager.updateEmail({ did, email })
} catch (err) {
if (err instanceof UserAlreadyExistsError) {
throw new InvalidRequestError(
Expand Down

0 comments on commit dd021b8

Please sign in to comment.