@react-native-firebase/auth 24.1.0 → 25.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +16 -4
  3. package/dist/module/ActionCodeURL.js +140 -0
  4. package/dist/module/ActionCodeURL.js.map +1 -0
  5. package/{lib → dist/module}/ConfirmationResult.js +4 -5
  6. package/dist/module/ConfirmationResult.js.map +1 -0
  7. package/{lib → dist/module}/MultiFactorResolver.js +14 -5
  8. package/dist/module/MultiFactorResolver.js.map +1 -0
  9. package/{lib → dist/module}/PhoneAuthListener.js +52 -75
  10. package/dist/module/PhoneAuthListener.js.map +1 -0
  11. package/dist/module/PhoneAuthState.js +25 -0
  12. package/dist/module/PhoneAuthState.js.map +1 -0
  13. package/dist/module/PhoneMultiFactorGenerator.js +39 -0
  14. package/dist/module/PhoneMultiFactorGenerator.js.map +1 -0
  15. package/{lib → dist/module}/Settings.js +3 -7
  16. package/dist/module/Settings.js.map +1 -0
  17. package/{lib → dist/module}/TotpMultiFactorGenerator.js +20 -15
  18. package/dist/module/TotpMultiFactorGenerator.js.map +1 -0
  19. package/{lib → dist/module}/TotpSecret.js +7 -5
  20. package/dist/module/TotpSecret.js.map +1 -0
  21. package/dist/module/User.js +245 -0
  22. package/dist/module/User.js.map +1 -0
  23. package/dist/module/constants.js +54 -0
  24. package/dist/module/constants.js.map +1 -0
  25. package/dist/module/credentials/AuthCredential.js +51 -0
  26. package/dist/module/credentials/AuthCredential.js.map +1 -0
  27. package/dist/module/credentials/EmailAuthCredential.js +51 -0
  28. package/dist/module/credentials/EmailAuthCredential.js.map +1 -0
  29. package/dist/module/credentials/OAuthCredential.js +84 -0
  30. package/dist/module/credentials/OAuthCredential.js.map +1 -0
  31. package/dist/module/credentials/PhoneAuthCredential.js +50 -0
  32. package/dist/module/credentials/PhoneAuthCredential.js.map +1 -0
  33. package/{lib/providers/GoogleAuthProvider.js → dist/module/credentials/index.js} +7 -19
  34. package/dist/module/credentials/index.js.map +1 -0
  35. package/{lib → dist/module}/getMultiFactorResolver.js +5 -8
  36. package/dist/module/getMultiFactorResolver.js.map +1 -0
  37. package/{lib/providers/FacebookAuthProvider.js → dist/module/index.js} +11 -18
  38. package/dist/module/index.js.map +1 -0
  39. package/dist/module/modular.js +779 -0
  40. package/dist/module/modular.js.map +1 -0
  41. package/{lib → dist/module}/multiFactor.js +16 -14
  42. package/dist/module/multiFactor.js.map +1 -0
  43. package/dist/module/namespaced.js +522 -0
  44. package/dist/module/namespaced.js.map +1 -0
  45. package/dist/module/package.json +1 -0
  46. package/dist/module/password-policy/PasswordPolicyImpl.js +103 -0
  47. package/dist/module/password-policy/PasswordPolicyImpl.js.map +1 -0
  48. package/{lib → dist/module}/password-policy/PasswordPolicyMixin.js +14 -16
  49. package/dist/module/password-policy/PasswordPolicyMixin.js.map +1 -0
  50. package/{lib → dist/module}/password-policy/passwordPolicyApi.js +18 -12
  51. package/dist/module/password-policy/passwordPolicyApi.js.map +1 -0
  52. package/{lib → dist/module}/providers/AppleAuthProvider.js +14 -7
  53. package/dist/module/providers/AppleAuthProvider.js.map +1 -0
  54. package/{lib → dist/module}/providers/EmailAuthProvider.js +10 -25
  55. package/dist/module/providers/EmailAuthProvider.js.map +1 -0
  56. package/dist/module/providers/FacebookAuthProvider.js +56 -0
  57. package/dist/module/providers/FacebookAuthProvider.js.map +1 -0
  58. package/dist/module/providers/GithubAuthProvider.js +49 -0
  59. package/dist/module/providers/GithubAuthProvider.js.map +1 -0
  60. package/dist/module/providers/GoogleAuthProvider.js +57 -0
  61. package/dist/module/providers/GoogleAuthProvider.js.map +1 -0
  62. package/dist/module/providers/OAuthProvider.js +116 -0
  63. package/dist/module/providers/OAuthProvider.js.map +1 -0
  64. package/{lib → dist/module}/providers/OIDCAuthProvider.js +15 -7
  65. package/dist/module/providers/OIDCAuthProvider.js.map +1 -0
  66. package/dist/module/providers/PhoneAuthProvider.js +87 -0
  67. package/dist/module/providers/PhoneAuthProvider.js.map +1 -0
  68. package/dist/module/providers/TwitterAuthProvider.js +50 -0
  69. package/dist/module/providers/TwitterAuthProvider.js.map +1 -0
  70. package/dist/module/types/auth.js +43 -0
  71. package/dist/module/types/auth.js.map +1 -0
  72. package/dist/module/types/internal.js +4 -0
  73. package/dist/module/types/internal.js.map +1 -0
  74. package/dist/module/types/namespaced.js +62 -0
  75. package/dist/module/types/namespaced.js.map +1 -0
  76. package/dist/module/version.js +5 -0
  77. package/dist/module/version.js.map +1 -0
  78. package/dist/module/web/RNFBAuthModule.android.js +5 -0
  79. package/dist/module/web/RNFBAuthModule.android.js.map +1 -0
  80. package/dist/module/web/RNFBAuthModule.ios.js +5 -0
  81. package/dist/module/web/RNFBAuthModule.ios.js.map +1 -0
  82. package/{lib → dist/module}/web/RNFBAuthModule.js +104 -321
  83. package/dist/module/web/RNFBAuthModule.js.map +1 -0
  84. package/dist/typescript/lib/ActionCodeURL.d.ts +41 -0
  85. package/dist/typescript/lib/ActionCodeURL.d.ts.map +1 -0
  86. package/dist/typescript/lib/ConfirmationResult.d.ts +10 -0
  87. package/dist/typescript/lib/ConfirmationResult.d.ts.map +1 -0
  88. package/dist/typescript/lib/MultiFactorResolver.d.ts +24 -0
  89. package/dist/typescript/lib/MultiFactorResolver.d.ts.map +1 -0
  90. package/dist/typescript/lib/PhoneAuthListener.d.ts +34 -0
  91. package/dist/typescript/lib/PhoneAuthListener.d.ts.map +1 -0
  92. package/dist/typescript/lib/PhoneAuthState.d.ts +7 -0
  93. package/dist/typescript/lib/PhoneAuthState.d.ts.map +1 -0
  94. package/dist/typescript/lib/PhoneMultiFactorGenerator.d.ts +7 -0
  95. package/dist/typescript/lib/PhoneMultiFactorGenerator.d.ts.map +1 -0
  96. package/dist/typescript/lib/Settings.d.ts +13 -0
  97. package/dist/typescript/lib/Settings.d.ts.map +1 -0
  98. package/dist/typescript/lib/TotpMultiFactorGenerator.d.ts +11 -0
  99. package/dist/typescript/lib/TotpMultiFactorGenerator.d.ts.map +1 -0
  100. package/dist/typescript/lib/TotpSecret.d.ts +33 -0
  101. package/dist/typescript/lib/TotpSecret.d.ts.map +1 -0
  102. package/dist/typescript/lib/User.d.ts +51 -0
  103. package/dist/typescript/lib/User.d.ts.map +1 -0
  104. package/dist/typescript/lib/constants.d.ts +35 -0
  105. package/dist/typescript/lib/constants.d.ts.map +1 -0
  106. package/dist/typescript/lib/credentials/AuthCredential.d.ts +12 -0
  107. package/dist/typescript/lib/credentials/AuthCredential.d.ts.map +1 -0
  108. package/dist/typescript/lib/credentials/EmailAuthCredential.d.ts +8 -0
  109. package/dist/typescript/lib/credentials/EmailAuthCredential.d.ts.map +1 -0
  110. package/dist/typescript/lib/credentials/OAuthCredential.d.ts +22 -0
  111. package/dist/typescript/lib/credentials/OAuthCredential.d.ts.map +1 -0
  112. package/dist/typescript/lib/credentials/PhoneAuthCredential.d.ts +8 -0
  113. package/dist/typescript/lib/credentials/PhoneAuthCredential.d.ts.map +1 -0
  114. package/dist/typescript/lib/credentials/index.d.ts +5 -0
  115. package/dist/typescript/lib/credentials/index.d.ts.map +1 -0
  116. package/dist/typescript/lib/getMultiFactorResolver.d.ts +19 -0
  117. package/dist/typescript/lib/getMultiFactorResolver.d.ts.map +1 -0
  118. package/dist/typescript/lib/index.d.ts +8 -0
  119. package/dist/typescript/lib/index.d.ts.map +1 -0
  120. package/dist/typescript/lib/modular.d.ts +360 -0
  121. package/dist/typescript/lib/modular.d.ts.map +1 -0
  122. package/dist/typescript/lib/multiFactor.d.ts +26 -0
  123. package/dist/typescript/lib/multiFactor.d.ts.map +1 -0
  124. package/dist/typescript/lib/namespaced.d.ts +12 -0
  125. package/dist/typescript/lib/namespaced.d.ts.map +1 -0
  126. package/dist/typescript/lib/password-policy/PasswordPolicyImpl.d.ts +19 -0
  127. package/dist/typescript/lib/password-policy/PasswordPolicyImpl.d.ts.map +1 -0
  128. package/dist/typescript/lib/password-policy/PasswordPolicyMixin.d.ts +11 -0
  129. package/dist/typescript/lib/password-policy/PasswordPolicyMixin.d.ts.map +1 -0
  130. package/dist/typescript/lib/password-policy/passwordPolicyApi.d.ts +10 -0
  131. package/dist/typescript/lib/password-policy/passwordPolicyApi.d.ts.map +1 -0
  132. package/dist/typescript/lib/providers/AppleAuthProvider.d.ts +16 -0
  133. package/dist/typescript/lib/providers/AppleAuthProvider.d.ts.map +1 -0
  134. package/dist/typescript/lib/providers/EmailAuthProvider.d.ts +11 -0
  135. package/dist/typescript/lib/providers/EmailAuthProvider.d.ts.map +1 -0
  136. package/dist/typescript/lib/providers/FacebookAuthProvider.d.ts +19 -0
  137. package/dist/typescript/lib/providers/FacebookAuthProvider.d.ts.map +1 -0
  138. package/dist/typescript/lib/providers/GithubAuthProvider.d.ts +15 -0
  139. package/dist/typescript/lib/providers/GithubAuthProvider.d.ts.map +1 -0
  140. package/dist/typescript/lib/providers/GoogleAuthProvider.d.ts +21 -0
  141. package/dist/typescript/lib/providers/GoogleAuthProvider.d.ts.map +1 -0
  142. package/dist/typescript/lib/providers/OAuthProvider.d.ts +33 -0
  143. package/dist/typescript/lib/providers/OAuthProvider.d.ts.map +1 -0
  144. package/dist/typescript/lib/providers/OIDCAuthProvider.d.ts +16 -0
  145. package/dist/typescript/lib/providers/OIDCAuthProvider.d.ts.map +1 -0
  146. package/dist/typescript/lib/providers/PhoneAuthProvider.d.ts +16 -0
  147. package/dist/typescript/lib/providers/PhoneAuthProvider.d.ts.map +1 -0
  148. package/dist/typescript/lib/providers/TwitterAuthProvider.d.ts +15 -0
  149. package/dist/typescript/lib/providers/TwitterAuthProvider.d.ts.map +1 -0
  150. package/dist/typescript/lib/types/auth.d.ts +305 -0
  151. package/dist/typescript/lib/types/auth.d.ts.map +1 -0
  152. package/dist/typescript/lib/types/internal.d.ts +292 -0
  153. package/dist/typescript/lib/types/internal.d.ts.map +1 -0
  154. package/dist/typescript/lib/types/namespaced.d.ts +2185 -0
  155. package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
  156. package/dist/typescript/lib/version.d.ts +2 -0
  157. package/dist/typescript/lib/version.d.ts.map +1 -0
  158. package/dist/typescript/lib/web/RNFBAuthModule.android.d.ts +3 -0
  159. package/dist/typescript/lib/web/RNFBAuthModule.android.d.ts.map +1 -0
  160. package/dist/typescript/lib/web/RNFBAuthModule.d.ts +406 -0
  161. package/dist/typescript/lib/web/RNFBAuthModule.d.ts.map +1 -0
  162. package/dist/typescript/lib/web/RNFBAuthModule.ios.d.ts +3 -0
  163. package/dist/typescript/lib/web/RNFBAuthModule.ios.d.ts.map +1 -0
  164. package/dist/typescript/package.json +1 -0
  165. package/ios/RNFBAuth/RNFBAuthModule.m +4 -2
  166. package/lib/ActionCodeURL.ts +174 -0
  167. package/lib/ConfirmationResult.ts +42 -0
  168. package/lib/MultiFactorResolver.ts +51 -0
  169. package/lib/PhoneAuthListener.ts +312 -0
  170. package/lib/PhoneAuthState.ts +22 -0
  171. package/lib/{PhoneMultiFactorGenerator.js → PhoneMultiFactorGenerator.ts} +8 -2
  172. package/lib/Settings.ts +59 -0
  173. package/lib/TotpMultiFactorGenerator.ts +78 -0
  174. package/lib/TotpSecret.ts +71 -0
  175. package/lib/{User.js → User.ts} +127 -83
  176. package/lib/constants.ts +55 -0
  177. package/lib/credentials/AuthCredential.ts +55 -0
  178. package/lib/credentials/EmailAuthCredential.ts +70 -0
  179. package/lib/credentials/OAuthCredential.ts +113 -0
  180. package/lib/credentials/PhoneAuthCredential.ts +66 -0
  181. package/lib/{providers/GithubAuthProvider.js → credentials/index.ts} +4 -19
  182. package/lib/getMultiFactorResolver.ts +40 -0
  183. package/lib/{providers/TwitterAuthProvider.js → index.ts} +14 -19
  184. package/lib/modular.ts +1158 -0
  185. package/lib/multiFactor.ts +83 -0
  186. package/lib/namespaced.ts +846 -0
  187. package/lib/password-policy/{PasswordPolicyImpl.js → PasswordPolicyImpl.ts} +37 -19
  188. package/lib/password-policy/PasswordPolicyMixin.ts +83 -0
  189. package/lib/password-policy/passwordPolicyApi.ts +60 -0
  190. package/lib/providers/AppleAuthProvider.ts +44 -0
  191. package/lib/providers/EmailAuthProvider.ts +42 -0
  192. package/lib/providers/FacebookAuthProvider.ts +58 -0
  193. package/lib/providers/GithubAuthProvider.ts +51 -0
  194. package/lib/providers/GoogleAuthProvider.ts +60 -0
  195. package/lib/providers/OAuthProvider.ts +150 -0
  196. package/lib/providers/OIDCAuthProvider.ts +49 -0
  197. package/lib/providers/PhoneAuthProvider.ts +161 -0
  198. package/lib/providers/TwitterAuthProvider.ts +52 -0
  199. package/lib/types/auth.ts +393 -0
  200. package/lib/types/internal.ts +474 -0
  201. package/lib/{index.d.ts → types/namespaced.ts} +52 -41
  202. package/lib/version.ts +2 -0
  203. package/lib/web/RNFBAuthModule.ts +1359 -0
  204. package/package.json +41 -9
  205. package/plugin/tsconfig.tsbuildinfo +1 -1
  206. package/tsconfig.json +26 -0
  207. package/tsdoc.json +22 -0
  208. package/typedoc.json +9 -2
  209. package/lib/index.js +0 -572
  210. package/lib/modular/index.d.ts +0 -801
  211. package/lib/modular/index.js +0 -651
  212. package/lib/providers/OAuthProvider.js +0 -70
  213. package/lib/providers/PhoneAuthProvider.js +0 -52
  214. package/lib/version.js +0 -2
  215. /package/lib/web/{RNFBAuthModule.android.js → RNFBAuthModule.android.ts} +0 -0
  216. /package/lib/web/{RNFBAuthModule.ios.js → RNFBAuthModule.ios.ts} +0 -0
package/lib/index.js DELETED
@@ -1,572 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- import {
19
- createDeprecationProxy,
20
- isAndroid,
21
- isBoolean,
22
- isNull,
23
- isOther,
24
- isString,
25
- isValidUrl,
26
- parseListenerOrObserver,
27
- } from '@react-native-firebase/app/dist/module/common';
28
- import { setReactNativeModule } from '@react-native-firebase/app/dist/module/internal/nativeModule';
29
- import {
30
- FirebaseModule,
31
- createModuleNamespace,
32
- getFirebaseRoot,
33
- } from '@react-native-firebase/app/dist/module/internal';
34
- import ConfirmationResult from './ConfirmationResult';
35
- import PhoneAuthListener from './PhoneAuthListener';
36
- import PhoneMultiFactorGenerator from './PhoneMultiFactorGenerator';
37
- import TotpMultiFactorGenerator from './TotpMultiFactorGenerator';
38
- import Settings from './Settings';
39
- import User from './User';
40
- import { getMultiFactorResolver } from './getMultiFactorResolver';
41
- import { MultiFactorUser, multiFactor } from './multiFactor';
42
- import AppleAuthProvider from './providers/AppleAuthProvider';
43
- import EmailAuthProvider from './providers/EmailAuthProvider';
44
- import FacebookAuthProvider from './providers/FacebookAuthProvider';
45
- import GithubAuthProvider from './providers/GithubAuthProvider';
46
- import GoogleAuthProvider from './providers/GoogleAuthProvider';
47
- import OAuthProvider from './providers/OAuthProvider';
48
- import OIDCAuthProvider from './providers/OIDCAuthProvider';
49
- import PhoneAuthProvider from './providers/PhoneAuthProvider';
50
- import TwitterAuthProvider from './providers/TwitterAuthProvider';
51
- import { TotpSecret } from './TotpSecret';
52
- import version from './version';
53
- import fallBackModule from './web/RNFBAuthModule';
54
- import { PasswordPolicyMixin } from './password-policy/PasswordPolicyMixin';
55
-
56
- const PhoneAuthState = {
57
- CODE_SENT: 'sent',
58
- AUTO_VERIFY_TIMEOUT: 'timeout',
59
- AUTO_VERIFIED: 'verified',
60
- ERROR: 'error',
61
- };
62
-
63
- export {
64
- AppleAuthProvider,
65
- EmailAuthProvider,
66
- PhoneAuthProvider,
67
- GoogleAuthProvider,
68
- GithubAuthProvider,
69
- TwitterAuthProvider,
70
- FacebookAuthProvider,
71
- PhoneMultiFactorGenerator,
72
- TotpMultiFactorGenerator,
73
- TotpSecret,
74
- OAuthProvider,
75
- OIDCAuthProvider,
76
- PhoneAuthState,
77
- };
78
-
79
- const statics = {
80
- AppleAuthProvider,
81
- EmailAuthProvider,
82
- PhoneAuthProvider,
83
- GoogleAuthProvider,
84
- GithubAuthProvider,
85
- TwitterAuthProvider,
86
- FacebookAuthProvider,
87
- PhoneMultiFactorGenerator,
88
- TotpMultiFactorGenerator,
89
- OAuthProvider,
90
- OIDCAuthProvider,
91
- PhoneAuthState,
92
- getMultiFactorResolver,
93
- multiFactor,
94
- };
95
-
96
- const namespace = 'auth';
97
- const nativeModuleName = 'RNFBAuthModule';
98
-
99
- class FirebaseAuthModule extends FirebaseModule {
100
- constructor(...args) {
101
- super(...args);
102
- this._user = null;
103
- this._settings = null;
104
- this._authResult = false;
105
- this._languageCode = this.native.APP_LANGUAGE[this.app._name];
106
- this._tenantId = null;
107
- this._projectPasswordPolicy = null;
108
- this._tenantPasswordPolicies = {};
109
-
110
- if (!this.languageCode) {
111
- this._languageCode = this.native.APP_LANGUAGE['[DEFAULT]'];
112
- }
113
-
114
- if (this.native.APP_USER[this.app._name]) {
115
- this._setUser(this.native.APP_USER[this.app._name]);
116
- }
117
-
118
- this.emitter.addListener(this.eventNameForApp('auth_state_changed'), event => {
119
- this._setUser(event.user);
120
- this.emitter.emit(this.eventNameForApp('onAuthStateChanged'), this._user);
121
- });
122
-
123
- this.emitter.addListener(this.eventNameForApp('phone_auth_state_changed'), event => {
124
- const eventKey = `phone:auth:${event.requestKey}:${event.type}`;
125
- this.emitter.emit(eventKey, event.state);
126
- });
127
-
128
- this.emitter.addListener(this.eventNameForApp('auth_id_token_changed'), auth => {
129
- this._setUser(auth.user);
130
- this.emitter.emit(this.eventNameForApp('onIdTokenChanged'), this._user);
131
- });
132
-
133
- this.native.addAuthStateListener();
134
- this.native.addIdTokenListener();
135
-
136
- // custom authDomain in only available from App's FirebaseOptions,
137
- // but we need it in Auth if it exists. During app configuration we store
138
- // mappings from app name to authDomain, this auth constructor
139
- // is a reasonable time to use the mapping and set it into auth natively
140
- if (!isOther) {
141
- // Only supported on native platforms
142
- this.native.configureAuthDomain();
143
- }
144
- }
145
-
146
- get languageCode() {
147
- return this._languageCode;
148
- }
149
-
150
- set languageCode(code) {
151
- // For modular API, not recommended to set languageCode directly as it should be set in the native SDKs first
152
- if (!isString(code) && !isNull(code)) {
153
- throw new Error(
154
- "firebase.auth().languageCode = (*) expected 'languageCode' to be a string or null value",
155
- );
156
- }
157
- // as this is a setter, we can't use async/await. So we set it first so it is available immediately
158
- if (code === null) {
159
- this._languageCode = this.native.APP_LANGUAGE[this.app._name];
160
-
161
- if (!this.languageCode) {
162
- this._languageCode = this.native.APP_LANGUAGE['[DEFAULT]'];
163
- }
164
- } else {
165
- this._languageCode = code;
166
- }
167
- // This sets it natively
168
- this.setLanguageCode(code);
169
- }
170
-
171
- get config() {
172
- // for modular API, firebase JS SDK has a config object which is not available in native SDKs
173
- return {};
174
- }
175
-
176
- get tenantId() {
177
- return this._tenantId;
178
- }
179
-
180
- get settings() {
181
- if (!this._settings) {
182
- this._settings = new Settings(this);
183
- }
184
- return this._settings;
185
- }
186
-
187
- get currentUser() {
188
- return this._user;
189
- }
190
-
191
- _setUser(user) {
192
- this._user = user ? createDeprecationProxy(new User(this, user)) : null;
193
- this._authResult = true;
194
- this.emitter.emit(this.eventNameForApp('onUserChanged'), this._user);
195
- return this._user;
196
- }
197
-
198
- _setUserCredential(userCredential) {
199
- const user = createDeprecationProxy(new User(this, userCredential.user));
200
- this._user = user;
201
- this._authResult = true;
202
- this.emitter.emit(this.eventNameForApp('onUserChanged'), this._user);
203
- return {
204
- additionalUserInfo: userCredential.additionalUserInfo,
205
- user,
206
- };
207
- }
208
-
209
- async setLanguageCode(code) {
210
- if (!isString(code) && !isNull(code)) {
211
- throw new Error(
212
- "firebase.auth().setLanguageCode(*) expected 'languageCode' to be a string or null value",
213
- );
214
- }
215
-
216
- await this.native.setLanguageCode(code);
217
-
218
- if (code === null) {
219
- this._languageCode = this.native.APP_LANGUAGE[this.app._name];
220
-
221
- if (!this.languageCode) {
222
- this._languageCode = this.native.APP_LANGUAGE['[DEFAULT]'];
223
- }
224
- } else {
225
- this._languageCode = code;
226
- }
227
- }
228
-
229
- async setTenantId(tenantId) {
230
- if (!isString(tenantId)) {
231
- throw new Error("firebase.auth().setTenantId(*) expected 'tenantId' to be a string");
232
- }
233
- this._tenantId = tenantId;
234
- await this.native.setTenantId(tenantId);
235
- }
236
-
237
- onAuthStateChanged(listenerOrObserver) {
238
- const listener = parseListenerOrObserver(listenerOrObserver);
239
- const subscription = this.emitter.addListener(
240
- this.eventNameForApp('onAuthStateChanged'),
241
- listener,
242
- );
243
-
244
- if (this._authResult) {
245
- Promise.resolve().then(() => {
246
- listener(this._user || null);
247
- });
248
- }
249
- return () => subscription.remove();
250
- }
251
-
252
- onIdTokenChanged(listenerOrObserver) {
253
- const listener = parseListenerOrObserver(listenerOrObserver);
254
- const subscription = this.emitter.addListener(
255
- this.eventNameForApp('onIdTokenChanged'),
256
- listener,
257
- );
258
-
259
- if (this._authResult) {
260
- Promise.resolve().then(() => {
261
- listener(this._user || null);
262
- });
263
- }
264
- return () => subscription.remove();
265
- }
266
-
267
- onUserChanged(listenerOrObserver) {
268
- const listener = parseListenerOrObserver(listenerOrObserver);
269
- const subscription = this.emitter.addListener(this.eventNameForApp('onUserChanged'), listener);
270
- if (this._authResult) {
271
- Promise.resolve().then(() => {
272
- listener(this._user || null);
273
- });
274
- }
275
-
276
- return () => {
277
- subscription.remove();
278
- };
279
- }
280
-
281
- signOut() {
282
- return this.native.signOut().then(() => {
283
- this._setUser();
284
- });
285
- }
286
-
287
- signInAnonymously() {
288
- return this.native
289
- .signInAnonymously()
290
- .then(userCredential => this._setUserCredential(userCredential));
291
- }
292
-
293
- signInWithPhoneNumber(phoneNumber, forceResend) {
294
- if (isAndroid) {
295
- return this.native
296
- .signInWithPhoneNumber(phoneNumber, forceResend || false)
297
- .then(result => new ConfirmationResult(this, result.verificationId));
298
- }
299
-
300
- return this.native
301
- .signInWithPhoneNumber(phoneNumber)
302
- .then(result => new ConfirmationResult(this, result.verificationId));
303
- }
304
-
305
- verifyPhoneNumber(phoneNumber, autoVerifyTimeoutOrForceResend, forceResend) {
306
- let _forceResend = forceResend;
307
- let _autoVerifyTimeout = 60;
308
-
309
- if (isBoolean(autoVerifyTimeoutOrForceResend)) {
310
- _forceResend = autoVerifyTimeoutOrForceResend;
311
- } else {
312
- _autoVerifyTimeout = autoVerifyTimeoutOrForceResend;
313
- }
314
-
315
- return new PhoneAuthListener(this, phoneNumber, _autoVerifyTimeout, _forceResend);
316
- }
317
-
318
- verifyPhoneNumberWithMultiFactorInfo(multiFactorHint, session) {
319
- return this.native.verifyPhoneNumberWithMultiFactorInfo(multiFactorHint.uid, session);
320
- }
321
-
322
- verifyPhoneNumberForMultiFactor(phoneInfoOptions) {
323
- const { phoneNumber, session } = phoneInfoOptions;
324
- return this.native.verifyPhoneNumberForMultiFactor(phoneNumber, session);
325
- }
326
-
327
- resolveMultiFactorSignIn(session, verificationId, verificationCode) {
328
- return this.native
329
- .resolveMultiFactorSignIn(session, verificationId, verificationCode)
330
- .then(userCredential => {
331
- return this._setUserCredential(userCredential);
332
- });
333
- }
334
-
335
- resolveTotpSignIn(session, uid, totpSecret) {
336
- return this.native.resolveTotpSignIn(session, uid, totpSecret).then(userCredential => {
337
- return this._setUserCredential(userCredential);
338
- });
339
- }
340
-
341
- createUserWithEmailAndPassword(email, password) {
342
- return (
343
- this.native
344
- .createUserWithEmailAndPassword(email, password)
345
- .then(userCredential => this._setUserCredential(userCredential))
346
- /* istanbul ignore next - native error handling cannot be unit tested */
347
- .catch(error => {
348
- if (error.code === 'auth/password-does-not-meet-requirements') {
349
- return this._recachePasswordPolicy()
350
- .catch(() => {
351
- // Silently ignore recache failures - the original error matters more
352
- })
353
- .then(() => {
354
- throw error;
355
- });
356
- }
357
- throw error;
358
- })
359
- );
360
- }
361
-
362
- signInWithEmailAndPassword(email, password) {
363
- return (
364
- this.native
365
- .signInWithEmailAndPassword(email, password)
366
- .then(userCredential => this._setUserCredential(userCredential))
367
- /* istanbul ignore next - native error handling cannot be unit tested */
368
- .catch(error => {
369
- if (error.code === 'auth/password-does-not-meet-requirements') {
370
- return this._recachePasswordPolicy()
371
- .catch(() => {
372
- // Silently ignore recache failures - the original error matters more
373
- })
374
- .then(() => {
375
- throw error;
376
- });
377
- }
378
- throw error;
379
- })
380
- );
381
- }
382
-
383
- signInWithCustomToken(customToken) {
384
- return this.native
385
- .signInWithCustomToken(customToken)
386
- .then(userCredential => this._setUserCredential(userCredential));
387
- }
388
-
389
- signInWithCredential(credential) {
390
- return this.native
391
- .signInWithCredential(credential.providerId, credential.token, credential.secret)
392
- .then(userCredential => this._setUserCredential(userCredential));
393
- }
394
-
395
- revokeToken(authorizationCode) {
396
- return this.native.revokeToken(authorizationCode);
397
- }
398
-
399
- sendPasswordResetEmail(email, actionCodeSettings = null) {
400
- return this.native.sendPasswordResetEmail(email, actionCodeSettings);
401
- }
402
-
403
- sendSignInLinkToEmail(email, actionCodeSettings = {}) {
404
- return this.native.sendSignInLinkToEmail(email, actionCodeSettings);
405
- }
406
-
407
- isSignInWithEmailLink(emailLink) {
408
- return this.native.isSignInWithEmailLink(emailLink);
409
- }
410
-
411
- signInWithEmailLink(email, emailLink) {
412
- return this.native
413
- .signInWithEmailLink(email, emailLink)
414
- .then(userCredential => this._setUserCredential(userCredential));
415
- }
416
-
417
- confirmPasswordReset(code, newPassword) {
418
- return (
419
- this.native
420
- .confirmPasswordReset(code, newPassword)
421
- /* istanbul ignore next - native error handling cannot be unit tested */
422
- .catch(error => {
423
- if (error.code === 'auth/password-does-not-meet-requirements') {
424
- return this._recachePasswordPolicy()
425
- .catch(() => {
426
- // Silently ignore recache failures - the original error matters more
427
- })
428
- .then(() => {
429
- throw error;
430
- });
431
- }
432
- throw error;
433
- })
434
- );
435
- }
436
-
437
- applyActionCode(code) {
438
- return this.native.applyActionCode(code).then(user => {
439
- this._setUser(user);
440
- });
441
- }
442
-
443
- checkActionCode(code) {
444
- return this.native.checkActionCode(code);
445
- }
446
-
447
- fetchSignInMethodsForEmail(email) {
448
- return this.native.fetchSignInMethodsForEmail(email);
449
- }
450
-
451
- verifyPasswordResetCode(code) {
452
- return this.native.verifyPasswordResetCode(code);
453
- }
454
-
455
- useUserAccessGroup(userAccessGroup) {
456
- if (isAndroid) {
457
- return Promise.resolve();
458
- }
459
- return this.native.useUserAccessGroup(userAccessGroup);
460
- }
461
-
462
- getRedirectResult() {
463
- throw new Error(
464
- 'firebase.auth().getRedirectResult() is unsupported by the native Firebase SDKs.',
465
- );
466
- }
467
-
468
- setPersistence() {
469
- throw new Error('firebase.auth().setPersistence() is unsupported by the native Firebase SDKs.');
470
- }
471
-
472
- signInWithPopup(provider) {
473
- return this.native
474
- .signInWithProvider(provider.toObject())
475
- .then(userCredential => this._setUserCredential(userCredential));
476
- }
477
-
478
- signInWithRedirect(provider) {
479
- return this.native
480
- .signInWithProvider(provider.toObject())
481
- .then(userCredential => this._setUserCredential(userCredential));
482
- }
483
-
484
- // firebase issue - https://github.com/invertase/react-native-firebase/pull/655#issuecomment-349904680
485
- useDeviceLanguage() {
486
- throw new Error(
487
- 'firebase.auth().useDeviceLanguage() is unsupported by the native Firebase SDKs.',
488
- );
489
- }
490
-
491
- useEmulator(url) {
492
- if (!url || !isString(url) || !isValidUrl(url)) {
493
- throw new Error('firebase.auth().useEmulator() takes a non-empty string URL');
494
- }
495
-
496
- let _url = url;
497
- const androidBypassEmulatorUrlRemap =
498
- typeof this.firebaseJson.android_bypass_emulator_url_remap === 'boolean' &&
499
- this.firebaseJson.android_bypass_emulator_url_remap;
500
- if (!androidBypassEmulatorUrlRemap && isAndroid && _url) {
501
- if (_url.startsWith('http://localhost')) {
502
- _url = _url.replace('http://localhost', 'http://10.0.2.2');
503
- // eslint-disable-next-line no-console
504
- console.log(
505
- 'Mapping auth host "localhost" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.',
506
- );
507
- }
508
- if (_url.startsWith('http://127.0.0.1')) {
509
- _url = _url.replace('http://127.0.0.1', 'http://10.0.2.2');
510
- // eslint-disable-next-line no-console
511
- console.log(
512
- 'Mapping auth host "127.0.0.1" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.',
513
- );
514
- }
515
- }
516
-
517
- // Native calls take the host and port split out
518
- const hostPortRegex = /^http:\/\/([\w\d-.]+):(\d+)$/;
519
- const urlMatches = _url.match(hostPortRegex);
520
- if (!urlMatches) {
521
- throw new Error('firebase.auth().useEmulator() unable to parse host and port from URL');
522
- }
523
- const host = urlMatches[1];
524
- const port = parseInt(urlMatches[2], 10);
525
- this.native.useEmulator(host, port);
526
- return [host, port]; // undocumented return, useful for unit testing
527
- }
528
-
529
- getMultiFactorResolver(error) {
530
- return getMultiFactorResolver(this, error);
531
- }
532
-
533
- multiFactor(user) {
534
- if (user.userId !== this.currentUser.userId) {
535
- throw new Error('firebase.auth().multiFactor() only operates on currentUser');
536
- }
537
- return new MultiFactorUser(this, user);
538
- }
539
-
540
- getCustomAuthDomain() {
541
- return this.native.getCustomAuthDomain();
542
- }
543
- }
544
-
545
- // Apply password policy mixin to FirebaseAuthModule
546
- Object.assign(FirebaseAuthModule.prototype, PasswordPolicyMixin);
547
-
548
- // import { SDK_VERSION } from '@react-native-firebase/auth';
549
- export const SDK_VERSION = version;
550
-
551
- // import auth from '@react-native-firebase/auth';
552
- // auth().X(...);
553
- export default createModuleNamespace({
554
- statics,
555
- version,
556
- namespace,
557
- nativeModuleName,
558
- nativeEvents: ['auth_state_changed', 'auth_id_token_changed', 'phone_auth_state_changed'],
559
- hasMultiAppSupport: true,
560
- hasCustomUrlOrRegionSupport: false,
561
- ModuleClass: FirebaseAuthModule,
562
- });
563
-
564
- export * from './modular/index';
565
-
566
- // import auth, { firebase } from '@react-native-firebase/auth';
567
- // auth().X(...);
568
- // firebase.auth().X(...);
569
- export const firebase = getFirebaseRoot();
570
-
571
- // Register the interop module for non-native platforms.
572
- setReactNativeModule(nativeModuleName, fallBackModule);