Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear email tokens on email update #2131

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/pds/src/account-manager/helpers/email-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export const deleteEmailToken = async (
)
}

export const deleteAllEmailTokens = async (db: AccountDb, did: string) => {
await db.executeWithRetry(
db.db.deleteFrom('email_token').where('did', '=', did),
)
}

export const assertValidToken = async (
db: AccountDb,
did: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/account-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class AccountManager {
await this.db.transaction((dbTxn) =>
Promise.all([
account.updateEmail(dbTxn, did, email),
emailToken.deleteEmailToken(dbTxn, did, 'update_email'),
emailToken.deleteAllEmailTokens(dbTxn, did),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to run this even when there is no token?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I believe so

becuase we want to clear all tokens regardless since they were associated with the old email

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I actually meant that it wasn't being run in that case and I figured we might want to!

]),
)
} else {
Expand Down
Loading