Skip to content

Conversation

AngelAngelXie
Copy link
Contributor

@AngelAngelXie AngelAngelXie commented Jun 2, 2023

Cleanup TOTP code to include Firebase User reference in MultiFactorSession.

  • Changed a field in MultiFactorSession from AuthInternal to UserInternal
  • fixed corresponding tests and functions to match the type change.

Ran the code in demo app and was able to complete TOTP enrollment.

@changeset-bot
Copy link

changeset-bot bot commented Jun 2, 2023

⚠️ No Changeset found

Latest commit: 4ee9d7f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 2, 2023

Size Report 1

Affected Products

  • @firebase/auth

    TypeBase (2ccc9dd)Merge (e7e820e)Diff
    browser170 kB171 kB+53 B (+0.0%)
    cordova198 kB198 kB-5 B (-0.0%)
    esm5223 kB223 kB+53 B (+0.0%)
    main167 kB168 kB+53 B (+0.0%)
    module170 kB171 kB+53 B (+0.0%)
    react-native183 kB183 kB-5 B (-0.0%)
  • @firebase/auth/cordova

    TypeBase (2ccc9dd)Merge (e7e820e)Diff
    browser198 kB198 kB-5 B (-0.0%)
    module198 kB198 kB-5 B (-0.0%)
  • @firebase/auth/internal

    TypeBase (2ccc9dd)Merge (e7e820e)Diff
    browser181 kB181 kB+53 B (+0.0%)
    esm5237 kB237 kB+53 B (+0.0%)
    main204 kB204 kB+53 B (+0.0%)
    module181 kB181 kB+53 B (+0.0%)
  • @firebase/auth/react-native

    TypeBase (2ccc9dd)Merge (e7e820e)Diff
    browser183 kB183 kB-5 B (-0.0%)
    module183 kB183 kB-5 B (-0.0%)
  • firebase

    TypeBase (2ccc9dd)Merge (e7e820e)Diff
    firebase-auth-compat.js132 kB132 kB-5 B (-0.0%)
    firebase-auth-cordova.js147 kB147 kB-5 B (-0.0%)
    firebase-auth-react-native.js160 kB160 kB-5 B (-0.0%)
    firebase-auth.js127 kB127 kB+50 B (+0.0%)
    firebase-compat.js773 kB773 kB-5 B (-0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/0uKXBPUkPe.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 2, 2023

Size Analysis Report 1

Affected Products

  • @firebase/auth

    • TotpMultiFactorGenerator

      Size

      TypeBase (2ccc9dd)Merge (ce8ffe5)Diff
      size37.5 kB37.6 kB+54 B (+0.1%)
      size-with-ext-deps58.3 kB58.4 kB+54 B (+0.1%)
    • multiFactor

      Size

      TypeBase (2ccc9dd)Merge (ce8ffe5)Diff
      size37.3 kB37.3 kB-5 B (-0.0%)
      size-with-ext-deps58.1 kB58.1 kB-5 B (-0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/xyn2FTowSo.html

Copy link
Contributor

@prameshj prameshj left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

) {}

static _fromIdtoken(
idToken: string,
auth?: AuthInternal
user?: UserInternal
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can make "user" a required parameter here. The only place this is invoked without the "user" is the fromJSON method -

return MultiFactorSessionImpl._fromIdtoken(

But I don't see this method being used anywhere. @sam-gc do you know why we have these methods?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can make "user" a required parameter here. The only place this is invoked without the "user" is the fromJSON method -

return MultiFactorSessionImpl._fromIdtoken(

But I don't see this method being used anywhere. Sam do you know why we have these methods?

toJSON can be invoked when an end user calls JSON.stringify(), but it's unclear where fromJSON is used.. since JSON.parse won't automatically call it and it is not in the expected reviver format - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter

But i think it is ok to leave it be, in case users are manually calling this function somewhere.

Copy link
Contributor

@prameshj prameshj left a comment

Choose a reason for hiding this comment

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

Please update the PR description to include any manual testing results with the demo app.

renkelvin

This comment was marked as duplicate.

Copy link

@renkelvin renkelvin left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me. Please update the PR description to provide a bit more details.

Copy link
Contributor

@prameshj prameshj left a comment

Choose a reason for hiding this comment

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

LGTM, except for the one comment about user param in _fromIdToken.

Let's also verify this in the demo app to make sure it works end to end. Thanks!

@AngelAngelXie AngelAngelXie changed the title Firebase cleanup ax Cleanup TOTP code to include Firebase User reference in MultiFactorSession. Jun 7, 2023
@AngelAngelXie AngelAngelXie merged commit f949ee9 into master Jun 9, 2023
@AngelAngelXie AngelAngelXie deleted the firebase-cleanup-ax branch June 9, 2023 17:30
dwyfrequency pushed a commit that referenced this pull request Jun 16, 2023
…ssion. (#7346)

* cleanup TOTP code to include Firebase user reference in MultiFactorSession

* removed helper comments

* Added fakeUid const to organize code

* edited test to match changes in MultiFactorSession

* resolved TestAuth incompatible type error

* resolved more TestAuth incompatible type error

* resubmitting

* fixed formatting & resolved issue with undefined

* fixed format issue

* fixed formatting

* tried to resolve issue with user being undefined

* fixed if statement formatting

* addressed feedback: changed expect to compare user

* fixed formatting

* fixed the issue with undefined

* instantiate user

* organized import statements

* changed import formatting

* resubmitting for import formatting issue

* ran yarn format
@firebase firebase locked and limited conversation to collaborators Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants