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

feat(2fa): Add two-factor lib #17937

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat(2fa): Add two-factor lib #17937

wants to merge 1 commit into from

Conversation

vbudhram
Copy link
Contributor

@vbudhram vbudhram commented Oct 30, 2024

Because

  • We want to be able to retrieve recovery codes for a given user

This pull request

  • Adds the BackupCodeManager class
  • Adds method hasRecoveryCodes
  • Supporting tests

Issue that this pull request solves

Closes: https://mozilla-hub.atlassian.net/browse/FXA-10332

Checklist

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Notes

The linked issue mentions the nx lib should be 2fa, but nx wont let you create a lib starting with a number. Opted for two-factor instead.

@vbudhram vbudhram self-assigned this Oct 30, 2024
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

export const generateBackupCodes = (count: number): string[] => {
Copy link
Member

Choose a reason for hiding this comment

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

A factory like this should be named BackupCodeFactory. Typically factories should be for complex types rather than simple types like the below, since they should always be TypeNameFactory.

getBackupCodes(userId: string): string[];
}

export class BackupCodeManager {
Copy link
Member

Choose a reason for hiding this comment

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

Are these intended to be consumed by NestJS? If so, we should add the @Injectable decorator

export class BackupCodeManager {
constructor(private readonly backupCodeRepository: BackupCodeRepository) {}

hasBackupCodes(userId: string): { hasBackupCodes: boolean; count: number } {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps rename to getCountForUserId? This method is implicitly part of the BackupCodeManager class so doesn't need the name of the class within the class.

@vbudhram vbudhram marked this pull request as ready for review November 1, 2024 18:07
@vbudhram vbudhram requested a review from a team as a code owner November 1, 2024 18:07
@vbudhram vbudhram changed the title feat(2fa): Add backup-code libs feat(2fa): Add two-factor lib Nov 1, 2024
@vbudhram vbudhram force-pushed the fxa-10332 branch 2 times, most recently from eaeeea8 to 68b233f Compare November 4, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants