Skip to content

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

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

Merged
merged 8 commits into from
Mar 23, 2025
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
48 changes: 48 additions & 0 deletions packages/auth/__tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { FirebaseAuthTypes } from '../lib/index';
// @ts-ignore
import User from '../lib/User';
// @ts-ignore test
import FirebaseModule from '../../app/lib/internal/FirebaseModule';

import auth, {
firebase,
getAuth,
Expand Down Expand Up @@ -58,6 +61,15 @@ import auth, {
verifyBeforeUpdateEmail,
getAdditionalUserInfo,
getCustomAuthDomain,
AppleAuthProvider,
EmailAuthProvider,
FacebookAuthProvider,
GithubAuthProvider,
GoogleAuthProvider,
OAuthProvider,
OIDCAuthProvider,
PhoneAuthProvider,
TwitterAuthProvider,
} from '../lib';

// @ts-ignore test
Expand Down Expand Up @@ -408,6 +420,42 @@ describe('Auth', function () {
expect(getCustomAuthDomain).toBeDefined();
});

it('`AppleAuthProvider` class is properly exposed to end user', function () {
expect(AppleAuthProvider).toBeDefined();
});

it('`EmailAuthProvider` class is properly exposed to end user', function () {
expect(EmailAuthProvider).toBeDefined();
});

it('`FacebookAuthProvider` class is properly exposed to end user', function () {
expect(FacebookAuthProvider).toBeDefined();
});

it('`GithubAuthProvider` class is properly exposed to end user', function () {
expect(GithubAuthProvider).toBeDefined();
});

it('`GoogleAuthProvider` class is properly exposed to end user', function () {
expect(GoogleAuthProvider).toBeDefined();
});

it('`OAuthProvider` class is properly exposed to end user', function () {
expect(OAuthProvider).toBeDefined();
});

it('`OIDCProvider` class is properly exposed to end user', function () {
expect(OIDCAuthProvider).toBeDefined();
});

it('`PhoneAuthProvider` class is properly exposed to end user', function () {
expect(PhoneAuthProvider).toBeDefined();
});

it('`TwitterAuthProvider` class is properly exposed to end user', function () {
expect(TwitterAuthProvider).toBeDefined();
});

describe('ActionCodeSettings', function () {
beforeAll(function () {
// @ts-ignore test
Expand Down
69 changes: 56 additions & 13 deletions packages/auth/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function applyActionCode(auth: Auth, oobCode: string): Promise<void>;
* @param auth - The Auth instance.
* @param callback - A callback function to run before the auth state changes.
* @param onAbort - Optional. A callback function to run if the operation is aborted.
*
*/
export function beforeAuthStateChanged(
auth: Auth,
Expand Down Expand Up @@ -148,14 +149,21 @@ export function getMultiFactorResolver(
* @param resolver - Optional. The popup redirect resolver.
* @returns A promise that resolves with the user credentials or null.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface PopupRedirectResolver {}

export function getRedirectResult(
auth: Auth,
resolver?: PopupRedirectResolver,
): Promise<FirebaseAuthTypes.UserCredential | null>;

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface PopupRedirectResolver {}

/**
* Loads the reCAPTCHA configuration into the Auth instance.
* Does not work in a Node.js environment
* @param auth - The Auth instance.
*/
export function initializeRecaptchaConfig(auth: Auth): Promise<void>;

/**
* Checks if an incoming link is a sign-in with email link suitable for signInWithEmailLink().
*
Expand Down Expand Up @@ -189,6 +197,13 @@ export function onIdTokenChanged(
nextOrObserver: CallbackOrObserver<AuthListenerCallback>,
): () => void;

/**
* Revoke the given access token, Currently only supports Apple OAuth access tokens.
* @param auth
* @param token
*/
export declare function revokeAccessToken(auth: Auth, token: string): Promise<void>;

/**
* Sends a password reset email to the given email address.
*
Expand All @@ -208,7 +223,7 @@ export function sendPasswordResetEmail(
*
* @param auth - The Auth instance.
* @param email - The user's email address.
* @param actionCodeSettings - Optional. Action code settings.
* @param actionCodeSettings - Optional, Action code settings.
* @returns A promise that resolves when the email is sent.
*/
export function sendSignInLinkToEmail(
Expand Down Expand Up @@ -300,7 +315,7 @@ export function signInWithEmailLink(
* Interface representing an application verifier.
*/
export interface ApplicationVerifier {
type: string;
readonly type: string;
verify(): Promise<string>;
}

Expand All @@ -309,13 +324,15 @@ export interface ApplicationVerifier {
*
* @param auth - The Auth instance.
* @param phoneNumber - The user's phone number.
* @param appVerifier - The application verifier.
* @param appVerifier - Optional. The application verifier.
* @param forceResend - Optional. (Native only) Forces a new message to be sent if it was already recently sent.
* @returns A promise that resolves with the confirmation result.
*/
export function signInWithPhoneNumber(
auth: Auth,
phoneNumber: string,
appVerifier: ApplicationVerifier,
appVerifier?: ApplicationVerifier,
forceResend?: boolean,
): Promise<FirebaseAuthTypes.ConfirmationResult>;

/**
Expand Down Expand Up @@ -360,7 +377,7 @@ export function signInWithRedirect(
auth: Auth,
provider: FirebaseAuthTypes.AuthProvider,
resolver?: PopupRedirectResolver,
): Promise<void>;
): Promise<never>;

/**
* Signs out the current user.
Expand All @@ -377,7 +394,7 @@ export function signOut(auth: Auth): Promise<void>;
* @param user - The user to set as the current user.
* @returns A promise that resolves when the user is set.
*/
export function updateCurrentUser(auth: Auth, user: FirebaseAuthTypes.User): Promise<void>;
export function updateCurrentUser(auth: Auth, user: FirebaseAuthTypes.User | null): Promise<void>;

/**
* Sets the current language to the default device/browser preference.
Expand All @@ -386,6 +403,15 @@ export function updateCurrentUser(auth: Auth, user: FirebaseAuthTypes.User): Pro
*/
export function useDeviceLanguage(auth: Auth): void;

/**
* Validates the password against the password policy configured for the project or tenant.
*
* @param auth - The Auth instance.
* @param password - The password to validate.
*
*/
export function validatePassword(auth: Auth, password: string): Promise<PasswordValidationStatus>;

/**
* Sets the current language to the default device/browser preference.
*
Expand Down Expand Up @@ -464,7 +490,7 @@ export function linkWithCredential(
export function linkWithPhoneNumber(
user: FirebaseAuthTypes.User,
phoneNumber: string,
appVerifier: ApplicationVerifier,
appVerifier?: ApplicationVerifier,
): Promise<FirebaseAuthTypes.ConfirmationResult>;

/**
Expand Down Expand Up @@ -526,7 +552,7 @@ export function reauthenticateWithCredential(
export function reauthenticateWithPhoneNumber(
user: FirebaseAuthTypes.User,
phoneNumber: string,
appVerifier: ApplicationVerifier,
appVerifier?: ApplicationVerifier,
): Promise<FirebaseAuthTypes.ConfirmationResult>;

/**
Expand Down Expand Up @@ -642,7 +668,7 @@ export function updateProfile(
export function verifyBeforeUpdateEmail(
user: FirebaseAuthTypes.User,
newEmail: string,
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings,
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings | null,
): Promise<void>;

/**
Expand All @@ -659,6 +685,23 @@ 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 {Promise<string>} A promise that resolves with the custom auth domain.
*/
export function getCustomAuthDomain(auth: Auth): Promise<string>;

/**
* Various Providers.
*
*
*/
export {
AppleAuthProvider,
EmailAuthProvider,
FacebookAuthProvider,
GithubAuthProvider,
GoogleAuthProvider,
OAuthProvider,
OIDCAuthProvider,
PhoneAuthProvider,
TwitterAuthProvider,
} from '../index';
22 changes: 22 additions & 0 deletions packages/auth/lib/modular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

import { getApp } from '@react-native-firebase/app';
import FacebookAuthProvider from '../providers/FacebookAuthProvider';
export { FacebookAuthProvider };

/**
* @typedef {import('@firebase/app-types').FirebaseApp} FirebaseApp
Expand Down Expand Up @@ -187,6 +189,15 @@
return auth.onIdTokenChanged(nextOrObserver);
}

/**
* Revoke the given access token, Currently only supports Apple OAuth access tokens.
* @param auth - The Auth Instance.
* @param token - The Access Token
*/
export async function revokeAccessToken(auth, token) {
throw new Error('revokeAccessToken() is only supported on Web');

Check warning on line 198 in packages/auth/lib/modular/index.js

View check run for this annotation

Codecov / codecov/patch

packages/auth/lib/modular/index.js#L197-L198

Added lines #L197 - L198 were not covered by tests
} //TO DO: Add Support

/**
* Sends a password reset email to the given email address.
* @param {Auth} auth - The Auth instance.
Expand Down Expand Up @@ -342,6 +353,17 @@
throw new Error('useDeviceLanguage is unsupported by the native Firebase SDKs');
}

/**
* Validates the password against the password policy configured for the project or tenant.
*
* @param auth - The Auth instance.
* @param password - The password to validate.
*
*/
export function validatePassword(auth, password) {
throw new Error('validatePassword is only supported on Web');

Check warning on line 364 in packages/auth/lib/modular/index.js

View check run for this annotation

Codecov / codecov/patch

packages/auth/lib/modular/index.js#L363-L364

Added lines #L363 - L364 were not covered by tests
} //TO DO: ADD support.

/**
* Sets the current language to the default device/browser preference.
* @param {Auth} auth - The Auth instance.
Expand Down
5 changes: 4 additions & 1 deletion packages/auth/type-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import firebase from '@react-native-firebase/app';
import firebase, { FirebaseAuthTypes } from '.';
import firebase, { FirebaseAuthTypes, signInWithPhoneNumber } from '.';

console.log(firebase.default().currentUser);

Expand Down Expand Up @@ -53,3 +53,6 @@ console.log(u ? u.toJSON() : '');
firebase.auth().signInAnonymously().then();

firebase.auth().signInWithEmailAndPassword('', '').then();

// Verify Modular API
signInWithPhoneNumber(firebase.auth(), '+1234567890');
Loading