@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
@@ -21,30 +21,42 @@ import {
21
21
  isUndefined,
22
22
  isBoolean,
23
23
  } from '@react-native-firebase/app/dist/module/common';
24
+ import type { IdTokenResult, UserInfo, UserMetadata } from './types/auth';
25
+ import type { FirebaseAuthTypes } from './types/namespaced';
26
+ import type { AuthInternal, NativeUserInternal } from './types/internal';
27
+
28
+ type AuthProviderWithObject = FirebaseAuthTypes.AuthProvider & {
29
+ toObject(): Record<string, unknown>;
30
+ };
24
31
 
25
32
  export default class User {
26
- constructor(auth, user) {
33
+ /** @internal */
34
+ readonly _auth: AuthInternal;
35
+ /** @internal */
36
+ readonly _user: NativeUserInternal;
37
+
38
+ constructor(auth: AuthInternal, user: NativeUserInternal) {
27
39
  this._auth = auth;
28
40
  this._user = user;
29
41
  }
30
42
 
31
- get displayName() {
43
+ get displayName(): string | null {
32
44
  return this._user.displayName || null;
33
45
  }
34
46
 
35
- get email() {
47
+ get email(): string | null {
36
48
  return this._user.email || null;
37
49
  }
38
50
 
39
- get emailVerified() {
51
+ get emailVerified(): boolean {
40
52
  return this._user.emailVerified || false;
41
53
  }
42
54
 
43
- get isAnonymous() {
55
+ get isAnonymous(): boolean {
44
56
  return this._user.isAnonymous || false;
45
57
  }
46
58
 
47
- get metadata() {
59
+ get metadata(): UserMetadata {
48
60
  const { metadata } = this._user;
49
61
 
50
62
  return {
@@ -53,148 +65,173 @@ export default class User {
53
65
  };
54
66
  }
55
67
 
56
- get multiFactor() {
68
+ get multiFactor(): FirebaseAuthTypes.MultiFactor | null {
57
69
  return this._user.multiFactor || null;
58
70
  }
59
71
 
60
- get phoneNumber() {
72
+ get phoneNumber(): string | null {
61
73
  return this._user.phoneNumber || null;
62
74
  }
63
75
 
64
- get tenantId() {
76
+ get tenantId(): string | null {
65
77
  return this._user.tenantId || null;
66
78
  }
67
79
 
68
- get photoURL() {
80
+ get photoURL(): string | null {
69
81
  return this._user.photoURL || null;
70
82
  }
71
83
 
72
- get providerData() {
73
- return this._user.providerData;
84
+ get providerData(): UserInfo[] {
85
+ return this._user.providerData.map(provider => ({
86
+ displayName: provider.displayName ?? null,
87
+ email: provider.email ?? null,
88
+ phoneNumber: provider.phoneNumber ?? null,
89
+ photoURL: provider.photoURL ?? null,
90
+ providerId: provider.providerId,
91
+ uid: provider.uid,
92
+ }));
74
93
  }
75
94
 
76
- get providerId() {
95
+ get providerId(): string {
77
96
  return this._user.providerId;
78
97
  }
79
98
 
80
- get uid() {
99
+ get uid(): string {
81
100
  return this._user.uid;
82
101
  }
83
102
 
84
- delete() {
103
+ delete(): Promise<void> {
85
104
  return this._auth.native.delete().then(() => {
86
- this._auth._setUser();
105
+ this._auth._setUser(null);
87
106
  });
88
107
  }
89
108
 
90
- getIdToken(forceRefresh = false) {
109
+ getIdToken(forceRefresh = false): Promise<string> {
91
110
  return this._auth.native.getIdToken(forceRefresh);
92
111
  }
93
112
 
94
- getIdTokenResult(forceRefresh = false) {
95
- return this._auth.native.getIdTokenResult(forceRefresh);
113
+ getIdTokenResult(forceRefresh = false): Promise<IdTokenResult> {
114
+ return this._auth.native.getIdTokenResult(forceRefresh) as Promise<IdTokenResult>;
96
115
  }
97
116
 
98
- linkWithCredential(credential) {
117
+ linkWithCredential(
118
+ credential: FirebaseAuthTypes.AuthCredential,
119
+ ): Promise<FirebaseAuthTypes.UserCredential> {
99
120
  return this._auth.native
100
121
  .linkWithCredential(credential.providerId, credential.token, credential.secret)
101
- .then(userCredential => this._auth._setUserCredential(userCredential));
122
+ .then(
123
+ userCredential =>
124
+ this._auth._setUserCredential(userCredential) as FirebaseAuthTypes.UserCredential,
125
+ );
102
126
  }
103
127
 
104
- linkWithPopup(provider) {
128
+ linkWithPopup(provider: AuthProviderWithObject): Promise<FirebaseAuthTypes.UserCredential> {
105
129
  // call through to linkWithRedirect for shared implementation
106
130
  return this.linkWithRedirect(provider);
107
131
  }
108
132
 
109
- linkWithRedirect(provider) {
133
+ linkWithRedirect(provider: AuthProviderWithObject): Promise<FirebaseAuthTypes.UserCredential> {
110
134
  return this._auth.native
111
135
  .linkWithProvider(provider.toObject())
112
- .then(userCredential => this._auth._setUserCredential(userCredential));
136
+ .then(
137
+ userCredential =>
138
+ this._auth._setUserCredential(userCredential) as FirebaseAuthTypes.UserCredential,
139
+ );
113
140
  }
114
141
 
115
- reauthenticateWithCredential(credential) {
142
+ reauthenticateWithCredential(
143
+ credential: FirebaseAuthTypes.AuthCredential,
144
+ ): Promise<FirebaseAuthTypes.UserCredential> {
116
145
  return this._auth.native
117
146
  .reauthenticateWithCredential(credential.providerId, credential.token, credential.secret)
118
- .then(userCredential => this._auth._setUserCredential(userCredential));
147
+ .then(
148
+ userCredential =>
149
+ this._auth._setUserCredential(userCredential) as FirebaseAuthTypes.UserCredential,
150
+ );
119
151
  }
120
152
 
121
- reauthenticateWithPopup(provider) {
153
+ reauthenticateWithPopup(
154
+ provider: AuthProviderWithObject,
155
+ ): Promise<FirebaseAuthTypes.UserCredential> {
122
156
  // call through to reauthenticateWithRedirect for shared implementation
123
- return this.reauthenticateWithRedirect(provider);
157
+ return this._auth.native
158
+ .reauthenticateWithProvider(provider.toObject())
159
+ .then(
160
+ userCredential =>
161
+ this._auth._setUserCredential(userCredential) as FirebaseAuthTypes.UserCredential,
162
+ );
124
163
  }
125
164
 
126
- reauthenticateWithRedirect(provider) {
165
+ reauthenticateWithRedirect(provider: AuthProviderWithObject): Promise<void> {
127
166
  return this._auth.native
128
167
  .reauthenticateWithProvider(provider.toObject())
129
- .then(userCredential => this._auth._setUserCredential(userCredential));
168
+ .then(userCredential => {
169
+ this._auth._setUserCredential(userCredential);
170
+ });
130
171
  }
131
172
 
132
- reload() {
173
+ reload(): Promise<void> {
133
174
  return this._auth.native.reload().then(user => {
134
175
  this._auth._setUser(user);
135
176
  });
136
177
  }
137
178
 
138
- sendEmailVerification(actionCodeSettings) {
179
+ sendEmailVerification(actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings): Promise<void> {
139
180
  if (isObject(actionCodeSettings)) {
140
- if (!isString(actionCodeSettings.url)) {
181
+ const settings = actionCodeSettings as FirebaseAuthTypes.ActionCodeSettings;
182
+
183
+ if (!isString(settings.url)) {
141
184
  throw new Error(
142
185
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.url' expected a string value.",
143
186
  );
144
187
  }
145
188
 
146
- if (!isUndefined(actionCodeSettings.linkDomain) && !isString(actionCodeSettings.linkDomain)) {
189
+ if (!isUndefined(settings.linkDomain) && !isString(settings.linkDomain)) {
147
190
  throw new Error(
148
191
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.linkDomain' expected a string value.",
149
192
  );
150
193
  }
151
194
 
152
- if (
153
- !isUndefined(actionCodeSettings.handleCodeInApp) &&
154
- !isBoolean(actionCodeSettings.handleCodeInApp)
155
- ) {
195
+ if (!isUndefined(settings.handleCodeInApp) && !isBoolean(settings.handleCodeInApp)) {
156
196
  throw new Error(
157
197
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.handleCodeInApp' expected a boolean value.",
158
198
  );
159
199
  }
160
200
 
161
- if (!isUndefined(actionCodeSettings.iOS)) {
162
- if (!isObject(actionCodeSettings.iOS)) {
201
+ if (!isUndefined(settings.iOS)) {
202
+ if (!isObject(settings.iOS)) {
163
203
  throw new Error(
164
204
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.iOS' expected an object value.",
165
205
  );
166
206
  }
167
- if (!isString(actionCodeSettings.iOS.bundleId)) {
207
+ if (!isString(settings.iOS.bundleId)) {
168
208
  throw new Error(
169
209
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.iOS.bundleId' expected a string value.",
170
210
  );
171
211
  }
172
212
  }
173
213
 
174
- if (!isUndefined(actionCodeSettings.android)) {
175
- if (!isObject(actionCodeSettings.android)) {
214
+ if (!isUndefined(settings.android)) {
215
+ if (!isObject(settings.android)) {
176
216
  throw new Error(
177
217
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.android' expected an object value.",
178
218
  );
179
219
  }
180
- if (!isString(actionCodeSettings.android.packageName)) {
220
+ if (!isString(settings.android.packageName)) {
181
221
  throw new Error(
182
222
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.android.packageName' expected a string value.",
183
223
  );
184
224
  }
185
225
 
186
- if (
187
- !isUndefined(actionCodeSettings.android.installApp) &&
188
- !isBoolean(actionCodeSettings.android.installApp)
189
- ) {
226
+ if (!isUndefined(settings.android.installApp) && !isBoolean(settings.android.installApp)) {
190
227
  throw new Error(
191
228
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.android.installApp' expected a boolean value.",
192
229
  );
193
230
  }
194
231
 
195
232
  if (
196
- !isUndefined(actionCodeSettings.android.minimumVersion) &&
197
- !isString(actionCodeSettings.android.minimumVersion)
233
+ !isUndefined(settings.android.minimumVersion) &&
234
+ !isString(settings.android.minimumVersion)
198
235
  ) {
199
236
  throw new Error(
200
237
  "firebase.auth.User.sendEmailVerification(*) 'actionCodeSettings.android.minimumVersion' expected a string value.",
@@ -204,31 +241,39 @@ export default class User {
204
241
  }
205
242
 
206
243
  return this._auth.native.sendEmailVerification(actionCodeSettings).then(user => {
207
- this._auth._setUser(user);
208
- });
244
+ this._auth._setUser(user);
245
+ });
209
246
  }
210
247
 
211
- toJSON() {
248
+ toJSON(): object {
212
249
  return Object.assign({}, this._user);
213
250
  }
214
251
 
215
- unlink(providerId) {
216
- return this._auth.native.unlink(providerId).then(user => this._auth._setUser(user));
252
+ unlink(providerId: string): Promise<FirebaseAuthTypes.User> {
253
+ return this._auth.native
254
+ .unlink(providerId)
255
+ .then(user => {
256
+ const updatedUser = this._auth._setUser(user);
257
+ if (!updatedUser) {
258
+ throw new Error('firebase.auth.User.unlink() returned no user after unlinking provider.');
259
+ }
260
+ return updatedUser;
261
+ });
217
262
  }
218
263
 
219
- updateEmail(email) {
264
+ updateEmail(email: string): Promise<void> {
220
265
  return this._auth.native.updateEmail(email).then(user => {
221
266
  this._auth._setUser(user);
222
267
  });
223
268
  }
224
269
 
225
- updatePassword(password) {
270
+ updatePassword(password: string): Promise<void> {
226
271
  return this._auth.native.updatePassword(password).then(user => {
227
272
  this._auth._setUser(user);
228
273
  });
229
274
  }
230
275
 
231
- updatePhoneNumber(credential) {
276
+ updatePhoneNumber(credential: FirebaseAuthTypes.AuthCredential): Promise<void> {
232
277
  return this._auth.native
233
278
  .updatePhoneNumber(credential.providerId, credential.token, credential.secret)
234
279
  .then(user => {
@@ -236,13 +281,16 @@ export default class User {
236
281
  });
237
282
  }
238
283
 
239
- updateProfile(updates) {
284
+ updateProfile(updates: FirebaseAuthTypes.UpdateProfile): Promise<void> {
240
285
  return this._auth.native.updateProfile(updates).then(user => {
241
286
  this._auth._setUser(user);
242
287
  });
243
288
  }
244
289
 
245
- verifyBeforeUpdateEmail(newEmail, actionCodeSettings) {
290
+ verifyBeforeUpdateEmail(
291
+ newEmail: string,
292
+ actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings,
293
+ ): Promise<void> {
246
294
  if (!isString(newEmail)) {
247
295
  throw new Error(
248
296
  "firebase.auth.User.verifyBeforeUpdateEmail(*) 'newEmail' expected a string value.",
@@ -250,64 +298,60 @@ export default class User {
250
298
  }
251
299
 
252
300
  if (isObject(actionCodeSettings)) {
253
- if (!isString(actionCodeSettings.url)) {
301
+ const settings = actionCodeSettings as FirebaseAuthTypes.ActionCodeSettings;
302
+
303
+ if (!isString(settings.url)) {
254
304
  throw new Error(
255
305
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.url' expected a string value.",
256
306
  );
257
307
  }
258
308
 
259
- if (!isUndefined(actionCodeSettings.linkDomain) && !isString(actionCodeSettings.linkDomain)) {
309
+ if (!isUndefined(settings.linkDomain) && !isString(settings.linkDomain)) {
260
310
  throw new Error(
261
311
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.linkDomain' expected a string value.",
262
312
  );
263
313
  }
264
314
 
265
- if (
266
- !isUndefined(actionCodeSettings.handleCodeInApp) &&
267
- !isBoolean(actionCodeSettings.handleCodeInApp)
268
- ) {
315
+ if (!isUndefined(settings.handleCodeInApp) && !isBoolean(settings.handleCodeInApp)) {
269
316
  throw new Error(
270
317
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.handleCodeInApp' expected a boolean value.",
271
318
  );
272
319
  }
273
320
 
274
- if (!isUndefined(actionCodeSettings.iOS)) {
275
- if (!isObject(actionCodeSettings.iOS)) {
321
+ if (!isUndefined(settings.iOS)) {
322
+ if (!isObject(settings.iOS)) {
276
323
  throw new Error(
277
324
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.iOS' expected an object value.",
278
325
  );
279
326
  }
280
- if (!isString(actionCodeSettings.iOS.bundleId)) {
327
+ if (!isString(settings.iOS.bundleId)) {
281
328
  throw new Error(
282
329
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.iOS.bundleId' expected a string value.",
283
330
  );
284
331
  }
285
332
  }
286
333
 
287
- if (!isUndefined(actionCodeSettings.android)) {
288
- if (!isObject(actionCodeSettings.android)) {
334
+ if (!isUndefined(settings.android)) {
335
+ if (!isObject(settings.android)) {
289
336
  throw new Error(
290
337
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.android' expected an object value.",
291
338
  );
292
339
  }
293
- if (!isString(actionCodeSettings.android.packageName)) {
340
+ if (!isString(settings.android.packageName)) {
294
341
  throw new Error(
295
342
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.android.packageName' expected a string value.",
296
343
  );
297
344
  }
298
345
 
299
- if (
300
- !isUndefined(actionCodeSettings.android.installApp) &&
301
- !isBoolean(actionCodeSettings.android.installApp)
302
- ) {
346
+ if (!isUndefined(settings.android.installApp) && !isBoolean(settings.android.installApp)) {
303
347
  throw new Error(
304
348
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.android.installApp' expected a boolean value.",
305
349
  );
306
350
  }
307
351
 
308
352
  if (
309
- !isUndefined(actionCodeSettings.android.minimumVersion) &&
310
- !isString(actionCodeSettings.android.minimumVersion)
353
+ !isUndefined(settings.android.minimumVersion) &&
354
+ !isString(settings.android.minimumVersion)
311
355
  ) {
312
356
  throw new Error(
313
357
  "firebase.auth.User.verifyBeforeUpdateEmail(_, *) 'actionCodeSettings.android.minimumVersion' expected a string value.",
@@ -317,27 +361,27 @@ export default class User {
317
361
  }
318
362
 
319
363
  return this._auth.native.verifyBeforeUpdateEmail(newEmail, actionCodeSettings).then(user => {
320
- this._auth._setUser(user);
321
- });
364
+ this._auth._setUser(user);
365
+ });
322
366
  }
323
367
 
324
368
  /**
325
369
  * KNOWN UNSUPPORTED METHODS
326
370
  */
327
371
 
328
- linkWithPhoneNumber() {
372
+ linkWithPhoneNumber(): never {
329
373
  throw new Error(
330
374
  'firebase.auth.User.linkWithPhoneNumber() is unsupported by the native Firebase SDKs.',
331
375
  );
332
376
  }
333
377
 
334
- reauthenticateWithPhoneNumber() {
378
+ reauthenticateWithPhoneNumber(): never {
335
379
  throw new Error(
336
380
  'firebase.auth.User.reauthenticateWithPhoneNumber() is unsupported by the native Firebase SDKs.',
337
381
  );
338
382
  }
339
383
 
340
- get refreshToken() {
384
+ get refreshToken(): never {
341
385
  throw new Error('firebase.auth.User.refreshToken is unsupported by the native Firebase SDKs.');
342
386
  }
343
387
  }
@@ -0,0 +1,55 @@
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
+ export const ActionCodeOperation = {
19
+ EMAIL_SIGNIN: 'EMAIL_SIGNIN',
20
+ PASSWORD_RESET: 'PASSWORD_RESET',
21
+ RECOVER_EMAIL: 'RECOVER_EMAIL',
22
+ REVERT_SECOND_FACTOR_ADDITION: 'REVERT_SECOND_FACTOR_ADDITION',
23
+ VERIFY_AND_CHANGE_EMAIL: 'VERIFY_AND_CHANGE_EMAIL',
24
+ VERIFY_EMAIL: 'VERIFY_EMAIL',
25
+ } as const;
26
+
27
+ export const FactorId = {
28
+ PHONE: 'phone',
29
+ TOTP: 'totp',
30
+ } as const;
31
+
32
+ export const OperationType = {
33
+ LINK: 'link',
34
+ REAUTHENTICATE: 'reauthenticate',
35
+ SIGN_IN: 'signIn',
36
+ } as const;
37
+
38
+ export const ProviderId = {
39
+ FACEBOOK: 'facebook.com',
40
+ GITHUB: 'github.com',
41
+ GOOGLE: 'google.com',
42
+ PASSWORD: 'password',
43
+ PHONE: 'phone',
44
+ TWITTER: 'twitter.com',
45
+ } as const;
46
+
47
+ export const SignInMethod = {
48
+ EMAIL_LINK: 'emailLink',
49
+ EMAIL_PASSWORD: 'password',
50
+ FACEBOOK: 'facebook.com',
51
+ GITHUB: 'github.com',
52
+ GOOGLE: 'google.com',
53
+ PHONE: 'phone',
54
+ TWITTER: 'twitter.com',
55
+ } as const;
@@ -0,0 +1,55 @@
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
+ export function parseCredentialJSON(json: object | string): object | null {
19
+ if (typeof json === 'string') {
20
+ try {
21
+ return JSON.parse(json) as object;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ if (json === null || Array.isArray(json)) {
28
+ return null;
29
+ }
30
+
31
+ return json;
32
+ }
33
+
34
+ export class AuthCredential {
35
+ readonly providerId: string;
36
+ readonly signInMethod: string;
37
+ /** @internal RNFB native bridge token slot. */
38
+ readonly token: string;
39
+ /** @internal RNFB native bridge secret slot. */
40
+ readonly secret: string;
41
+
42
+ constructor(providerId: string, signInMethod: string, token: string, secret: string) {
43
+ this.providerId = providerId;
44
+ this.signInMethod = signInMethod;
45
+ this.token = token;
46
+ this.secret = secret;
47
+ }
48
+
49
+ toJSON(): object {
50
+ return {
51
+ providerId: this.providerId,
52
+ signInMethod: this.signInMethod,
53
+ };
54
+ }
55
+ }
@@ -0,0 +1,70 @@
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 { AuthCredential, parseCredentialJSON } from './AuthCredential';
19
+
20
+ type EmailCredentialJSON = {
21
+ email?: string;
22
+ password?: string;
23
+ signInMethod?: string;
24
+ tenantId?: string | null;
25
+ };
26
+
27
+ export class EmailAuthCredential extends AuthCredential {
28
+ constructor(
29
+ signInMethod: 'password' | 'emailLink',
30
+ email: string,
31
+ password: string,
32
+ ) {
33
+ super(signInMethod, signInMethod, email, password);
34
+ }
35
+
36
+ toJSON(): object {
37
+ return {
38
+ email: this.token,
39
+ password: this.secret,
40
+ signInMethod: this.signInMethod,
41
+ tenantId: null,
42
+ };
43
+ }
44
+
45
+ static fromJSON(json: object | string): EmailAuthCredential | null {
46
+ const parsed = parseCredentialJSON(json) as EmailCredentialJSON | null;
47
+ if (!parsed) {
48
+ return null;
49
+ }
50
+
51
+ const signInMethod = parsed.signInMethod;
52
+ if (signInMethod !== 'password' && signInMethod !== 'emailLink') {
53
+ return null;
54
+ }
55
+
56
+ if (typeof parsed.email !== 'string' || typeof parsed.password !== 'string') {
57
+ return null;
58
+ }
59
+
60
+ return new EmailAuthCredential(signInMethod, parsed.email, parsed.password);
61
+ }
62
+ }
63
+
64
+ export function createEmailAuthCredential(
65
+ email: string,
66
+ password: string,
67
+ signInMethod: 'password' | 'emailLink',
68
+ ): EmailAuthCredential {
69
+ return new EmailAuthCredential(signInMethod, email, password);
70
+ }