Skip to content

Commit 3dc8119

Browse files
MichaelVerdonrussellwheatleymikehardy
authored
fix(auth): Fix auth type definitions and add more (#8323)
* fix(auth): ensure all types are correct * Definitions added with tests they are defined * fix(auth): Exported from namespaced implementation. * types: fix return type to be Promise until new arch sync is possible --------- Co-authored-by: russellwheatley <russellwheatley85@gmail.com> Co-authored-by: Mike Hardy <github@mikehardy.net>
1 parent 6dc1da9 commit 3dc8119

File tree

4 files changed

+130
-14
lines changed

4 files changed

+130
-14
lines changed

packages/auth/__tests__/auth.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
22
import { FirebaseAuthTypes } from '../lib/index';
33
// @ts-ignore
44
import User from '../lib/User';
5+
// @ts-ignore test
6+
import FirebaseModule from '../../app/lib/internal/FirebaseModule';
7+
58
import auth, {
69
firebase,
710
getAuth,
@@ -58,6 +61,15 @@ import auth, {
5861
verifyBeforeUpdateEmail,
5962
getAdditionalUserInfo,
6063
getCustomAuthDomain,
64+
AppleAuthProvider,
65+
EmailAuthProvider,
66+
FacebookAuthProvider,
67+
GithubAuthProvider,
68+
GoogleAuthProvider,
69+
OAuthProvider,
70+
OIDCAuthProvider,
71+
PhoneAuthProvider,
72+
TwitterAuthProvider,
6173
} from '../lib';
6274

6375
// @ts-ignore test
@@ -408,6 +420,42 @@ describe('Auth', function () {
408420
expect(getCustomAuthDomain).toBeDefined();
409421
});
410422

423+
it('`AppleAuthProvider` class is properly exposed to end user', function () {
424+
expect(AppleAuthProvider).toBeDefined();
425+
});
426+
427+
it('`EmailAuthProvider` class is properly exposed to end user', function () {
428+
expect(EmailAuthProvider).toBeDefined();
429+
});
430+
431+
it('`FacebookAuthProvider` class is properly exposed to end user', function () {
432+
expect(FacebookAuthProvider).toBeDefined();
433+
});
434+
435+
it('`GithubAuthProvider` class is properly exposed to end user', function () {
436+
expect(GithubAuthProvider).toBeDefined();
437+
});
438+
439+
it('`GoogleAuthProvider` class is properly exposed to end user', function () {
440+
expect(GoogleAuthProvider).toBeDefined();
441+
});
442+
443+
it('`OAuthProvider` class is properly exposed to end user', function () {
444+
expect(OAuthProvider).toBeDefined();
445+
});
446+
447+
it('`OIDCProvider` class is properly exposed to end user', function () {
448+
expect(OIDCAuthProvider).toBeDefined();
449+
});
450+
451+
it('`PhoneAuthProvider` class is properly exposed to end user', function () {
452+
expect(PhoneAuthProvider).toBeDefined();
453+
});
454+
455+
it('`TwitterAuthProvider` class is properly exposed to end user', function () {
456+
expect(TwitterAuthProvider).toBeDefined();
457+
});
458+
411459
describe('ActionCodeSettings', function () {
412460
beforeAll(function () {
413461
// @ts-ignore test

packages/auth/lib/modular/index.d.ts

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function applyActionCode(auth: Auth, oobCode: string): Promise<void>;
5858
* @param auth - The Auth instance.
5959
* @param callback - A callback function to run before the auth state changes.
6060
* @param onAbort - Optional. A callback function to run if the operation is aborted.
61+
*
6162
*/
6263
export function beforeAuthStateChanged(
6364
auth: Auth,
@@ -148,14 +149,21 @@ export function getMultiFactorResolver(
148149
* @param resolver - Optional. The popup redirect resolver.
149150
* @returns A promise that resolves with the user credentials or null.
150151
*/
151-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
152-
export interface PopupRedirectResolver {}
153-
154152
export function getRedirectResult(
155153
auth: Auth,
156154
resolver?: PopupRedirectResolver,
157155
): Promise<FirebaseAuthTypes.UserCredential | null>;
158156

157+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
158+
export interface PopupRedirectResolver {}
159+
160+
/**
161+
* Loads the reCAPTCHA configuration into the Auth instance.
162+
* Does not work in a Node.js environment
163+
* @param auth - The Auth instance.
164+
*/
165+
export function initializeRecaptchaConfig(auth: Auth): Promise<void>;
166+
159167
/**
160168
* Checks if an incoming link is a sign-in with email link suitable for signInWithEmailLink().
161169
*
@@ -189,6 +197,13 @@ export function onIdTokenChanged(
189197
nextOrObserver: CallbackOrObserver<AuthListenerCallback>,
190198
): () => void;
191199

200+
/**
201+
* Revoke the given access token, Currently only supports Apple OAuth access tokens.
202+
* @param auth
203+
* @param token
204+
*/
205+
export declare function revokeAccessToken(auth: Auth, token: string): Promise<void>;
206+
192207
/**
193208
* Sends a password reset email to the given email address.
194209
*
@@ -208,7 +223,7 @@ export function sendPasswordResetEmail(
208223
*
209224
* @param auth - The Auth instance.
210225
* @param email - The user's email address.
211-
* @param actionCodeSettings - Optional. Action code settings.
226+
* @param actionCodeSettings - Optional, Action code settings.
212227
* @returns A promise that resolves when the email is sent.
213228
*/
214229
export function sendSignInLinkToEmail(
@@ -300,7 +315,7 @@ export function signInWithEmailLink(
300315
* Interface representing an application verifier.
301316
*/
302317
export interface ApplicationVerifier {
303-
type: string;
318+
readonly type: string;
304319
verify(): Promise<string>;
305320
}
306321

@@ -309,13 +324,15 @@ export interface ApplicationVerifier {
309324
*
310325
* @param auth - The Auth instance.
311326
* @param phoneNumber - The user's phone number.
312-
* @param appVerifier - The application verifier.
327+
* @param appVerifier - Optional. The application verifier.
328+
* @param forceResend - Optional. (Native only) Forces a new message to be sent if it was already recently sent.
313329
* @returns A promise that resolves with the confirmation result.
314330
*/
315331
export function signInWithPhoneNumber(
316332
auth: Auth,
317333
phoneNumber: string,
318-
appVerifier: ApplicationVerifier,
334+
appVerifier?: ApplicationVerifier,
335+
forceResend?: boolean,
319336
): Promise<FirebaseAuthTypes.ConfirmationResult>;
320337

321338
/**
@@ -360,7 +377,7 @@ export function signInWithRedirect(
360377
auth: Auth,
361378
provider: FirebaseAuthTypes.AuthProvider,
362379
resolver?: PopupRedirectResolver,
363-
): Promise<void>;
380+
): Promise<never>;
364381

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

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

406+
/**
407+
* Validates the password against the password policy configured for the project or tenant.
408+
*
409+
* @param auth - The Auth instance.
410+
* @param password - The password to validate.
411+
*
412+
*/
413+
export function validatePassword(auth: Auth, password: string): Promise<PasswordValidationStatus>;
414+
389415
/**
390416
* Sets the current language to the default device/browser preference.
391417
*
@@ -464,7 +490,7 @@ export function linkWithCredential(
464490
export function linkWithPhoneNumber(
465491
user: FirebaseAuthTypes.User,
466492
phoneNumber: string,
467-
appVerifier: ApplicationVerifier,
493+
appVerifier?: ApplicationVerifier,
468494
): Promise<FirebaseAuthTypes.ConfirmationResult>;
469495

470496
/**
@@ -526,7 +552,7 @@ export function reauthenticateWithCredential(
526552
export function reauthenticateWithPhoneNumber(
527553
user: FirebaseAuthTypes.User,
528554
phoneNumber: string,
529-
appVerifier: ApplicationVerifier,
555+
appVerifier?: ApplicationVerifier,
530556
): Promise<FirebaseAuthTypes.ConfirmationResult>;
531557

532558
/**
@@ -642,7 +668,7 @@ export function updateProfile(
642668
export function verifyBeforeUpdateEmail(
643669
user: FirebaseAuthTypes.User,
644670
newEmail: string,
645-
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings,
671+
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings | null,
646672
): Promise<void>;
647673

648674
/**
@@ -659,6 +685,23 @@ export function getAdditionalUserInfo(
659685
* Returns the custom auth domain for the auth instance.
660686
*
661687
* @param auth - The Auth instance.
662-
* @returns A promise that resolves with the custom auth domain.
688+
* @returns {Promise<string>} A promise that resolves with the custom auth domain.
663689
*/
664690
export function getCustomAuthDomain(auth: Auth): Promise<string>;
691+
692+
/**
693+
* Various Providers.
694+
*
695+
*
696+
*/
697+
export {
698+
AppleAuthProvider,
699+
EmailAuthProvider,
700+
FacebookAuthProvider,
701+
GithubAuthProvider,
702+
GoogleAuthProvider,
703+
OAuthProvider,
704+
OIDCAuthProvider,
705+
PhoneAuthProvider,
706+
TwitterAuthProvider,
707+
} from '../index';

packages/auth/lib/modular/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717

1818
import { getApp } from '@react-native-firebase/app';
19+
import FacebookAuthProvider from '../providers/FacebookAuthProvider';
20+
export { FacebookAuthProvider };
1921

2022
/**
2123
* @typedef {import('@firebase/app-types').FirebaseApp} FirebaseApp
@@ -187,6 +189,15 @@ export function onIdTokenChanged(auth, nextOrObserver) {
187189
return auth.onIdTokenChanged(nextOrObserver);
188190
}
189191

192+
/**
193+
* Revoke the given access token, Currently only supports Apple OAuth access tokens.
194+
* @param auth - The Auth Instance.
195+
* @param token - The Access Token
196+
*/
197+
export async function revokeAccessToken(auth, token) {
198+
throw new Error('revokeAccessToken() is only supported on Web');
199+
} //TO DO: Add Support
200+
190201
/**
191202
* Sends a password reset email to the given email address.
192203
* @param {Auth} auth - The Auth instance.
@@ -342,6 +353,17 @@ export function useDeviceLanguage(auth) {
342353
throw new Error('useDeviceLanguage is unsupported by the native Firebase SDKs');
343354
}
344355

356+
/**
357+
* Validates the password against the password policy configured for the project or tenant.
358+
*
359+
* @param auth - The Auth instance.
360+
* @param password - The password to validate.
361+
*
362+
*/
363+
export function validatePassword(auth, password) {
364+
throw new Error('validatePassword is only supported on Web');
365+
} //TO DO: ADD support.
366+
345367
/**
346368
* Sets the current language to the default device/browser preference.
347369
* @param {Auth} auth - The Auth instance.

packages/auth/type-test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import firebase from '@react-native-firebase/app';
2-
import firebase, { FirebaseAuthTypes } from '.';
2+
import firebase, { FirebaseAuthTypes, signInWithPhoneNumber } from '.';
33

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

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

5555
firebase.auth().signInWithEmailAndPassword('', '').then();
56+
57+
// Verify Modular API
58+
signInWithPhoneNumber(firebase.auth(), '+1234567890');

0 commit comments

Comments
 (0)