@react-native-firebase/auth 24.1.1 → 25.0.1
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.
- package/CHANGELOG.md +16 -0
- package/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +16 -4
- package/dist/module/ActionCodeURL.js +140 -0
- package/dist/module/ActionCodeURL.js.map +1 -0
- package/{lib → dist/module}/ConfirmationResult.js +4 -5
- package/dist/module/ConfirmationResult.js.map +1 -0
- package/{lib → dist/module}/MultiFactorResolver.js +14 -5
- package/dist/module/MultiFactorResolver.js.map +1 -0
- package/{lib → dist/module}/PhoneAuthListener.js +52 -75
- package/dist/module/PhoneAuthListener.js.map +1 -0
- package/dist/module/PhoneAuthState.js +25 -0
- package/dist/module/PhoneAuthState.js.map +1 -0
- package/dist/module/PhoneMultiFactorGenerator.js +39 -0
- package/dist/module/PhoneMultiFactorGenerator.js.map +1 -0
- package/{lib → dist/module}/Settings.js +3 -7
- package/dist/module/Settings.js.map +1 -0
- package/{lib → dist/module}/TotpMultiFactorGenerator.js +20 -15
- package/dist/module/TotpMultiFactorGenerator.js.map +1 -0
- package/{lib → dist/module}/TotpSecret.js +7 -5
- package/dist/module/TotpSecret.js.map +1 -0
- package/dist/module/User.js +245 -0
- package/dist/module/User.js.map +1 -0
- package/dist/module/constants.js +54 -0
- package/dist/module/constants.js.map +1 -0
- package/dist/module/credentials/AuthCredential.js +51 -0
- package/dist/module/credentials/AuthCredential.js.map +1 -0
- package/dist/module/credentials/EmailAuthCredential.js +51 -0
- package/dist/module/credentials/EmailAuthCredential.js.map +1 -0
- package/dist/module/credentials/OAuthCredential.js +84 -0
- package/dist/module/credentials/OAuthCredential.js.map +1 -0
- package/dist/module/credentials/PhoneAuthCredential.js +50 -0
- package/dist/module/credentials/PhoneAuthCredential.js.map +1 -0
- package/{lib/providers/GoogleAuthProvider.js → dist/module/credentials/index.js} +7 -19
- package/dist/module/credentials/index.js.map +1 -0
- package/{lib → dist/module}/getMultiFactorResolver.js +5 -8
- package/dist/module/getMultiFactorResolver.js.map +1 -0
- package/{lib/providers/FacebookAuthProvider.js → dist/module/index.js} +11 -18
- package/dist/module/index.js.map +1 -0
- package/dist/module/modular.js +793 -0
- package/dist/module/modular.js.map +1 -0
- package/{lib → dist/module}/multiFactor.js +16 -14
- package/dist/module/multiFactor.js.map +1 -0
- package/dist/module/namespaced.js +522 -0
- package/dist/module/namespaced.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/password-policy/PasswordPolicyImpl.js +103 -0
- package/dist/module/password-policy/PasswordPolicyImpl.js.map +1 -0
- package/{lib → dist/module}/password-policy/PasswordPolicyMixin.js +14 -16
- package/dist/module/password-policy/PasswordPolicyMixin.js.map +1 -0
- package/{lib → dist/module}/password-policy/passwordPolicyApi.js +18 -12
- package/dist/module/password-policy/passwordPolicyApi.js.map +1 -0
- package/{lib → dist/module}/providers/AppleAuthProvider.js +14 -7
- package/dist/module/providers/AppleAuthProvider.js.map +1 -0
- package/{lib → dist/module}/providers/EmailAuthProvider.js +10 -25
- package/dist/module/providers/EmailAuthProvider.js.map +1 -0
- package/dist/module/providers/FacebookAuthProvider.js +56 -0
- package/dist/module/providers/FacebookAuthProvider.js.map +1 -0
- package/dist/module/providers/GithubAuthProvider.js +49 -0
- package/dist/module/providers/GithubAuthProvider.js.map +1 -0
- package/dist/module/providers/GoogleAuthProvider.js +57 -0
- package/dist/module/providers/GoogleAuthProvider.js.map +1 -0
- package/dist/module/providers/OAuthProvider.js +116 -0
- package/dist/module/providers/OAuthProvider.js.map +1 -0
- package/{lib → dist/module}/providers/OIDCAuthProvider.js +15 -7
- package/dist/module/providers/OIDCAuthProvider.js.map +1 -0
- package/dist/module/providers/PhoneAuthProvider.js +87 -0
- package/dist/module/providers/PhoneAuthProvider.js.map +1 -0
- package/dist/module/providers/TwitterAuthProvider.js +50 -0
- package/dist/module/providers/TwitterAuthProvider.js.map +1 -0
- package/dist/module/types/auth.js +43 -0
- package/dist/module/types/auth.js.map +1 -0
- package/dist/module/types/internal.js +4 -0
- package/dist/module/types/internal.js.map +1 -0
- package/dist/module/types/namespaced.js +62 -0
- package/dist/module/types/namespaced.js.map +1 -0
- package/dist/module/version.js +5 -0
- package/dist/module/version.js.map +1 -0
- package/dist/module/web/RNFBAuthModule.android.js +5 -0
- package/dist/module/web/RNFBAuthModule.android.js.map +1 -0
- package/dist/module/web/RNFBAuthModule.ios.js +5 -0
- package/dist/module/web/RNFBAuthModule.ios.js.map +1 -0
- package/{lib → dist/module}/web/RNFBAuthModule.js +104 -321
- package/dist/module/web/RNFBAuthModule.js.map +1 -0
- package/dist/typescript/lib/ActionCodeURL.d.ts +41 -0
- package/dist/typescript/lib/ActionCodeURL.d.ts.map +1 -0
- package/dist/typescript/lib/ConfirmationResult.d.ts +10 -0
- package/dist/typescript/lib/ConfirmationResult.d.ts.map +1 -0
- package/dist/typescript/lib/MultiFactorResolver.d.ts +24 -0
- package/dist/typescript/lib/MultiFactorResolver.d.ts.map +1 -0
- package/dist/typescript/lib/PhoneAuthListener.d.ts +34 -0
- package/dist/typescript/lib/PhoneAuthListener.d.ts.map +1 -0
- package/dist/typescript/lib/PhoneAuthState.d.ts +7 -0
- package/dist/typescript/lib/PhoneAuthState.d.ts.map +1 -0
- package/dist/typescript/lib/PhoneMultiFactorGenerator.d.ts +7 -0
- package/dist/typescript/lib/PhoneMultiFactorGenerator.d.ts.map +1 -0
- package/dist/typescript/lib/Settings.d.ts +13 -0
- package/dist/typescript/lib/Settings.d.ts.map +1 -0
- package/dist/typescript/lib/TotpMultiFactorGenerator.d.ts +11 -0
- package/dist/typescript/lib/TotpMultiFactorGenerator.d.ts.map +1 -0
- package/dist/typescript/lib/TotpSecret.d.ts +33 -0
- package/dist/typescript/lib/TotpSecret.d.ts.map +1 -0
- package/dist/typescript/lib/User.d.ts +51 -0
- package/dist/typescript/lib/User.d.ts.map +1 -0
- package/dist/typescript/lib/constants.d.ts +35 -0
- package/dist/typescript/lib/constants.d.ts.map +1 -0
- package/dist/typescript/lib/credentials/AuthCredential.d.ts +12 -0
- package/dist/typescript/lib/credentials/AuthCredential.d.ts.map +1 -0
- package/dist/typescript/lib/credentials/EmailAuthCredential.d.ts +8 -0
- package/dist/typescript/lib/credentials/EmailAuthCredential.d.ts.map +1 -0
- package/dist/typescript/lib/credentials/OAuthCredential.d.ts +22 -0
- package/dist/typescript/lib/credentials/OAuthCredential.d.ts.map +1 -0
- package/dist/typescript/lib/credentials/PhoneAuthCredential.d.ts +8 -0
- package/dist/typescript/lib/credentials/PhoneAuthCredential.d.ts.map +1 -0
- package/dist/typescript/lib/credentials/index.d.ts +5 -0
- package/dist/typescript/lib/credentials/index.d.ts.map +1 -0
- package/dist/typescript/lib/getMultiFactorResolver.d.ts +19 -0
- package/dist/typescript/lib/getMultiFactorResolver.d.ts.map +1 -0
- package/dist/typescript/lib/index.d.ts +8 -0
- package/dist/typescript/lib/index.d.ts.map +1 -0
- package/dist/typescript/lib/modular.d.ts +370 -0
- package/dist/typescript/lib/modular.d.ts.map +1 -0
- package/dist/typescript/lib/multiFactor.d.ts +26 -0
- package/dist/typescript/lib/multiFactor.d.ts.map +1 -0
- package/dist/typescript/lib/namespaced.d.ts +12 -0
- package/dist/typescript/lib/namespaced.d.ts.map +1 -0
- package/dist/typescript/lib/password-policy/PasswordPolicyImpl.d.ts +19 -0
- package/dist/typescript/lib/password-policy/PasswordPolicyImpl.d.ts.map +1 -0
- package/dist/typescript/lib/password-policy/PasswordPolicyMixin.d.ts +11 -0
- package/dist/typescript/lib/password-policy/PasswordPolicyMixin.d.ts.map +1 -0
- package/dist/typescript/lib/password-policy/passwordPolicyApi.d.ts +10 -0
- package/dist/typescript/lib/password-policy/passwordPolicyApi.d.ts.map +1 -0
- package/dist/typescript/lib/providers/AppleAuthProvider.d.ts +16 -0
- package/dist/typescript/lib/providers/AppleAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/EmailAuthProvider.d.ts +11 -0
- package/dist/typescript/lib/providers/EmailAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/FacebookAuthProvider.d.ts +19 -0
- package/dist/typescript/lib/providers/FacebookAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/GithubAuthProvider.d.ts +15 -0
- package/dist/typescript/lib/providers/GithubAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/GoogleAuthProvider.d.ts +21 -0
- package/dist/typescript/lib/providers/GoogleAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/OAuthProvider.d.ts +33 -0
- package/dist/typescript/lib/providers/OAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/OIDCAuthProvider.d.ts +16 -0
- package/dist/typescript/lib/providers/OIDCAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/PhoneAuthProvider.d.ts +16 -0
- package/dist/typescript/lib/providers/PhoneAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/providers/TwitterAuthProvider.d.ts +15 -0
- package/dist/typescript/lib/providers/TwitterAuthProvider.d.ts.map +1 -0
- package/dist/typescript/lib/types/auth.d.ts +305 -0
- package/dist/typescript/lib/types/auth.d.ts.map +1 -0
- package/dist/typescript/lib/types/internal.d.ts +293 -0
- package/dist/typescript/lib/types/internal.d.ts.map +1 -0
- package/dist/typescript/lib/types/namespaced.d.ts +2185 -0
- package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
- package/dist/typescript/lib/version.d.ts +2 -0
- package/dist/typescript/lib/version.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBAuthModule.android.d.ts +3 -0
- package/dist/typescript/lib/web/RNFBAuthModule.android.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBAuthModule.d.ts +406 -0
- package/dist/typescript/lib/web/RNFBAuthModule.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBAuthModule.ios.d.ts +3 -0
- package/dist/typescript/lib/web/RNFBAuthModule.ios.d.ts.map +1 -0
- package/dist/typescript/package.json +1 -0
- package/ios/RNFBAuth/RNFBAuthModule.m +4 -2
- package/lib/ActionCodeURL.ts +174 -0
- package/lib/ConfirmationResult.ts +42 -0
- package/lib/MultiFactorResolver.ts +51 -0
- package/lib/PhoneAuthListener.ts +312 -0
- package/lib/PhoneAuthState.ts +22 -0
- package/lib/{PhoneMultiFactorGenerator.js → PhoneMultiFactorGenerator.ts} +8 -2
- package/lib/Settings.ts +59 -0
- package/lib/TotpMultiFactorGenerator.ts +78 -0
- package/lib/TotpSecret.ts +71 -0
- package/lib/{User.js → User.ts} +127 -83
- package/lib/constants.ts +55 -0
- package/lib/credentials/AuthCredential.ts +55 -0
- package/lib/credentials/EmailAuthCredential.ts +70 -0
- package/lib/credentials/OAuthCredential.ts +113 -0
- package/lib/credentials/PhoneAuthCredential.ts +66 -0
- package/lib/{providers/GithubAuthProvider.js → credentials/index.ts} +4 -19
- package/lib/getMultiFactorResolver.ts +40 -0
- package/lib/{providers/TwitterAuthProvider.js → index.ts} +14 -19
- package/lib/modular.ts +1172 -0
- package/lib/multiFactor.ts +83 -0
- package/lib/namespaced.ts +846 -0
- package/lib/password-policy/{PasswordPolicyImpl.js → PasswordPolicyImpl.ts} +37 -19
- package/lib/password-policy/PasswordPolicyMixin.ts +83 -0
- package/lib/password-policy/passwordPolicyApi.ts +60 -0
- package/lib/providers/AppleAuthProvider.ts +44 -0
- package/lib/providers/EmailAuthProvider.ts +42 -0
- package/lib/providers/FacebookAuthProvider.ts +58 -0
- package/lib/providers/GithubAuthProvider.ts +51 -0
- package/lib/providers/GoogleAuthProvider.ts +60 -0
- package/lib/providers/OAuthProvider.ts +150 -0
- package/lib/providers/OIDCAuthProvider.ts +49 -0
- package/lib/providers/PhoneAuthProvider.ts +161 -0
- package/lib/providers/TwitterAuthProvider.ts +52 -0
- package/lib/types/auth.ts +393 -0
- package/lib/types/internal.ts +475 -0
- package/lib/{index.d.ts → types/namespaced.ts} +52 -41
- package/lib/version.ts +2 -0
- package/lib/web/RNFBAuthModule.ts +1359 -0
- package/package.json +41 -9
- package/plugin/tsconfig.tsbuildinfo +1 -1
- package/tsconfig.json +26 -0
- package/tsdoc.json +22 -0
- package/typedoc.json +9 -2
- package/lib/index.js +0 -572
- package/lib/modular/index.d.ts +0 -801
- package/lib/modular/index.js +0 -651
- package/lib/providers/OAuthProvider.js +0 -70
- package/lib/providers/PhoneAuthProvider.js +0 -52
- package/lib/version.js +0 -2
- /package/lib/web/{RNFBAuthModule.android.js → RNFBAuthModule.android.ts} +0 -0
- /package/lib/web/{RNFBAuthModule.ios.js → RNFBAuthModule.ios.ts} +0 -0
package/lib/modular.ts
ADDED
|
@@ -0,0 +1,1172 @@
|
|
|
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
|
+
import { getApp } from '@react-native-firebase/app';
|
|
18
|
+
import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
|
|
19
|
+
import {
|
|
20
|
+
ActionCodeOperation,
|
|
21
|
+
FactorId,
|
|
22
|
+
OperationType,
|
|
23
|
+
ProviderId,
|
|
24
|
+
SignInMethod,
|
|
25
|
+
} from './constants';
|
|
26
|
+
import PhoneMultiFactorGenerator from './PhoneMultiFactorGenerator';
|
|
27
|
+
import { PhoneAuthState } from './PhoneAuthState';
|
|
28
|
+
import TotpMultiFactorGenerator from './TotpMultiFactorGenerator';
|
|
29
|
+
import { TotpSecret } from './TotpSecret';
|
|
30
|
+
import { MultiFactorUser as MultiFactorUserModule } from './multiFactor';
|
|
31
|
+
import AppleAuthProvider from './providers/AppleAuthProvider';
|
|
32
|
+
import EmailAuthProvider from './providers/EmailAuthProvider';
|
|
33
|
+
import FacebookAuthProvider from './providers/FacebookAuthProvider';
|
|
34
|
+
import GithubAuthProvider from './providers/GithubAuthProvider';
|
|
35
|
+
import GoogleAuthProvider from './providers/GoogleAuthProvider';
|
|
36
|
+
import OAuthProvider from './providers/OAuthProvider';
|
|
37
|
+
import OIDCAuthProvider from './providers/OIDCAuthProvider';
|
|
38
|
+
import PhoneAuthProvider from './providers/PhoneAuthProvider';
|
|
39
|
+
import TwitterAuthProvider from './providers/TwitterAuthProvider';
|
|
40
|
+
import type { FirebaseApp } from '@react-native-firebase/app';
|
|
41
|
+
import { ActionCodeURL } from './ActionCodeURL';
|
|
42
|
+
import type {
|
|
43
|
+
ActionCodeInfo,
|
|
44
|
+
ActionCodeSettings,
|
|
45
|
+
AdditionalUserInfo,
|
|
46
|
+
AdditionalUserInfoNative,
|
|
47
|
+
ApplicationVerifier,
|
|
48
|
+
Auth,
|
|
49
|
+
AuthCredential,
|
|
50
|
+
AuthProvider,
|
|
51
|
+
CompleteFn,
|
|
52
|
+
ConfirmationResult,
|
|
53
|
+
Dependencies,
|
|
54
|
+
ErrorFn,
|
|
55
|
+
IdTokenResult,
|
|
56
|
+
MultiFactorError,
|
|
57
|
+
MultiFactorInfo,
|
|
58
|
+
MultiFactorResolver,
|
|
59
|
+
MultiFactorUser,
|
|
60
|
+
NextOrObserver,
|
|
61
|
+
PasswordValidationStatus,
|
|
62
|
+
Persistence,
|
|
63
|
+
PhoneAuthCredential,
|
|
64
|
+
PhoneAuthListener,
|
|
65
|
+
PhoneMultiFactorInfo,
|
|
66
|
+
PopupRedirectResolver,
|
|
67
|
+
TotpMultiFactorInfo,
|
|
68
|
+
Unsubscribe,
|
|
69
|
+
User,
|
|
70
|
+
UserCredential,
|
|
71
|
+
} from './types/auth';
|
|
72
|
+
import type {
|
|
73
|
+
ActionCodeInfoResultInternal,
|
|
74
|
+
AppWithAuthInternal,
|
|
75
|
+
AuthInternal,
|
|
76
|
+
AuthListenerCallbackInternal,
|
|
77
|
+
AuthProviderWithObjectInternal,
|
|
78
|
+
ConfirmationResultResultInternal,
|
|
79
|
+
MultiFactorResolverResultInternal,
|
|
80
|
+
MultiFactorUserResultInternal,
|
|
81
|
+
MultiFactorUserSourceInternal,
|
|
82
|
+
UserCredentialResultInternal,
|
|
83
|
+
UserInternal,
|
|
84
|
+
WithAuthDeprecationArg,
|
|
85
|
+
} from './types/internal';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Modular Auth API for React Native Firebase.
|
|
89
|
+
*
|
|
90
|
+
* Most exports mirror the [firebase-js-sdk modular Auth API](https://firebase.google.com/docs/reference/js/auth).
|
|
91
|
+
* Remarks on individual symbols call out React Native-specific behavior, unsupported
|
|
92
|
+
* web-only APIs, and return-type differences.
|
|
93
|
+
*
|
|
94
|
+
* @packageDocumentation
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
type AnyFn = (...args: any[]) => any;
|
|
98
|
+
|
|
99
|
+
type UserModuleInternal = UserInternal;
|
|
100
|
+
type MultiFactorInfoInternal =
|
|
101
|
+
| MultiFactorInfo
|
|
102
|
+
| MultiFactorResolverResultInternal['hints'][number];
|
|
103
|
+
|
|
104
|
+
export {
|
|
105
|
+
ActionCodeOperation,
|
|
106
|
+
FactorId,
|
|
107
|
+
OperationType,
|
|
108
|
+
ProviderId,
|
|
109
|
+
SignInMethod,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function appWithAuth(app?: FirebaseApp): AppWithAuthInternal {
|
|
113
|
+
return (app ? getApp(app.name) : getApp()) as unknown as AppWithAuthInternal;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function getAuthInternal(auth: Auth): AuthInternal {
|
|
117
|
+
return auth as unknown as AuthInternal;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function getUserInternal(user: User): UserModuleInternal {
|
|
121
|
+
return user as unknown as UserModuleInternal;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type AdditionalUserInfoSource = {
|
|
125
|
+
isNewUser?: boolean;
|
|
126
|
+
profile?: Record<string, unknown> | null;
|
|
127
|
+
providerId?: string | null;
|
|
128
|
+
username?: string | null;
|
|
129
|
+
} & Record<string, unknown>;
|
|
130
|
+
|
|
131
|
+
function normalizeAdditionalUserInfo(
|
|
132
|
+
info: AdditionalUserInfoSource,
|
|
133
|
+
): AdditionalUserInfoNative {
|
|
134
|
+
return {
|
|
135
|
+
...info,
|
|
136
|
+
isNewUser: Boolean(info.isNewUser),
|
|
137
|
+
profile: info.profile ?? null,
|
|
138
|
+
providerId: info.providerId ?? null,
|
|
139
|
+
username: info.username ?? null,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function normalizeUserCredential(
|
|
144
|
+
userCredential: UserCredentialResultInternal,
|
|
145
|
+
overrides: Partial<Pick<UserCredential, 'operationType' | 'providerId'>> = {},
|
|
146
|
+
): UserCredential {
|
|
147
|
+
const normalizedUserCredential: UserCredential = {
|
|
148
|
+
user: userCredential.user as unknown as User,
|
|
149
|
+
providerId:
|
|
150
|
+
overrides.providerId ??
|
|
151
|
+
userCredential.providerId ??
|
|
152
|
+
userCredential.additionalUserInfo?.providerId ??
|
|
153
|
+
null,
|
|
154
|
+
operationType: overrides.operationType ?? userCredential.operationType ?? OperationType.SIGN_IN,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
if (userCredential.additionalUserInfo) {
|
|
158
|
+
normalizedUserCredential.additionalUserInfo = normalizeAdditionalUserInfo(
|
|
159
|
+
userCredential.additionalUserInfo as AdditionalUserInfoSource,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return normalizedUserCredential;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function normalizeMultiFactorInfo(info: MultiFactorInfoInternal): MultiFactorInfo {
|
|
167
|
+
const normalizedInfo = {
|
|
168
|
+
uid: info.uid,
|
|
169
|
+
displayName: info.displayName ?? null,
|
|
170
|
+
enrollmentTime: info.enrollmentTime,
|
|
171
|
+
factorId: info.factorId,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
if ('phoneNumber' in info) {
|
|
175
|
+
return {
|
|
176
|
+
...normalizedInfo,
|
|
177
|
+
phoneNumber: info.phoneNumber,
|
|
178
|
+
} as PhoneMultiFactorInfo;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return normalizedInfo as TotpMultiFactorInfo;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function normalizeActionCodeInfo(actionCodeInfo: ActionCodeInfoResultInternal): ActionCodeInfo {
|
|
185
|
+
const data = actionCodeInfo.data ?? {};
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
data: {
|
|
189
|
+
email: data.email ?? null,
|
|
190
|
+
multiFactorInfo:
|
|
191
|
+
'multiFactorInfo' in data && data.multiFactorInfo
|
|
192
|
+
? normalizeMultiFactorInfo(data.multiFactorInfo)
|
|
193
|
+
: null,
|
|
194
|
+
previousEmail:
|
|
195
|
+
('previousEmail' in data ? data.previousEmail : undefined) ??
|
|
196
|
+
('fromEmail' in data ? data.fromEmail : undefined) ??
|
|
197
|
+
null,
|
|
198
|
+
},
|
|
199
|
+
operation: actionCodeInfo.operation as ActionCodeInfo['operation'],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function normalizeConfirmationResult(
|
|
204
|
+
confirmationResult: ConfirmationResultResultInternal,
|
|
205
|
+
): ConfirmationResult {
|
|
206
|
+
if (!confirmationResult.verificationId) {
|
|
207
|
+
throw new Error('signInWithPhoneNumber() did not return a verificationId.');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
verificationId: confirmationResult.verificationId,
|
|
212
|
+
async confirm(verificationCode: string) {
|
|
213
|
+
const userCredential = await confirmationResult.confirm(verificationCode);
|
|
214
|
+
|
|
215
|
+
if (!userCredential) {
|
|
216
|
+
throw new Error('signInWithPhoneNumber().confirm() returned no user credential.');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return normalizeUserCredential(userCredential, {
|
|
220
|
+
providerId: ProviderId.PHONE,
|
|
221
|
+
operationType: OperationType.SIGN_IN,
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function normalizeMultiFactorResolver(
|
|
228
|
+
resolver: MultiFactorResolverResultInternal,
|
|
229
|
+
): MultiFactorResolver {
|
|
230
|
+
return {
|
|
231
|
+
hints: resolver.hints.map(normalizeMultiFactorInfo),
|
|
232
|
+
session: resolver.session,
|
|
233
|
+
async resolveSignIn(assertion) {
|
|
234
|
+
return normalizeUserCredential(await resolver.resolveSignIn(assertion), {
|
|
235
|
+
providerId: assertion.factorId === FactorId.PHONE ? ProviderId.PHONE : null,
|
|
236
|
+
operationType: OperationType.SIGN_IN,
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function normalizeMultiFactorUser(multiFactorUser: MultiFactorUserResultInternal): MultiFactorUser {
|
|
243
|
+
return {
|
|
244
|
+
enrolledFactors: multiFactorUser.enrolledFactors.map(normalizeMultiFactorInfo),
|
|
245
|
+
getSession: () => multiFactorUser.getSession(),
|
|
246
|
+
enroll: (assertion, displayName) => multiFactorUser.enroll(assertion, displayName),
|
|
247
|
+
unenroll: option =>
|
|
248
|
+
multiFactorUser.unenroll(
|
|
249
|
+
option as Parameters<MultiFactorUserResultInternal['unenroll']>[0],
|
|
250
|
+
),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { ActionCodeURL } from './ActionCodeURL';
|
|
255
|
+
export {
|
|
256
|
+
AuthCredential,
|
|
257
|
+
EmailAuthCredential,
|
|
258
|
+
OAuthCredential,
|
|
259
|
+
PhoneAuthCredential,
|
|
260
|
+
} from './credentials';
|
|
261
|
+
|
|
262
|
+
export {
|
|
263
|
+
AppleAuthProvider,
|
|
264
|
+
EmailAuthProvider,
|
|
265
|
+
FacebookAuthProvider,
|
|
266
|
+
GithubAuthProvider,
|
|
267
|
+
GoogleAuthProvider,
|
|
268
|
+
OAuthProvider,
|
|
269
|
+
OIDCAuthProvider,
|
|
270
|
+
PhoneAuthProvider,
|
|
271
|
+
PhoneAuthState,
|
|
272
|
+
PhoneMultiFactorGenerator,
|
|
273
|
+
TotpMultiFactorGenerator,
|
|
274
|
+
TotpSecret,
|
|
275
|
+
TwitterAuthProvider,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
function normalizeAuthListener(
|
|
279
|
+
nextOrObserver: NextOrObserver<User>,
|
|
280
|
+
): AuthListenerCallbackInternal | { next: AuthListenerCallbackInternal } {
|
|
281
|
+
if (typeof nextOrObserver === 'function') {
|
|
282
|
+
return nextOrObserver as AuthListenerCallbackInternal;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (typeof nextOrObserver.next !== 'function') {
|
|
286
|
+
return { next: () => {} };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return nextOrObserver as { next: AuthListenerCallbackInternal };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function callAuthMethod<F extends AnyFn>(
|
|
293
|
+
auth: AuthInternal,
|
|
294
|
+
method: F,
|
|
295
|
+
...args: Parameters<F>
|
|
296
|
+
): ReturnType<F> {
|
|
297
|
+
return (method as unknown as WithAuthDeprecationArg<F>).call(
|
|
298
|
+
auth,
|
|
299
|
+
...args,
|
|
300
|
+
MODULAR_DEPRECATION_ARG,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function callUserMethod<F extends AnyFn>(
|
|
305
|
+
user: UserModuleInternal,
|
|
306
|
+
method: F,
|
|
307
|
+
...args: Parameters<F>
|
|
308
|
+
): ReturnType<F> {
|
|
309
|
+
return (method as unknown as WithAuthDeprecationArg<F>).call(
|
|
310
|
+
user,
|
|
311
|
+
...args,
|
|
312
|
+
MODULAR_DEPRECATION_ARG,
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Returns the Auth instance associated with the provided FirebaseApp.
|
|
318
|
+
*
|
|
319
|
+
* @param app - The Firebase app instance. Defaults to the default app.
|
|
320
|
+
*/
|
|
321
|
+
export function getAuth(app?: FirebaseApp): Auth {
|
|
322
|
+
// Keep getAuth() on the shared namespaced instance; method wrappers add the modular sentinel.
|
|
323
|
+
return appWithAuth(app).auth();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* This function allows more control over the Auth instance than getAuth().
|
|
328
|
+
*
|
|
329
|
+
* @param app - The Firebase app to initialize Auth for.
|
|
330
|
+
* @param _deps - Optional firebase-js-sdk dependency bag.
|
|
331
|
+
*
|
|
332
|
+
* @remarks
|
|
333
|
+
* The optional `deps` argument exists for firebase-js-sdk API parity. React Native Firebase
|
|
334
|
+
* ignores persistence, popup redirect resolver, and error-map dependencies because native
|
|
335
|
+
* iOS/Android SDKs manage auth state and do not support the web-only persistence stack.
|
|
336
|
+
* `initializeAuth()` returns the same shared Auth instance as {@link getAuth}.
|
|
337
|
+
*/
|
|
338
|
+
export function initializeAuth(app: FirebaseApp, _deps?: Dependencies): Auth {
|
|
339
|
+
// Keep initializeAuth() aligned with getAuth(); passing the sentinel here creates a second module.
|
|
340
|
+
return appWithAuth(app).auth();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Applies an out-of-band email action code (for example from a password reset or email verification link).
|
|
345
|
+
*/
|
|
346
|
+
export function applyActionCode(auth: Auth, oobCode: string): Promise<void> {
|
|
347
|
+
const authInternal = getAuthInternal(auth);
|
|
348
|
+
return callAuthMethod(authInternal, authInternal.applyActionCode, oobCode);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Registers a callback to run before an auth state change is committed.
|
|
353
|
+
*
|
|
354
|
+
* @returns An unsubscribe function.
|
|
355
|
+
*/
|
|
356
|
+
export function beforeAuthStateChanged(
|
|
357
|
+
auth: Auth,
|
|
358
|
+
callback: (user: User | null) => void | Promise<void>,
|
|
359
|
+
onAbort?: () => void,
|
|
360
|
+
): Unsubscribe {
|
|
361
|
+
const authInternal = getAuthInternal(auth);
|
|
362
|
+
return authInternal.beforeAuthStateChanged(callback, onAbort);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Checks the validity of an out-of-band email action code and returns metadata about the pending operation.
|
|
367
|
+
*
|
|
368
|
+
* @remarks React Native Firebase normalizes native results toward firebase-js-sdk shapes, including mapping
|
|
369
|
+
* `fromEmail` to `previousEmail` and coercing multi-factor info objects.
|
|
370
|
+
*/
|
|
371
|
+
export function checkActionCode(auth: Auth, oobCode: string): Promise<ActionCodeInfo> {
|
|
372
|
+
const authInternal = getAuthInternal(auth);
|
|
373
|
+
return callAuthMethod(authInternal, authInternal.checkActionCode, oobCode).then(
|
|
374
|
+
normalizeActionCodeInfo,
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Confirms a password reset using the out-of-band code from the reset email.
|
|
380
|
+
*/
|
|
381
|
+
export function confirmPasswordReset(
|
|
382
|
+
auth: Auth,
|
|
383
|
+
oobCode: string,
|
|
384
|
+
newPassword: string,
|
|
385
|
+
): Promise<void> {
|
|
386
|
+
const authInternal = getAuthInternal(auth);
|
|
387
|
+
return callAuthMethod(authInternal, authInternal.confirmPasswordReset, oobCode, newPassword);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Connects the Auth instance to the Auth emulator.
|
|
392
|
+
*
|
|
393
|
+
* @remarks Delegates to the native `useEmulator` bridge. Accepts the firebase-js-sdk
|
|
394
|
+
* `options.disableWarnings` flag for {@link Auth.emulatorConfig} parity. On web, that flag
|
|
395
|
+
* suppresses the emulator DOM warning banner; native iOS/Android SDKs do not surface that banner,
|
|
396
|
+
* so the value is recorded on `auth.emulatorConfig.options` only. When `options` is provided,
|
|
397
|
+
* `disableWarnings` is required (matching firebase-js-sdk).
|
|
398
|
+
*/
|
|
399
|
+
export function connectAuthEmulator(
|
|
400
|
+
auth: Auth,
|
|
401
|
+
url: string,
|
|
402
|
+
options?: { disableWarnings: boolean },
|
|
403
|
+
): void {
|
|
404
|
+
const authInternal = getAuthInternal(auth);
|
|
405
|
+
callAuthMethod(authInternal, authInternal.useEmulator, url, options);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Creates a new user with an email address and password.
|
|
410
|
+
*
|
|
411
|
+
* @remarks Returned {@link UserCredential} objects include top-level `providerId` and `operationType`
|
|
412
|
+
* fields. `additionalUserInfo`, when present, is attached as a non-enumerable property.
|
|
413
|
+
*/
|
|
414
|
+
export function createUserWithEmailAndPassword(
|
|
415
|
+
auth: Auth,
|
|
416
|
+
email: string,
|
|
417
|
+
password: string,
|
|
418
|
+
): Promise<UserCredential> {
|
|
419
|
+
const authInternal = getAuthInternal(auth);
|
|
420
|
+
return callAuthMethod(authInternal, authInternal.createUserWithEmailAndPassword, email, password).then(
|
|
421
|
+
userCredential =>
|
|
422
|
+
normalizeUserCredential(userCredential, {
|
|
423
|
+
operationType: OperationType.SIGN_IN,
|
|
424
|
+
}),
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Fetches the sign-in methods available for the given email address.
|
|
430
|
+
*/
|
|
431
|
+
export function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise<string[]> {
|
|
432
|
+
const authInternal = getAuthInternal(auth);
|
|
433
|
+
return callAuthMethod(authInternal, authInternal.fetchSignInMethodsForEmail, email);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Extracts a {@link MultiFactorResolver} from a {@link MultiFactorError}.
|
|
438
|
+
*
|
|
439
|
+
* @throws If the error does not contain resolver hints.
|
|
440
|
+
*/
|
|
441
|
+
export function getMultiFactorResolver(auth: Auth, error: MultiFactorError): MultiFactorResolver {
|
|
442
|
+
const authInternal = getAuthInternal(auth);
|
|
443
|
+
const resolver = callAuthMethod(
|
|
444
|
+
authInternal,
|
|
445
|
+
authInternal.getMultiFactorResolver,
|
|
446
|
+
error,
|
|
447
|
+
) as MultiFactorResolverResultInternal | null;
|
|
448
|
+
|
|
449
|
+
if (!resolver) {
|
|
450
|
+
throw new Error('The provided auth error did not contain a multi-factor resolver.');
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return normalizeMultiFactorResolver(resolver);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Returns the redirect sign-in result after a browser redirect flow completes.
|
|
458
|
+
*
|
|
459
|
+
* @remarks
|
|
460
|
+
* **Not supported on React Native Firebase.** Always throws synchronously because native provider
|
|
461
|
+
* flows do not use the browser redirect contract from the firebase-js-sdk.
|
|
462
|
+
*/
|
|
463
|
+
export function getRedirectResult(
|
|
464
|
+
_auth: Auth,
|
|
465
|
+
_resolver?: PopupRedirectResolver,
|
|
466
|
+
): Promise<UserCredential | null> {
|
|
467
|
+
throw new Error('getRedirectResult is unsupported by the native Firebase SDKs.');
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Checks whether an email link is a valid sign-in with email link URL.
|
|
472
|
+
*
|
|
473
|
+
* @remarks React Native Firebase performs this check through the native bridge and returns
|
|
474
|
+
* `Promise<boolean>`. The firebase-js-sdk returns a synchronous `boolean`.
|
|
475
|
+
*/
|
|
476
|
+
export function isSignInWithEmailLink(auth: Auth, emailLink: string): Promise<boolean> {
|
|
477
|
+
const authInternal = getAuthInternal(auth);
|
|
478
|
+
return callAuthMethod(authInternal, authInternal.isSignInWithEmailLink, emailLink);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Subscribes to auth state changes for the given Auth instance.
|
|
483
|
+
*
|
|
484
|
+
* @returns An unsubscribe function.
|
|
485
|
+
*
|
|
486
|
+
* @remarks The legacy `error` and `completed` callback overload exists for firebase-js-sdk API parity.
|
|
487
|
+
* Native auth listeners never invoke separate error or completed callbacks.
|
|
488
|
+
*/
|
|
489
|
+
export function onAuthStateChanged(
|
|
490
|
+
auth: Auth,
|
|
491
|
+
nextOrObserver: NextOrObserver<User>,
|
|
492
|
+
_error?: ErrorFn,
|
|
493
|
+
_completed?: CompleteFn,
|
|
494
|
+
): Unsubscribe {
|
|
495
|
+
// The legacy callback overload exists for JS SDK compatibility, but native auth listeners
|
|
496
|
+
// never invoke separate error/completed callbacks.
|
|
497
|
+
const authInternal = getAuthInternal(auth);
|
|
498
|
+
return callAuthMethod(
|
|
499
|
+
authInternal,
|
|
500
|
+
authInternal.onAuthStateChanged,
|
|
501
|
+
normalizeAuthListener(nextOrObserver),
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Subscribes to ID token changes for the given Auth instance.
|
|
507
|
+
*
|
|
508
|
+
* @returns An unsubscribe function.
|
|
509
|
+
*
|
|
510
|
+
* @remarks The legacy `error` and `completed` callback overload exists for firebase-js-sdk API parity.
|
|
511
|
+
* Native auth listeners never invoke separate error or completed callbacks.
|
|
512
|
+
*/
|
|
513
|
+
export function onIdTokenChanged(
|
|
514
|
+
auth: Auth,
|
|
515
|
+
nextOrObserver: NextOrObserver<User>,
|
|
516
|
+
_error?: ErrorFn,
|
|
517
|
+
_completed?: CompleteFn,
|
|
518
|
+
): Unsubscribe {
|
|
519
|
+
// The legacy callback overload exists for JS SDK compatibility, but native auth listeners
|
|
520
|
+
// never invoke separate error/completed callbacks.
|
|
521
|
+
const authInternal = getAuthInternal(auth);
|
|
522
|
+
return callAuthMethod(
|
|
523
|
+
authInternal,
|
|
524
|
+
authInternal.onIdTokenChanged,
|
|
525
|
+
normalizeAuthListener(nextOrObserver),
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Revokes the given OAuth access token for the current user.
|
|
531
|
+
*
|
|
532
|
+
* @remarks
|
|
533
|
+
* **Web only.** Always throws synchronously on React Native Firebase.
|
|
534
|
+
*/
|
|
535
|
+
export function revokeAccessToken(_auth: Auth, _token: string): Promise<void> {
|
|
536
|
+
throw new Error('revokeAccessToken() is only supported on Web');
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Revokes a user's Sign in with Apple token.
|
|
541
|
+
*
|
|
542
|
+
* @remarks
|
|
543
|
+
* React Native Firebase-specific API required by Apple's account-deletion guidelines.
|
|
544
|
+
* **Supported on iOS** via the native `revokeTokenWithAuthorizationCode` bridge.
|
|
545
|
+
* On Android and Web the bridge resolves without performing revocation (no-op).
|
|
546
|
+
* Distinct from firebase-js-sdk {@link revokeAccessToken}, which revokes OAuth access tokens on Web only.
|
|
547
|
+
*/
|
|
548
|
+
export function revokeToken(auth: Auth, authorizationCode: string): Promise<void> {
|
|
549
|
+
const authInternal = getAuthInternal(auth);
|
|
550
|
+
return callAuthMethod(authInternal, authInternal.revokeToken, authorizationCode);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Sends a password reset email to the given address.
|
|
555
|
+
*/
|
|
556
|
+
export function sendPasswordResetEmail(
|
|
557
|
+
auth: Auth,
|
|
558
|
+
email: string,
|
|
559
|
+
actionCodeSettings?: ActionCodeSettings,
|
|
560
|
+
): Promise<void> {
|
|
561
|
+
const authInternal = getAuthInternal(auth);
|
|
562
|
+
return callAuthMethod(
|
|
563
|
+
authInternal,
|
|
564
|
+
authInternal.sendPasswordResetEmail,
|
|
565
|
+
email,
|
|
566
|
+
actionCodeSettings,
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Sends a sign-in with email link to the given address.
|
|
572
|
+
*
|
|
573
|
+
* @remarks `actionCodeSettings` is required in the modular API (matching firebase-js-sdk).
|
|
574
|
+
* The namespaced `firebase.auth().sendSignInLinkToEmail(email, settings?)` API still supplies
|
|
575
|
+
* defaults when settings are omitted.
|
|
576
|
+
*/
|
|
577
|
+
export function sendSignInLinkToEmail(
|
|
578
|
+
auth: Auth,
|
|
579
|
+
email: string,
|
|
580
|
+
actionCodeSettings: ActionCodeSettings,
|
|
581
|
+
): Promise<void> {
|
|
582
|
+
const authInternal = getAuthInternal(auth);
|
|
583
|
+
return callAuthMethod(
|
|
584
|
+
authInternal,
|
|
585
|
+
authInternal.sendSignInLinkToEmail,
|
|
586
|
+
email,
|
|
587
|
+
actionCodeSettings,
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Sets the persistence type for the Auth instance.
|
|
593
|
+
*
|
|
594
|
+
* @remarks
|
|
595
|
+
* **Not supported on React Native Firebase.** Always throws synchronously because auth state is
|
|
596
|
+
* managed by the native iOS/Android SDKs rather than the web persistence stack.
|
|
597
|
+
*/
|
|
598
|
+
export function setPersistence(_auth: Auth, _persistence: Persistence): Promise<void> {
|
|
599
|
+
throw new Error('setPersistence is unsupported by the native Firebase SDKs.');
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Signs in anonymously.
|
|
604
|
+
*/
|
|
605
|
+
export function signInAnonymously(auth: Auth): Promise<UserCredential> {
|
|
606
|
+
const authInternal = getAuthInternal(auth);
|
|
607
|
+
return callAuthMethod(authInternal, authInternal.signInAnonymously).then(userCredential =>
|
|
608
|
+
normalizeUserCredential(userCredential, {
|
|
609
|
+
operationType: OperationType.SIGN_IN,
|
|
610
|
+
}),
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Signs in with the given auth credential.
|
|
616
|
+
*/
|
|
617
|
+
export function signInWithCredential(
|
|
618
|
+
auth: Auth,
|
|
619
|
+
credential: AuthCredential,
|
|
620
|
+
): Promise<UserCredential> {
|
|
621
|
+
const authInternal = getAuthInternal(auth);
|
|
622
|
+
return callAuthMethod(authInternal, authInternal.signInWithCredential, credential).then(
|
|
623
|
+
userCredential =>
|
|
624
|
+
normalizeUserCredential(userCredential, {
|
|
625
|
+
providerId: credential.providerId,
|
|
626
|
+
operationType: OperationType.SIGN_IN,
|
|
627
|
+
}),
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Signs in with a custom authentication token.
|
|
633
|
+
*/
|
|
634
|
+
export function signInWithCustomToken(auth: Auth, customToken: string): Promise<UserCredential> {
|
|
635
|
+
const authInternal = getAuthInternal(auth);
|
|
636
|
+
return callAuthMethod(authInternal, authInternal.signInWithCustomToken, customToken).then(
|
|
637
|
+
userCredential =>
|
|
638
|
+
normalizeUserCredential(userCredential, {
|
|
639
|
+
operationType: OperationType.SIGN_IN,
|
|
640
|
+
}),
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Signs in with an email address and password.
|
|
646
|
+
*/
|
|
647
|
+
export function signInWithEmailAndPassword(
|
|
648
|
+
auth: Auth,
|
|
649
|
+
email: string,
|
|
650
|
+
password: string,
|
|
651
|
+
): Promise<UserCredential> {
|
|
652
|
+
const authInternal = getAuthInternal(auth);
|
|
653
|
+
return callAuthMethod(authInternal, authInternal.signInWithEmailAndPassword, email, password).then(
|
|
654
|
+
userCredential =>
|
|
655
|
+
normalizeUserCredential(userCredential, {
|
|
656
|
+
operationType: OperationType.SIGN_IN,
|
|
657
|
+
}),
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Signs in using an email and sign-in with email link.
|
|
663
|
+
*
|
|
664
|
+
* @remarks The `emailLink` argument is optional, matching firebase-js-sdk.
|
|
665
|
+
*/
|
|
666
|
+
export function signInWithEmailLink(
|
|
667
|
+
auth: Auth,
|
|
668
|
+
email: string,
|
|
669
|
+
emailLink?: string,
|
|
670
|
+
): Promise<UserCredential> {
|
|
671
|
+
const authInternal = getAuthInternal(auth);
|
|
672
|
+
return callAuthMethod(authInternal, authInternal.signInWithEmailLink, email, emailLink).then(
|
|
673
|
+
userCredential =>
|
|
674
|
+
normalizeUserCredential(userCredential, {
|
|
675
|
+
providerId: ProviderId.PASSWORD,
|
|
676
|
+
operationType: OperationType.SIGN_IN,
|
|
677
|
+
}),
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Signs in with a phone number and returns a confirmation result for SMS verification.
|
|
683
|
+
*
|
|
684
|
+
* @remarks
|
|
685
|
+
* Native SDKs own the phone verification flow. The optional `appVerifier` argument from the
|
|
686
|
+
* firebase-js-sdk is ignored. This modular API also does not accept RNFB's legacy `forceResend`
|
|
687
|
+
* argument — use {@link verifyPhoneNumber} for the native listener / force-resend flow instead.
|
|
688
|
+
*/
|
|
689
|
+
export function signInWithPhoneNumber(
|
|
690
|
+
auth: Auth,
|
|
691
|
+
phoneNumber: string,
|
|
692
|
+
_appVerifier?: ApplicationVerifier,
|
|
693
|
+
): Promise<ConfirmationResult> {
|
|
694
|
+
// Native SDKs own the verification flow, so the modular wrapper intentionally ignores the
|
|
695
|
+
// JS SDK's optional ApplicationVerifier and forwards only the phone number.
|
|
696
|
+
const authInternal = getAuthInternal(auth);
|
|
697
|
+
return callAuthMethod(authInternal, authInternal.signInWithPhoneNumber, phoneNumber).then(
|
|
698
|
+
normalizeConfirmationResult,
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Starts native phone number verification and returns a listener for verification events.
|
|
704
|
+
*
|
|
705
|
+
* @remarks React Native Firebase-specific API with no firebase-js-sdk equivalent. Use this for
|
|
706
|
+
* auto-verification, resend, and multi-step phone auth flows that require native callbacks.
|
|
707
|
+
*/
|
|
708
|
+
export function verifyPhoneNumber(
|
|
709
|
+
auth: Auth,
|
|
710
|
+
phoneNumber: string,
|
|
711
|
+
autoVerifyTimeoutOrForceResend?: number | boolean,
|
|
712
|
+
forceResend?: boolean,
|
|
713
|
+
): PhoneAuthListener {
|
|
714
|
+
const authInternal = getAuthInternal(auth);
|
|
715
|
+
return callAuthMethod(
|
|
716
|
+
authInternal,
|
|
717
|
+
authInternal.verifyPhoneNumber,
|
|
718
|
+
phoneNumber,
|
|
719
|
+
autoVerifyTimeoutOrForceResend,
|
|
720
|
+
forceResend,
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Signs in with the given provider using a native popup-style flow where supported.
|
|
726
|
+
*/
|
|
727
|
+
export function signInWithPopup(
|
|
728
|
+
auth: Auth,
|
|
729
|
+
provider: AuthProvider,
|
|
730
|
+
_resolver?: PopupRedirectResolver,
|
|
731
|
+
): Promise<UserCredential> {
|
|
732
|
+
const authInternal = getAuthInternal(auth);
|
|
733
|
+
return callAuthMethod(
|
|
734
|
+
authInternal,
|
|
735
|
+
authInternal.signInWithPopup,
|
|
736
|
+
provider as unknown as AuthProviderWithObjectInternal,
|
|
737
|
+
).then(userCredential =>
|
|
738
|
+
normalizeUserCredential(userCredential, {
|
|
739
|
+
providerId: provider.providerId,
|
|
740
|
+
operationType: OperationType.SIGN_IN,
|
|
741
|
+
}),
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Signs in with the given provider using a redirect-style flow.
|
|
747
|
+
*
|
|
748
|
+
* @remarks On React Native Firebase, native provider flows complete immediately and resolve with a
|
|
749
|
+
* {@link UserCredential} instead of following the browser redirect contract used by the
|
|
750
|
+
* firebase-js-sdk (which resolves later via {@link getRedirectResult}).
|
|
751
|
+
*/
|
|
752
|
+
export function signInWithRedirect(
|
|
753
|
+
auth: Auth,
|
|
754
|
+
provider: AuthProvider,
|
|
755
|
+
_resolver?: PopupRedirectResolver,
|
|
756
|
+
): Promise<UserCredential> {
|
|
757
|
+
// Native provider flows complete immediately and return a credential instead of following the
|
|
758
|
+
// browser redirect contract from the Firebase JS SDK.
|
|
759
|
+
const authInternal = getAuthInternal(auth);
|
|
760
|
+
return callAuthMethod(
|
|
761
|
+
authInternal,
|
|
762
|
+
authInternal.signInWithRedirect,
|
|
763
|
+
provider as unknown as AuthProviderWithObjectInternal,
|
|
764
|
+
).then(userCredential =>
|
|
765
|
+
normalizeUserCredential(userCredential, {
|
|
766
|
+
providerId: provider.providerId,
|
|
767
|
+
operationType: OperationType.SIGN_IN,
|
|
768
|
+
}),
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Signs out the current user for the given Auth instance.
|
|
774
|
+
*/
|
|
775
|
+
export function signOut(auth: Auth): Promise<void> {
|
|
776
|
+
const authInternal = getAuthInternal(auth);
|
|
777
|
+
return callAuthMethod(authInternal, authInternal.signOut);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Updates the currently signed-in user on the Auth instance.
|
|
782
|
+
*/
|
|
783
|
+
export function updateCurrentUser(auth: Auth, user: User | null): Promise<void> {
|
|
784
|
+
const authInternal = getAuthInternal(auth);
|
|
785
|
+
return callAuthMethod(authInternal, authInternal.updateCurrentUser, user);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Sets the Auth `languageCode` from the device locale.
|
|
790
|
+
*
|
|
791
|
+
* @remarks
|
|
792
|
+
* **Not supported on React Native Firebase.** Always throws synchronously. Set `auth.languageCode`
|
|
793
|
+
* directly or use {@link setLanguageCode}.
|
|
794
|
+
*/
|
|
795
|
+
export function useDeviceLanguage(_auth: Auth): void {
|
|
796
|
+
throw new Error('useDeviceLanguage is unsupported by the native Firebase SDKs');
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Sets the Auth language code.
|
|
801
|
+
*
|
|
802
|
+
* @remarks React Native Firebase exposes this as a modular helper. The firebase-js-sdk only exposes
|
|
803
|
+
* the writable `auth.languageCode` property.
|
|
804
|
+
*/
|
|
805
|
+
export function setLanguageCode(auth: Auth, languageCode: string | null): Promise<void> {
|
|
806
|
+
const authInternal = getAuthInternal(auth);
|
|
807
|
+
return callAuthMethod(authInternal, authInternal.setLanguageCode, languageCode);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Configures iOS keychain access group sharing for the Auth instance.
|
|
812
|
+
*
|
|
813
|
+
* @remarks React Native Firebase-specific iOS helper with no firebase-js-sdk equivalent.
|
|
814
|
+
*/
|
|
815
|
+
export function useUserAccessGroup(auth: Auth, userAccessGroup: string): Promise<void> {
|
|
816
|
+
const authInternal = getAuthInternal(auth);
|
|
817
|
+
return callAuthMethod(authInternal, authInternal.useUserAccessGroup, userAccessGroup).then(
|
|
818
|
+
() => undefined,
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Verifies a password reset code and returns the associated email address.
|
|
824
|
+
*/
|
|
825
|
+
export function verifyPasswordResetCode(auth: Auth, code: string): Promise<string> {
|
|
826
|
+
const authInternal = getAuthInternal(auth);
|
|
827
|
+
return callAuthMethod(authInternal, authInternal.verifyPasswordResetCode, code);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Parses an email action link string.
|
|
832
|
+
*
|
|
833
|
+
* @param link - The email action link to parse.
|
|
834
|
+
* @returns The {@link ActionCodeURL} object, or `null` if the link is invalid.
|
|
835
|
+
*
|
|
836
|
+
* @remarks Pure URL parsing (ported from firebase-js-sdk). Works on all platforms without a native
|
|
837
|
+
* bridge. See also {@link ActionCodeURL.parseLink}.
|
|
838
|
+
*/
|
|
839
|
+
export function parseActionCodeURL(link: string): ActionCodeURL | null {
|
|
840
|
+
return ActionCodeURL.parseLink(link);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Deletes the given user account.
|
|
845
|
+
*/
|
|
846
|
+
export function deleteUser(user: User): Promise<void> {
|
|
847
|
+
const userInternal = getUserInternal(user);
|
|
848
|
+
return callUserMethod(userInternal, userInternal.delete);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Returns the current ID token for the user.
|
|
853
|
+
*/
|
|
854
|
+
export function getIdToken(user: User, forceRefresh?: boolean): Promise<string> {
|
|
855
|
+
const userInternal = getUserInternal(user);
|
|
856
|
+
return callUserMethod(userInternal, userInternal.getIdToken, forceRefresh);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Returns the decoded ID token result for the user.
|
|
861
|
+
*/
|
|
862
|
+
export function getIdTokenResult(user: User, forceRefresh?: boolean): Promise<IdTokenResult> {
|
|
863
|
+
const userInternal = getUserInternal(user);
|
|
864
|
+
return callUserMethod(userInternal, userInternal.getIdTokenResult, forceRefresh);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Links the user account with the given credential.
|
|
869
|
+
*/
|
|
870
|
+
export function linkWithCredential(
|
|
871
|
+
user: User,
|
|
872
|
+
credential: AuthCredential,
|
|
873
|
+
): Promise<UserCredential> {
|
|
874
|
+
const userInternal = getUserInternal(user);
|
|
875
|
+
return callUserMethod(userInternal, userInternal.linkWithCredential, credential).then(
|
|
876
|
+
userCredential =>
|
|
877
|
+
normalizeUserCredential(userCredential, {
|
|
878
|
+
providerId: credential.providerId,
|
|
879
|
+
operationType: OperationType.LINK,
|
|
880
|
+
}),
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Links the user account with a phone number using SMS verification.
|
|
886
|
+
*
|
|
887
|
+
* @remarks
|
|
888
|
+
* **Not supported on React Native Firebase.** Always throws synchronously.
|
|
889
|
+
*/
|
|
890
|
+
export function linkWithPhoneNumber(
|
|
891
|
+
_user: User,
|
|
892
|
+
_phoneNumber: string,
|
|
893
|
+
_appVerifier?: ApplicationVerifier,
|
|
894
|
+
): Promise<ConfirmationResult> {
|
|
895
|
+
throw new Error('linkWithPhoneNumber is unsupported by the native Firebase SDKs');
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Links the user account with the given provider using a native popup-style flow where supported.
|
|
900
|
+
*/
|
|
901
|
+
export function linkWithPopup(
|
|
902
|
+
user: User,
|
|
903
|
+
provider: AuthProvider,
|
|
904
|
+
_resolver?: PopupRedirectResolver,
|
|
905
|
+
): Promise<UserCredential> {
|
|
906
|
+
const userInternal = getUserInternal(user);
|
|
907
|
+
return callUserMethod(
|
|
908
|
+
userInternal,
|
|
909
|
+
userInternal.linkWithPopup,
|
|
910
|
+
provider as unknown as AuthProviderWithObjectInternal,
|
|
911
|
+
).then(userCredential =>
|
|
912
|
+
normalizeUserCredential(userCredential, {
|
|
913
|
+
providerId: provider.providerId,
|
|
914
|
+
operationType: OperationType.LINK,
|
|
915
|
+
}),
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Links the user account with the given provider using a redirect-style flow.
|
|
921
|
+
*
|
|
922
|
+
* @remarks On React Native Firebase, native provider flows complete immediately and resolve with a
|
|
923
|
+
* {@link UserCredential} instead of following the browser redirect contract used by the
|
|
924
|
+
* firebase-js-sdk.
|
|
925
|
+
*/
|
|
926
|
+
export function linkWithRedirect(
|
|
927
|
+
user: User,
|
|
928
|
+
provider: AuthProvider,
|
|
929
|
+
_resolver?: PopupRedirectResolver,
|
|
930
|
+
): Promise<UserCredential> {
|
|
931
|
+
// Native provider flows complete immediately and return a credential instead of following the
|
|
932
|
+
// browser redirect contract from the Firebase JS SDK.
|
|
933
|
+
const userInternal = getUserInternal(user);
|
|
934
|
+
return callUserMethod(
|
|
935
|
+
userInternal,
|
|
936
|
+
userInternal.linkWithRedirect,
|
|
937
|
+
provider as unknown as AuthProviderWithObjectInternal,
|
|
938
|
+
).then(userCredential =>
|
|
939
|
+
normalizeUserCredential(userCredential, {
|
|
940
|
+
providerId: provider.providerId,
|
|
941
|
+
operationType: OperationType.LINK,
|
|
942
|
+
}),
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Returns the multi-factor interface for the given user.
|
|
948
|
+
*
|
|
949
|
+
* @remarks Uses the user's own Auth instance instead of always calling {@link getAuth}, which fixes
|
|
950
|
+
* secondary Firebase app usage compared with earlier RNFB behavior.
|
|
951
|
+
*/
|
|
952
|
+
export function multiFactor(user: User): MultiFactorUser {
|
|
953
|
+
return normalizeMultiFactorUser(
|
|
954
|
+
new MultiFactorUserModule(
|
|
955
|
+
((user as unknown as UserInternal)._auth ||
|
|
956
|
+
(getAuth() as unknown as UserInternal['_auth'])) as NonNullable<UserInternal['_auth']>,
|
|
957
|
+
user as unknown as MultiFactorUserSourceInternal,
|
|
958
|
+
),
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Reauthenticates the user with the given credential.
|
|
964
|
+
*/
|
|
965
|
+
export function reauthenticateWithCredential(
|
|
966
|
+
user: User,
|
|
967
|
+
credential: AuthCredential,
|
|
968
|
+
): Promise<UserCredential> {
|
|
969
|
+
const userInternal = getUserInternal(user);
|
|
970
|
+
return callUserMethod(userInternal, userInternal.reauthenticateWithCredential, credential).then(
|
|
971
|
+
userCredential =>
|
|
972
|
+
normalizeUserCredential(userCredential, {
|
|
973
|
+
providerId: credential.providerId,
|
|
974
|
+
operationType: OperationType.REAUTHENTICATE,
|
|
975
|
+
}),
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Reauthenticates the user with a phone number using SMS verification.
|
|
981
|
+
*
|
|
982
|
+
* @remarks
|
|
983
|
+
* **Not supported on React Native Firebase.** Always throws synchronously.
|
|
984
|
+
*/
|
|
985
|
+
export function reauthenticateWithPhoneNumber(
|
|
986
|
+
_user: User,
|
|
987
|
+
_phoneNumber: string,
|
|
988
|
+
_appVerifier?: ApplicationVerifier,
|
|
989
|
+
): Promise<ConfirmationResult> {
|
|
990
|
+
throw new Error('reauthenticateWithPhoneNumber is unsupported by the native Firebase SDKs');
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Reauthenticates the user with the given provider using a native popup-style flow where supported.
|
|
995
|
+
*/
|
|
996
|
+
export function reauthenticateWithPopup(
|
|
997
|
+
user: User,
|
|
998
|
+
provider: AuthProvider,
|
|
999
|
+
_resolver?: PopupRedirectResolver,
|
|
1000
|
+
): Promise<UserCredential> {
|
|
1001
|
+
const userInternal = getUserInternal(user);
|
|
1002
|
+
return callUserMethod(
|
|
1003
|
+
userInternal,
|
|
1004
|
+
userInternal.reauthenticateWithPopup,
|
|
1005
|
+
provider as unknown as AuthProviderWithObjectInternal,
|
|
1006
|
+
).then(userCredential =>
|
|
1007
|
+
normalizeUserCredential(userCredential, {
|
|
1008
|
+
providerId: provider.providerId,
|
|
1009
|
+
operationType: OperationType.REAUTHENTICATE,
|
|
1010
|
+
}),
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Reauthenticates the user with the given provider using a redirect-style flow.
|
|
1016
|
+
*
|
|
1017
|
+
* @remarks On React Native Firebase, native provider flows do not follow the browser redirect
|
|
1018
|
+
* contract. This resolves with `void` after the native flow completes instead of the
|
|
1019
|
+
* firebase-js-sdk `Promise<never>` signature used for unresolved browser redirects.
|
|
1020
|
+
*/
|
|
1021
|
+
export function reauthenticateWithRedirect(
|
|
1022
|
+
user: User,
|
|
1023
|
+
provider: AuthProvider,
|
|
1024
|
+
_resolver?: PopupRedirectResolver,
|
|
1025
|
+
): Promise<void> {
|
|
1026
|
+
const userInternal = getUserInternal(user);
|
|
1027
|
+
return callUserMethod(
|
|
1028
|
+
userInternal,
|
|
1029
|
+
userInternal.reauthenticateWithRedirect,
|
|
1030
|
+
provider as unknown as AuthProviderWithObjectInternal,
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Reloads the user's profile data from the server.
|
|
1036
|
+
*/
|
|
1037
|
+
export function reload(user: User): Promise<void> {
|
|
1038
|
+
const userInternal = getUserInternal(user);
|
|
1039
|
+
return callUserMethod(userInternal, userInternal.reload);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* Sends an email verification message to the user.
|
|
1044
|
+
*/
|
|
1045
|
+
export function sendEmailVerification(
|
|
1046
|
+
user: User,
|
|
1047
|
+
actionCodeSettings?: ActionCodeSettings | null,
|
|
1048
|
+
): Promise<void> {
|
|
1049
|
+
const userInternal = getUserInternal(user);
|
|
1050
|
+
return callUserMethod(
|
|
1051
|
+
userInternal,
|
|
1052
|
+
userInternal.sendEmailVerification,
|
|
1053
|
+
actionCodeSettings ?? undefined,
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* Unlinks a provider from the user account.
|
|
1059
|
+
*/
|
|
1060
|
+
export function unlink(user: User, providerId: string): Promise<User> {
|
|
1061
|
+
const userInternal = getUserInternal(user);
|
|
1062
|
+
return callUserMethod(userInternal, userInternal.unlink, providerId);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Updates the user's email address.
|
|
1067
|
+
*/
|
|
1068
|
+
export function updateEmail(user: User, newEmail: string): Promise<void> {
|
|
1069
|
+
const userInternal = getUserInternal(user);
|
|
1070
|
+
return callUserMethod(userInternal, userInternal.updateEmail, newEmail);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* Updates the user's password.
|
|
1075
|
+
*/
|
|
1076
|
+
export function updatePassword(user: User, newPassword: string): Promise<void> {
|
|
1077
|
+
const userInternal = getUserInternal(user);
|
|
1078
|
+
return callUserMethod(userInternal, userInternal.updatePassword, newPassword);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Updates the user's phone number using a phone auth credential.
|
|
1083
|
+
*/
|
|
1084
|
+
export function updatePhoneNumber(user: User, credential: PhoneAuthCredential): Promise<void> {
|
|
1085
|
+
const userInternal = getUserInternal(user);
|
|
1086
|
+
return callUserMethod(userInternal, userInternal.updatePhoneNumber, credential);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* Updates the user's display name and/or photo URL.
|
|
1091
|
+
*/
|
|
1092
|
+
export function updateProfile(
|
|
1093
|
+
user: User,
|
|
1094
|
+
profile: { displayName?: string | null; photoURL?: string | null },
|
|
1095
|
+
): Promise<void> {
|
|
1096
|
+
const userInternal = getUserInternal(user);
|
|
1097
|
+
return callUserMethod(userInternal, userInternal.updateProfile, {
|
|
1098
|
+
displayName: profile.displayName,
|
|
1099
|
+
photoURL: profile.photoURL,
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* Sends a verification email to the new address before updating the user's email.
|
|
1105
|
+
*/
|
|
1106
|
+
export function verifyBeforeUpdateEmail(
|
|
1107
|
+
user: User,
|
|
1108
|
+
newEmail: string,
|
|
1109
|
+
actionCodeSettings?: ActionCodeSettings | null,
|
|
1110
|
+
): Promise<void> {
|
|
1111
|
+
const userInternal = getUserInternal(user);
|
|
1112
|
+
return callUserMethod(
|
|
1113
|
+
userInternal,
|
|
1114
|
+
userInternal.verifyBeforeUpdateEmail,
|
|
1115
|
+
newEmail,
|
|
1116
|
+
actionCodeSettings ?? undefined,
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* Returns additional OAuth / federated sign-in information from a {@link UserCredential}.
|
|
1122
|
+
*
|
|
1123
|
+
* @remarks Returns firebase-js-sdk core fields plus any extra native keys copied from the bridge.
|
|
1124
|
+
*/
|
|
1125
|
+
export function getAdditionalUserInfo(
|
|
1126
|
+
userCredential: UserCredential,
|
|
1127
|
+
): AdditionalUserInfo | null {
|
|
1128
|
+
if (userCredential.additionalUserInfo) {
|
|
1129
|
+
return userCredential.additionalUserInfo;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
const info = (userCredential as unknown as UserCredentialResultInternal).additionalUserInfo;
|
|
1133
|
+
if (!info) {
|
|
1134
|
+
return null;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
return normalizeAdditionalUserInfo(info as AdditionalUserInfoSource);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* Returns the configured custom auth domain for the Auth instance.
|
|
1142
|
+
*
|
|
1143
|
+
* @remarks React Native Firebase-specific helper with no firebase-js-sdk equivalent.
|
|
1144
|
+
*/
|
|
1145
|
+
export function getCustomAuthDomain(auth: Auth): Promise<string> {
|
|
1146
|
+
const authInternal = getAuthInternal(auth);
|
|
1147
|
+
return callAuthMethod(authInternal, authInternal.getCustomAuthDomain);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Validates a password against the project's password policy.
|
|
1152
|
+
*/
|
|
1153
|
+
export function validatePassword(auth: Auth, password: string): Promise<PasswordValidationStatus> {
|
|
1154
|
+
if (!auth || !('app' in auth)) {
|
|
1155
|
+
throw new Error(
|
|
1156
|
+
`firebase.auth().validatePassword(*) 'auth' must be a valid Auth instance with an 'app' property`,
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
if (password === null || password === undefined) {
|
|
1161
|
+
throw new Error(
|
|
1162
|
+
"firebase.auth().validatePassword(*) expected 'password' to be a non-null or a defined value.",
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
const authWithPasswordValidation = getAuthInternal(auth);
|
|
1167
|
+
return callAuthMethod(
|
|
1168
|
+
authWithPasswordValidation,
|
|
1169
|
+
authWithPasswordValidation.validatePassword,
|
|
1170
|
+
password,
|
|
1171
|
+
);
|
|
1172
|
+
}
|