forked from invertase/react-native-firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
2217 lines (2103 loc) · 85 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { ReactNativeFirebase } from '@react-native-firebase/app';
/**
* Firebase Authentication package for React Native.
*
* #### Example: Access the firebase export from the `auth` package:
*
* ```js
* import { firebase } from '@react-native-firebase/auth';
*
* // firebase.auth().X
* ```
*
* #### Example: Using the default export from the `auth` package:
*
* ```js
* import auth from '@react-native-firebase/auth';
*
* // auth().X
* ```
*
* #### Example: Using the default export from the `app` package:
*
* ```js
* import firebase from '@react-native-firebase/app';
* import '@react-native-firebase/auth';
*
* // firebase.auth().X
* ```
* TODO @salakar @ehesp missing auth providers (PhoneAuthProvider, Facebook etc)
*
* @firebase auth
*/
export namespace FirebaseAuthTypes {
import FirebaseModule = ReactNativeFirebase.FirebaseModule;
import NativeFirebaseError = ReactNativeFirebase.NativeFirebaseError;
export interface NativeFirebaseAuthError extends NativeFirebaseError {
userInfo: {
/**
* When trying to sign in or link with an AuthCredential which was already associated with an account,
* you might receive an updated credential (depending of provider) which you can use to recover from the error.
*/
authCredential: AuthCredential | null;
/**
* When trying to sign in the user might be prompted for a second factor confirmation. Can
* can use this object to initialize the second factor flow and recover from the error.
*/
resolver: MultiFactorResolver | null;
};
}
/**
* Interface that represents the credentials returned by an auth provider. Implementations specify the details
* about each auth provider's credential requirements.
*
* TODO Missing; signInMethod, toJSON, fromJSON
*
* #### Example
*
* ```js
* const provider = firebase.auth.EmailAuthProvider;
* const authCredential = provider.credential('foo@bar.com', '123456');
*
* await firebase.auth().signInWithCredential(authCredential);
* ```
*/
export interface AuthCredential {
/**
* The authentication provider ID for the credential. For example, 'facebook.com', or 'google.com'.
*/
providerId: string;
token: string;
secret: string;
}
/**
* Interface that represents an auth provider. Implemented by other providers.
*/
export interface AuthProvider {
/**
* The provider ID of the provider.
*/
PROVIDER_ID: string;
/**
* Creates a new `AuthCredential`.
*
* @returns {@link auth.AuthCredential}.
* @param token A provider token.
* @param secret A provider secret.
*/
credential: (token: string | null, secret?: string) => AuthCredential;
}
/**
* Interface that represents an OAuth provider. Implemented by other providers.
*/
export interface OAuthProvider extends AuthProvider {
/**
* The provider ID of the provider.
* @param providerId
*/
// eslint-disable-next-line @typescript-eslint/no-misused-new
new (providerId: string): OAuthProvider;
/**
* Creates a new `AuthCredential`.
*
* @returns {@link auth.AuthCredential}.
* @param token A provider token.
* @param secret A provider secret.
*/
credential: (token: string | null, secret?: string) => AuthCredential;
/**
* Sets the OAuth custom parameters to pass in an OAuth request for sign-in
* operations.
*
* @remarks
* For a detailed list, check the reserved required OAuth 2.0 parameters such as `client_id`,
* `redirect_uri`, `scope`, `response_type`, and `state` are not allowed and will be ignored.
*
* @param customOAuthParameters - The custom OAuth parameters to pass in the OAuth request.
*/
setCustomParameters: (customOAuthParameters: Record<string, string>) => AuthProvider;
/**
* Retrieve the current list of custom parameters.
* @returns The current map of OAuth custom parameters.
*/
getCustomParameters: () => Record<string, string>;
/**
* Add an OAuth scope to the credential.
*
* @param scope - Provider OAuth scope to add.
*/
addScope: (scope: string) => AuthProvider;
/**
* Retrieve the current list of OAuth scopes.
*/
getScopes: () => string[];
}
/**
* Interface that represents an Open ID Connect auth provider. Implemented by other providers.
*/
export interface OIDCProvider {
/**
* The provider ID of the provider.
*/
PROVIDER_ID: string;
/**
* Creates a new `OIDCProvider`.
*
* @returns {@link auth.AuthCredential}.
* @param oidcSuffix this is the "Provider ID" value from the firebase console fx `azure_test`.
* @param token A provider token.
*/
credential: (oidcSuffix: string, idToken: string) => AuthCredential;
}
/**
* Email and password auth provider implementation.
*/
export interface EmailAuthProvider {
/**
* The provider ID. Always returns `password`.
*/
PROVIDER_ID: string;
/**
* This corresponds to the sign-in method identifier as returned in {@link auth#fetchSignInMethodsForEmail}.
*
* #### Example
*
* ```js
* const signInMethods = await firebase.auth().fetchSignInMethodsForEmail('...');
* if (signInMethods.indexOf(firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD) != -1) {
* // User can sign in with email/link
* }
* ```
*/
EMAIL_LINK_SIGN_IN_METHOD: string;
/**
* This corresponds to the sign-in method identifier as returned in {@link auth#fetchSignInMethodsForEmail}.
*
* #### Example
*
* ```js
* const signInMethods = await firebase.auth().fetchSignInMethodsForEmail('...');
* if (signInMethods.indexOf(firebase.auth.EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD) != -1) {
* // User can sign in with email/password
* }
* ```
*/
EMAIL_PASSWORD_SIGN_IN_METHOD: string;
/**
* Returns the auth provider credential.
*
* #### Example
*
* ```js
* const authCredential = firebase.auth.EmailAuthProvider.credential('joe.bloggs@example.com', '123456');
* ```
*
* @returns {@link auth.AuthCredential}
* @param email Users email address.
* @param password User account password.
*/
credential: (email: string, password: string) => AuthCredential;
/**
* Initialize an `EmailAuthProvider` credential using an email and an email link after a sign in with email link operation.
*
* #### Example
*
* ```js
* const authCredential = firebase.auth.EmailAuthProvider.credentialWithLink('joe.bloggs@example.com', 'https://myexample.com/invite');
* ```
*
* @param email Users email address.
* @param emailLink Sign-in email link.
*/
credentialWithLink: (email: string, emailLink: string) => AuthCredential;
}
/**
*
*/
export interface PhoneAuthState {
/**
* SMS message with verification code sent to phone number.
*/
CODE_SENT: 'sent';
/**
* The timeout specified in {@link auth#verifyPhoneNumber} has expired.
*/
AUTO_VERIFY_TIMEOUT: 'timeout';
/**
* Phone number auto-verification succeeded.
*/
AUTO_VERIFIED: 'verified';
/**
* Phone number verification failed with an error.
*/
ERROR: 'error';
}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface MultiFactorSession {
// this is has no documented contents, it is simply returned from some APIs and passed to others
}
export interface PhoneMultiFactorGenerator {
/**
* Identifies second factors of type phone.
*/
FACTOR_ID: FactorId.PHONE;
/**
* Build a MultiFactorAssertion to resolve the multi-factor sign in process.
*/
assertion(credential: AuthCredential): MultiFactorAssertion;
}
/**
* firebase.auth.X
*/
export interface Statics {
getMultiFactorResolver: getMultiFactorResolver;
/**
* Email and password auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.EmailAuthProvider;
* ```
*/
EmailAuthProvider: EmailAuthProvider;
/**
* Phone auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.PhoneAuthProvider;
* ```
*/
PhoneAuthProvider: AuthProvider;
/**
* Google auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.GoogleAuthProvider;
* ```
*/
GoogleAuthProvider: AuthProvider;
/**
* Apple auth provider implementation. Currently this is iOS only.
*
* For Apple Authentication please see our [`@invertase/react-native-apple-authentication`](https://github.com/invertase/react-native-apple-authentication) library which integrates well with Firebase and provides Firebase + Apple Auth examples.
*
* #### Example
*
* ```js
* firebase.auth.AppleAuthProvider;
* ```
*/
AppleAuthProvider: AuthProvider;
/**
* Github auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.GithubAuthProvider;
* ```
*/
GithubAuthProvider: AuthProvider;
/**
* Twitter auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.TwitterAuthProvider;
* ```
*/
TwitterAuthProvider: AuthProvider;
/**
* Facebook auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.FacebookAuthProvider;
* ```
*/
FacebookAuthProvider: AuthProvider;
/**
* Custom OAuth auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.OAuthProvider;
* ```
*/
OAuthProvider: OAuthProvider;
/**
* Custom Open ID connect auth provider implementation.
*
* #### Example
*
* ```js
* firebase.auth.OIDCAuthProvider;
* ```
*/
OIDCAuthProvider: OIDCProvider;
/**
* A PhoneAuthState interface.
*
* #### Example
*
* ```js
* firebase.auth.PhoneAuthState;
* ```
*/
PhoneAuthState: PhoneAuthState;
/**
* A PhoneMultiFactorGenerator interface.
*/
PhoneMultiFactorGenerator: PhoneMultiFactorGenerator;
}
/**
* A structure containing additional user information from a federated identity provider via {@link auth.UserCredential}.
*
* #### Example
*
* ```js
* const userCredential = await firebase.auth().signInAnonymously();
* console.log('Additional user info: ', userCredential.additionalUserInfo);
* ```
*
* @error auth/operation-not-allowed Thrown if anonymous accounts are not enabled. Enable anonymous accounts in the Firebase Console, under the Auth tab.
*/
export interface AdditionalUserInfo {
/**
* Returns whether the user is new or existing.
*/
isNewUser: boolean;
/**
* Returns an Object containing IDP-specific user data if the provider is one of Facebook,
* GitHub, Google, Twitter, Microsoft, or Yahoo.
*/
profile?: Record<string, any>;
/**
* Returns the provider ID for specifying which provider the information in `profile` is for.
*/
providerId: string;
/**
* Returns the username if the provider is GitHub or Twitter.
*/
username?: string;
}
/**
* A structure containing a User, an AuthCredential, the operationType, and any additional user
* information that was returned from the identity provider. operationType could be 'signIn' for
* a sign-in operation, 'link' for a linking operation and 'reauthenticate' for a re-authentication operation.
*
* TODO @salakar; missing credential, operationType
*/
export interface UserCredential {
/**
* Any additional user information assigned to the user.
*/
additionalUserInfo?: AdditionalUserInfo;
/**
* Returns the {@link auth.User} interface of this credential.
*/
user: User;
}
/**
* Holds the user metadata for the current {@link auth.User}.
*
* #### Example
*
* ```js
* const user = firebase.auth().currentUser;
* console.log('User metadata: ', user.metadata);
* ```
*/
export interface UserMetadata {
/**
* Returns the timestamp at which this account was created as dictated by the server clock
* as an ISO Date string.
*/
creationTime?: string;
/**
* Returns the last signin timestamp as dictated by the server clock as an ISO Date string.
* This is only accurate up to a granularity of 2 minutes for consecutive sign-in attempts.
*/
lastSignInTime?: string;
}
/**
* Identifies the type of a second factor.
*/
export enum FactorId {
PHONE = 'phone',
}
/**
* Contains information about a second factor.
*/
export type MultiFactorInfo = PhoneMultiFactorInfo | TotpMultiFactorInfo;
export interface PhoneMultiFactorInfo extends MultiFactorInfoCommon {
factorId: 'phone';
/**
* The phone number used for this factor.
*/
phoneNumber: string;
}
export interface TotpMultiFactorInfo extends MultiFactorInfoCommon {
factorId: 'totp';
}
export interface MultiFactorInfoCommon {
/**
* User friendly name for this factor.
*/
displayName?: string;
/**
* Time the second factor was enrolled, in UTC.
*/
enrollmentTime: string;
/**
* Unique id for this factor.
*/
uid: string;
}
export interface MultiFactorAssertion {
token: string;
secret: string;
}
export interface PhoneMultiFactorEnrollInfoOptions {
phoneNumber: string;
session: MultiFactorSession;
}
export interface PhoneMultiFactorSignInInfoOptions {
multiFactorHint?: MultiFactorInfo;
/**
* Unused in react-native-firebase ipmlementation
*/
multiFactorUid?: string;
session: MultiFactorSession;
}
/**
* Facilitates the recovery when a user needs to provide a second factor to sign-in.
*/
export interface MultiFactorResolver {
/**
* A list of enrolled factors that can be used to complete the multi-factor challenge.
*/
hints: MultiFactorInfo[];
/**
* Serialized session this resolver belongs to.
*/
session: MultiFactorSession;
/**
* For testing purposes only
*/
_auth?: FirebaseAuthTypes.Module;
/**
* Resolve the multi factor flow.
*/
resolveSignIn(assertion: MultiFactorAssertion): Promise<UserCredential>;
}
/**
* Try and obtain a #{@link MultiFactorResolver} instance based on an error.
* Returns null if no resolver object could be found.
*
* #### Example
*
* ```js
* const auth = firebase.auth();
* auth.signInWithEmailAndPassword(email, password).then((user) => {
* // signed in
* }).catch((error) => {
* if (error.code === 'auth/multi-factor-auth-required') {
* const resolver = getMultiFactorResolver(auth, error);
* }
* });
* ```
*/
export type getMultiFactorResolver = (
auth: FirebaseAuthTypes.Module,
error: unknown,
) => MultiFactorResolver | null;
/**
* The entry point for most multi-factor operations.
*/
export interface MultiFactorUser {
/**
* Returns the user's enrolled factors.
*/
enrolledFactors: MultiFactorInfo[];
/**
* Return the session for this user.
*/
getSession(): Promise<MultiFactorSession>;
/**
* Enroll an additional factor. Provide an optional display name that can be shown to the user.
* The method will ensure the user state is reloaded after successfully enrolling a factor.
*/
enroll(assertion: MultiFactorAssertion, displayName?: string): Promise<void>;
}
/**
* Return the #{@link MultiFactorUser} instance for the current user.
*/
export type multiFactor = (auth: FirebaseAuthTypes.Module) => Promise<MultiFactorUser>;
/**
* Holds information about the user's enrolled factors.
*
* #### Example
*
* ```js
* const user = firebase.auth().currentUser;
* console.log('User multi factors: ', user.multiFactor);
* ```
*/
export interface MultiFactor {
/**
* Returns the enrolled factors
*/
enrolledFactors: MultiFactorInfo[];
}
/**
* Represents a collection of standard profile information for a user. Can be used to expose
* profile information returned by an identity provider, such as Google Sign-In or Facebook Login.
*
* TODO @salakar: isEmailVerified
*
* #### Example
*
* ```js
* const user = firebase.auth().currentUser;
*
* user.providerData.forEach((userInfo) => {
* console.log('User info for provider: ', userInfo);
* });
* ```
*/
export interface UserInfo {
/**
* Returns the user's display name, if available.
*/
displayName?: string;
/**
* Returns the email address corresponding to the user's account in the specified provider, if available.
*/
email?: string;
/**
* The phone number normalized based on the E.164 standard (e.g. +16505550101) for the current user. This is null if the user has no phone credential linked to the account.
*/
phoneNumber?: string;
/**
* Returns a url to the user's profile picture, if available.
*/
photoURL?: string;
/**
* Returns the unique identifier of the provider type that this instance corresponds to.
*/
providerId: string;
/**
* Returns a string representing the multi-tenant tenant id. This is null if the user is not associated with a tenant.
*/
tenantId?: string;
/**
* Returns a user identifier as specified by the authentication provider.
*/
uid: string;
}
/**
* Interface representing ID token result obtained from {@link auth.User#getIdTokenResult}.
* It contains the ID token JWT string and other helper properties for getting different data
* associated with the token as well as all the decoded payload claims.
*
* TODO @salakar validate timestamp types
*
* #### Example
*
* ```js
* const idTokenResult = await firebase.auth().currentUser.getIdTokenResult();
* console.log('User JWT: ', idTokenResult.token);
* ```
*/
export interface IdTokenResult {
/**
* The Firebase Auth ID token JWT string.
*/
token: string;
/**
* The authentication time formatted as a UTC string. This is the time the user authenticated
* (signed in) and not the time the token was refreshed.
*/
authTime: string;
/**
* The ID token issued at time formatted as a UTC string.
*/
issuedAtTime: string;
/**
* The ID token expiration time formatted as a UTC string.
*/
expirationTime: string;
/**
* The sign-in provider through which the ID token was obtained (anonymous, custom,
* phone, password, etc). Note, this does not map to provider IDs.
*/
signInProvider: null | string;
/**
* The entire payload claims of the ID token including the standard reserved claims as well as
* the custom claims.
*/
claims: {
[key: string]: any;
};
}
/**
* Request used to update user profile information.
*
* #### Example
*
* ```js
* const update = {
* displayName: 'Alias',
* photoURL: 'https://my-cdn.com/assets/user/123.png',
* };
*
* await firebase.auth().currentUser.updateProfile(update);
* ```
*/
export interface UpdateProfile {
/**
* An optional display name for the user. Explicitly pass null to clear the displayName.
*/
displayName?: string | null;
/**
* An optional photo URL for the user. Explicitly pass null to clear the photoURL.
*/
photoURL?: string | null;
}
/**
* A result from a {@link auth#signInWithPhoneNumber} call.
*
* #### Example
*
* ```js
* // Force a new message to be sent
* const result = await firebase.auth().signInWithPhoneNumber('#4423456789');
* const user = await result.confirm('12345');
* ```
*/
export interface ConfirmationResult {
/**
* The phone number authentication operation's verification ID. This can be used along with
* the verification code to initialize a phone auth credential.
*/
verificationId: string | null;
/**
* Finishes the sign in flow. Validates a code that was sent to the users device.
*
* @param verificationCode The code sent to the users device from Firebase.
*/
confirm(verificationCode: string): Promise<UserCredential | null>;
}
/**
* Android specific options which can be attached to the {@link auth.ActionCodeSettings} object
* to be sent with requests such as {@link auth.User#sendEmailVerification}.
*
* #### Example
*
* ```js
* await firebase.auth().currentUser.sendEmailVerification({
* android: {
* installApp: true,
* packageName: 'com.awesome.app',
* },
* });
* ```
*/
export interface ActionCodeSettingsAndroid {
/**
* Sets the Android package name. This will try to open the link in an android app if it is installed.
*/
packageName: string;
/**
* If installApp is passed, it specifies whether to install the Android app if the device supports it and the app is not already installed. If this field is provided without a packageName, an error is thrown explaining that the packageName must be provided in conjunction with this field.
*/
installApp?: boolean;
/**
* If minimumVersion is specified, and an older version of the app is installed, the user is taken to the Play Store to upgrade the app. The Android app needs to be registered in the Console.
*/
minimumVersion?: string;
}
/**
* Additional data returned from a {@link auth#checkActionCode} call.
* For the PASSWORD_RESET, VERIFY_EMAIL, and RECOVER_EMAIL actions, this object contains an email field with the address the email was sent to.
* For the RECOVER_EMAIL action, which allows a user to undo an email address change, this object also contains a fromEmail field with the user account's new email address. After the action completes, the user's email address will revert to the value in the email field from the value in fromEmail field.
*
* #### Example
*
* ```js
* const actionCodeInfo = await firebase.auth().checkActionCode('ABCD');
*Data
* console.log('Action code email: ', actionCodeInfo.data.email);
* console.log('Action code from email: ', actionCodeInfo.data.fromEmail);
* ```
*/
export interface ActionCodeInfoData {
/**
* This signifies the email before the call was made.
*/
email?: string;
/**
* This signifies the current email associated with the account, which may have changed as a result of the {@link auth#checkActionCode} call performed.
*/
fromEmail?: string;
}
/**
* The interface returned from a {@link auth#checkActionCode} call.
*
* #### Example
*
* ```js
* const actionCodeInfo = await firebase.auth().checkActionCode('ABCD');
* console.log('Action code operation: ', actionCodeInfo.operation);
* ```
*/
export interface ActionCodeInfo {
/**
* The data associated with the action code.
*/
data: ActionCodeInfoData;
/**
* The operation from where the action originated.
*/
operation: 'PASSWORD_RESET' | 'VERIFY_EMAIL' | 'RECOVER_EMAIL' | 'EMAIL_SIGNIN' | 'ERROR';
}
/**
* iOS specific options which can be attached to the {@link auth.ActionCodeSettings} object
* to be sent with requests such as {@link auth.User#sendEmailVerification}.
*
* #### Example
*
* ```js
* await firebase.auth().currentUser.sendEmailVerification({
* iOS: {
* bundleId: '123456',
* },
* });
* ```
*/
export interface ActionCodeSettingsIos {
/**
* Sets the iOS bundle ID. This will try to open the link in an iOS app if it is installed. The iOS app needs to be registered in the Console.
*/
bundleId?: string;
}
/**
* Options to be sent with requests such as {@link auth.User#sendEmailVerification}.
*
* #### Example
*
* ```js
* await firebase.auth().currentUser.sendEmailVerification({
* handleCodeInApp: true,
* url: 'app/email-verification',
* });
* ```
*/
export interface ActionCodeSettings {
/**
* Android specific settings.
*/
android?: ActionCodeSettingsAndroid;
/**
* Whether the email action link will be opened in a mobile app or a web link first. The default is false. When set to true, the action code link will be be sent as a Universal Link or Android App Link and will be opened by the app if installed. In the false case, the code will be sent to the web widget first and then on continue will redirect to the app if installed.
*/
handleCodeInApp?: boolean;
/**
* iOS specific settings.
*/
iOS?: ActionCodeSettingsIos;
/**
* Sets the dynamic link domain (or subdomain) to use for the current link if it is to be opened using Firebase Dynamic Links. As multiple dynamic link domains can be configured per project, this field provides the ability to explicitly choose one. If none is provided, the first domain is used by default.
* Deprecated - use {@link ActionCodeSettings.linkDomain} instead.
*/
dynamicLinkDomain?: string;
/**
* This URL represents the state/Continue URL in the form of a universal link. This URL can should be constructed as a universal link that would either directly open the app where the action code would be handled or continue to the app after the action code is handled by Firebase.
*/
url: string;
/**
* Firebase Dynamic Links is deprecated and will be shut down as early as August * 2025.
* Instead, use ActionCodeSettings.linkDomain to set a a custom domain. Learn more at: https://firebase.google.com/support/dynamic-links-faq
*/
linkDomain?: string;
}
/**
* An auth listener callback function for {@link auth#onAuthStateChanged}.
*
* #### Example
*
* ```js
* function listener(user) {
* if (user) {
* // Signed in
* } else {
* // Signed out
* }
* }
*
* firebase.auth().onAuthStateChanged(listener);
* ```
*/
export type AuthListenerCallback = (user: User | null) => void;
/**
* A snapshot interface of the current phone auth state.
*
* #### Example
*
* ```js
* firebase.auth().verifyPhoneNumber('+4423456789')
* .on('state_changed', (phoneAuthSnapshot) => {
* console.log('Snapshot state: ', phoneAuthSnapshot.state);
* });
* ```
*/
export interface PhoneAuthSnapshot {
/**
* The current phone auth verification state.
*
* - `sent`: On iOS, this is the final event received. Once sent, show a visible input box asking the user to enter the verification code.
* - `timeout`: Auto verification has timed out. Show a visible input box asking the user to enter the verification code.
* - `verified`: The verification code has automatically been verified by the Android device. The snapshot contains the verification ID & code to create a credential.
* - `error`: An error occurred. Handle or allow the promise to reject.
*/
state: 'sent' | 'timeout' | 'verified' | 'error';
/**
* The verification ID to build a `PhoneAuthProvider` credential.
*/
verificationId: string;
/**
* The verification code. Will only be available if auto verification has taken place.
*/
code: string | null;
/**
* A native JavaScript error if an error occurs.
*/
error: NativeFirebaseError | null;
}
/**
* A custom error in the event verifying a phone number failed.
*
* #### Example
*
* ```js
* firebase.auth().verifyPhoneNumber('+4423456789')
* .on('state_changed', (phoneAuthSnapshot) => {
* console.log('Snapshot state: ', phoneAuthSnapshot.state);
* }, (phoneAuthError) => {
* console.error('Error: ', phoneAuthError.message);
* });
* ```
*/
export interface PhoneAuthError {
/**
* The code the verification failed with.
*/
code: string | null;
/**
* The verification ID which failed.
*/
verificationId: string;
/**
* JavaScript error message.
*/
message: string | null;
/**
* JavaScript error stack trace.
*/
stack: string | null;
}
/**
* The listener function returned from a {@link auth#verifyPhoneNumber} call.
*/
export interface PhoneAuthListener {
/**
* The phone auth state listener. See {@link auth.PhoneAuthState} for different event state types.
*
* #### Example
*
* ```js
* firebase.auth().verifyPhoneNumber('+4423456789')
* .on('state_changed', (phoneAuthSnapshot) => {
* console.log('State: ', phoneAuthSnapshot.state);
* }, (error) => {