Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

fix: improve mfa.enroll return types#956

Merged
J0 merged 1 commit into
supabase:masterfrom
aloisklink:fix/fix-mfa.enroll-return-types
Sep 17, 2024
Merged

fix: improve mfa.enroll return types#956
J0 merged 1 commit into
supabase:masterfrom
aloisklink:fix/fix-mfa.enroll-return-types

Conversation

@aloisklink

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix for the TypeScript types.

What is the current behavior?

What is the new behavior?

Use TypeScript's function overloading to return

  • TOTP data when mfa.enroll was passed factorType: 'totp',
  • phone data when mfa.enroll was passed factorType: 'phone'.

This fixes a breaking change in the types in b957c30.

Additional context

This PR would also expose the new following types:

  • MFAEnrollTOTPParams
  • MFAEnrollPhoneParams
  • AuthMFAEnrollTOTPResponse
  • AuthMFAEnrollPhoneResponse
  • AuthMFAEnrollErrorResponse (it might be better to roll this type in with the other two).

It might be better to keep these types private, since once they're exposed, you can't easily remove them again without creating a breaking change.

Use TypeScript's operator overloading to return
- TOTP data when `mfa.enroll` was passed `factorType: 'totp'`,
- phone data when `mfa.enroll` was passed `factorType: 'phone'`.

This fixes a breaking change in the types in
b957c30.
@J0

J0 commented Sep 17, 2024

Copy link
Copy Markdown
Contributor

It might be better to keep these types private, since once they're exposed, you can't easily remove them again without creating a breaking change.

Would agree with this

Thanks for the PR! Looks great so far

@J0 J0 merged commit 8a1ec06 into supabase:master Sep 17, 2024
@J0

J0 commented Sep 17, 2024

Copy link
Copy Markdown
Contributor

Will follow up with the corresponding PR for challengeParams and verifyParams (if they are at all needed)

Upd: shouldn't be needed, except in relation to MFA (WebAuthn).

@aloisklink

Copy link
Copy Markdown
Contributor Author

It might be better to keep these types private, since once they're exposed, you can't easily remove them again without creating a breaking change.

Would agree with this

If you are still interested in this, I think the easiest way to do this would be to make a new file called something like src/lib/internal-types.ts that isn't exported outside of the package using export * from './lib/types'.

Then, src/GoTrueClient.ts and src/lib/types.ts could both import types from this file.

(the hardest thing would be picking the right conventional commit prefix 😆, since this PR has already been merged, but not released, so it's not yet a breaking change)

Will follow up with the corresponding PR for challengeParams and verifyParams (if they are at all needed)

Upd: shouldn't be needed, except in relation to MFA (WebAuthn).

Yep, we use both supabase.auth.mfa.challenge and supabase.auth.mfa.verify in our code (based of the example in https://github.com/supabase/supabase/blob/10ba4999cd33f796e89c50a0821e46b3d346eb7c/apps/docs/content/guides/auth/auth-mfa/totp.mdx?plain=1#L245-L261), and v2.65.0 works fine in those cases!

And I'm excited to see WebAuthn support!

@aloisklink aloisklink deleted the fix/fix-mfa.enroll-return-types branch September 18, 2024 06:55
@J0

J0 commented Sep 23, 2024

Copy link
Copy Markdown
Contributor

@aloisklink, thanks for the update.

I think an internal-types file would work. Let me do that shortly. Thanks!

J0 added a commit that referenced this pull request Oct 8, 2024
## What kind of change does this PR introduce?

Follow up to #956, hides the MFA sub-types (e.g. MFA Phone, MFA TOTP)
needed to fix type errors before we release to public so that we can
remove them as and when we like. The sub-types are now stored in an
`internal-types` file which, unlike the `types` file is not exposed to
public.


The types mentioned here have not been released yet so fine to hide them
kangmingtay pushed a commit that referenced this pull request Oct 15, 2024
🤖 I have created a release *beep* *boop*
---


##
[2.65.1](v2.65.0...v2.65.1)
(2024-10-14)


### Bug Fixes

* Call `SIGNED_OUT` event where session is removed
([#854](#854))
([436fd9f](436fd9f))
* improve `mfa.enroll` return types
([#956](#956))
([8a1ec06](8a1ec06))
* move MFA sub types to internal file
([#964](#964))
([4b7455c](4b7455c))
* remove phone mfa deletion, match on error codes
([#963](#963))
([ef3911c](ef3911c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
mandarini pushed a commit to supabase/supabase-js that referenced this pull request Oct 2, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.65.1](supabase/auth-js@v2.65.0...v2.65.1)
(2024-10-14)


### Bug Fixes

* Call `SIGNED_OUT` event where session is removed
([#854](supabase/auth-js#854))
([421d7d4](supabase/auth-js@421d7d4))
* improve `mfa.enroll` return types
([#956](supabase/auth-js#956))
([aca7870](supabase/auth-js@aca7870))
* move MFA sub types to internal file
([#964](supabase/auth-js#964))
([70cecdb](supabase/auth-js@70cecdb))
* remove phone mfa deletion, match on error codes
([#963](supabase/auth-js#963))
([3547cd9](supabase/auth-js@3547cd9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

mfa.enroll's return type has a TypeScript breaking change in v2.65.0

2 participants