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

fix(auth): Fix auth type definitions and add more #8323

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

MichaelVerdon
Copy link
Collaborator

@MichaelVerdon MichaelVerdon commented Feb 11, 2025

Description

Added and edited type definitions to match Firebase JS-SDK with tests for definitions. Furthermore, this should fix this issue

Related issues

Release Summary

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan


Think react-native-firebase is great? Please consider supporting the project with any of the below:

Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-firebase ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 11, 2025 5:35pm

@CLAassistant
Copy link

CLAassistant commented Feb 11, 2025

CLA assistant check
All committers have signed the CLA.

@MichaelVerdon MichaelVerdon changed the title Fix auth types fix(auth): Fix auth type definitions and add more Feb 11, 2025
@@ -1,4 +1,6 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
// @ts-ignore test
import FirebaseModule from '../../app/lib/internal/FirebaseModule';
Copy link
Member

Choose a reason for hiding this comment

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

can remove this.

@@ -208,13 +224,13 @@ export function sendPasswordResetEmail(
*
* @param auth - The Auth instance.
* @param email - The user's email address.
* @param actionCodeSettings - Optional. Action code settings.
* @param actionCodeSettings - No longer optional from JS Docs. Action code settings.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted it

@@ -309,13 +325,15 @@ export interface ApplicationVerifier {
*
* @param auth - The Auth instance.
* @param phoneNumber - The user's phone number.
* @param forceResend - Forces a new message to be sent if it was already recently sent.
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a few cases where native is a superset of firebase-js-sdk and I think, philosophically, that's incredible - it's the reason you would use native vs just firebase-js-sdk. So I strongly support implementing the native-only stuff when it appears.

In order to maintain drop-in API compatibility though, I think it should follow these general rules:

  • any native-only parameters should be after any firebase-js-sdk parameters so that their optionality doesn't affect optional firebase-js-sdk params (this applies here! the order should be flipped I think)
  • they should be marked clearly as for whatever platform they are exclusive to
  • if they are a type and it means our new type shape isn't the same as the firebase-js-sdk shape, we should extend their type to add the new property/properties, with ReactNative prepended to the type name (e.g., ReactNativeFirebaseApp should extend FirebaseApp, ReactNativeFirebaseError should extend FirebaseError etc

In this case I think it's 1) keep the param but 2) move the param to be after all the optional firebase-js-sdk upstream params

@@ -642,7 +672,7 @@ export function updateProfile(
export function verifyBeforeUpdateEmail(
user: FirebaseAuthTypes.User,
newEmail: string,
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings,
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings | null,
Copy link
Member

Choose a reason for hiding this comment

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

It does seem a touch redundant to have the type as actionCodeSettings? and also have | null. but firebase-js-sdk has it, so I guess it stays

@@ -659,6 +689,273 @@ export function getAdditionalUserInfo(
* Returns the custom auth domain for the auth instance.
*
* @param auth - The Auth instance.
* @returns A promise that resolves with the custom auth domain.
* @returns {string} A promise that resolves with the custom auth domain.
Copy link
Member

Choose a reason for hiding this comment

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

this returns * @returns {Promise<string>}, one day it should be just string but that is when RNFB adopts new architecture with sync API calls to native.

* Not in JS Docs
*
*/
export class AppleAuthProvider {
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure the provider types that already exist on RNFB can't be imported out of lib/index.d.ts and reused?

*
*
*/
export class OAuthProvider {

Choose a reason for hiding this comment

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

Following your comment at #8368 (comment), I had a look at this PR. It does indeed seem to add the exports I'm missing, but I'm a bit confused about what seems like a mismatch between the runtime and typed structure of the provider classes. For example, OAuthProvider seems to have very different methods at runtime compared to these types: https://github.com/invertase/react-native-firebase/blob/main/packages/auth/lib/providers/OAuthProvider.js#L18

Or am I simply misunderstanding something?

Copy link
Collaborator Author

@MichaelVerdon MichaelVerdon Feb 25, 2025

Choose a reason for hiding this comment

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

I understand what you are saying, what we try to do here is match the React Native implementation with the Javascript one but seeing those other methods are there in that class there must be a reason they are there. I will confirm it with the rest of the team.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The older namespaced API has the addition of these seemingly extra methods.

Copy link

@henribru henribru Feb 25, 2025

Choose a reason for hiding this comment

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

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.

5 participants