1818import { Platform } from 'react-native' ;
1919import { getReactNativeModule } from '@react-native-firebase/app/dist/module/internal/nativeModule' ;
2020
21- import type { VerificationSupportInfo , VerifiedPhoneNumberResult } from './types/pnv' ;
21+ import type { VerificationSupportResult , VerifiedPhoneNumberTokenResult } from './types/pnv' ;
2222
2323const UNSUPPORTED_MSG = 'Firebase Phone Number Verification is only supported on Android.' ;
2424
2525const NATIVE_MODULE_NAME = 'RNFBPnvModule' ;
2626
2727interface NativePnvModule {
2828 enableTestSession ( token : string ) : Promise < void > ;
29- getVerificationSupportInfo ( ) : Promise < VerificationSupportInfo [ ] > ;
30- getVerificationSupportInfoForSimSlot ( simSlot : number ) : Promise < VerificationSupportInfo [ ] > ;
31- getVerifiedPhoneNumber ( ) : Promise < VerifiedPhoneNumberResult > ;
29+ getVerificationSupportInfo ( ) : Promise < VerificationSupportResult [ ] > ;
30+ getVerificationSupportInfoForSimSlot ( simSlot : number ) : Promise < VerificationSupportResult [ ] > ;
31+ getVerifiedPhoneNumber ( ) : Promise < VerifiedPhoneNumberTokenResult > ;
3232 getDigitalCredentialPayload ( nonce : string ) : Promise < string > ;
33- exchangeCredentialResponseForPhoneNumber ( dcApiResponse : string ) : Promise < VerifiedPhoneNumberResult > ;
33+ exchangeCredentialResponseForPhoneNumber (
34+ dcApiResponse : string ,
35+ ) : Promise < VerifiedPhoneNumberTokenResult > ;
3436}
3537
3638function getNativeModule ( ) : NativePnvModule {
@@ -49,11 +51,17 @@ function getNativeModule(): NativePnvModule {
4951/**
5052 * Enables a test session for SIM-less testing.
5153 * Must be called only once per app instance; subsequent calls will reject with
52- * error code `test-session-already-enabled`.
54+ * error code `pnv/ test-session-already-enabled`.
5355 *
56+ * @remarks
5457 * In test mode, phone numbers follow the format: valid country code followed by all zeros.
58+ * Requires a test token generated from the Firebase Console (7-day TTL).
5559 *
5660 * @param token - The test token generated from the Firebase Console.
61+ * @throws `pnv/test-session-already-enabled` if called more than once.
62+ * @throws `pnv/invalid-test-number-id` if the token is empty, expired, or duplicated.
63+ * @see https://firebase.google.com/docs/phone-number-verification
64+ * @android
5765 */
5866export function enableTestSession ( token : string ) : Promise < void > {
5967 return getNativeModule ( ) . enableTestSession ( token ) ;
@@ -62,10 +70,18 @@ export function enableTestSession(token: string): Promise<void> {
6270/**
6371 * Checks if the device's SIM card(s) support phone number verification.
6472 *
65- * @param simSlot - Optional SIM slot index to query a specific slot instead of all slots.
66- * @returns Array of support info results, one per SIM slot (or one entry if simSlot is specified).
73+ * @remarks
74+ * This method does not require user consent and can be called freely.
75+ * Returns one {@link VerificationSupportResult} per SIM slot (or one entry if `simSlot` is specified).
76+ *
77+ * @param simSlot - Optional 0-based SIM slot index to query a specific slot instead of all slots.
78+ * @returns Array of support results, one per SIM slot.
79+ * @see https://firebase.google.com/docs/phone-number-verification
80+ * @android
6781 */
68- export function getVerificationSupportInfo ( simSlot ?: number ) : Promise < VerificationSupportInfo [ ] > {
82+ export function getVerificationSupportInfo (
83+ simSlot ?: number ,
84+ ) : Promise < VerificationSupportResult [ ] > {
6985 if ( simSlot !== undefined ) {
7086 return getNativeModule ( ) . getVerificationSupportInfoForSimSlot ( simSlot ) ;
7187 }
@@ -76,9 +92,16 @@ export function getVerificationSupportInfo(simSlot?: number): Promise<Verificati
7692 * Initiates the phone number verification flow, including user consent and token generation.
7793 * A consent dialog will be presented to the user.
7894 *
95+ * @remarks
96+ * The app should prepare the user for the consent screen before calling this method.
97+ *
7998 * @returns The verified phone number and a JWT token with full claims for server-side validation.
99+ * @throws `pnv/carrier-not-supported` if the carrier does not support PNV.
100+ * @throws `pnv/activity-context-required` if no foreground Activity is available.
101+ * @see https://firebase.google.com/docs/phone-number-verification/android/get-started
102+ * @android
80103 */
81- export function getVerifiedPhoneNumber ( ) : Promise < VerifiedPhoneNumberResult > {
104+ export function getVerifiedPhoneNumber ( ) : Promise < VerifiedPhoneNumberTokenResult > {
82105 return getNativeModule ( ) . getVerifiedPhoneNumber ( ) ;
83106}
84107
@@ -88,6 +111,8 @@ export function getVerifiedPhoneNumber(): Promise<VerifiedPhoneNumberResult> {
88111 *
89112 * @param nonce - A unique value to prevent replay attacks.
90113 * @returns The digital credential payload string.
114+ * @see https://firebase.google.com/docs/phone-number-verification
115+ * @android
91116 */
92117export function getDigitalCredentialPayload ( nonce : string ) : Promise < string > {
93118 return getNativeModule ( ) . getDigitalCredentialPayload ( nonce ) ;
@@ -99,9 +124,12 @@ export function getDigitalCredentialPayload(nonce: string): Promise<string> {
99124 *
100125 * @param dcApiResponse - The JWT from the Credential Manager response.
101126 * @returns The verified phone number and a JWT token with full claims for server-side validation.
127+ * @throws `pnv/invalid-digital-credential-response` if the response is invalid.
128+ * @see https://firebase.google.com/docs/phone-number-verification
129+ * @android
102130 */
103131export function exchangeCredentialResponseForPhoneNumber (
104132 dcApiResponse : string ,
105- ) : Promise < VerifiedPhoneNumberResult > {
133+ ) : Promise < VerifiedPhoneNumberTokenResult > {
106134 return getNativeModule ( ) . exchangeCredentialResponseForPhoneNumber ( dcApiResponse ) ;
107135}
0 commit comments