@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
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
createDeprecationProxy,
|
|
20
|
+
isAndroid,
|
|
21
|
+
isBoolean,
|
|
22
|
+
isNull,
|
|
23
|
+
isOther,
|
|
24
|
+
isString,
|
|
25
|
+
isValidUrl,
|
|
26
|
+
parseListenerOrObserver,
|
|
27
|
+
} from '@react-native-firebase/app/dist/module/common';
|
|
28
|
+
import type { ReactNativeFirebase } from '@react-native-firebase/app';
|
|
29
|
+
import { setReactNativeModule } from '@react-native-firebase/app/dist/module/internal/nativeModule';
|
|
30
|
+
import {
|
|
31
|
+
FirebaseModule,
|
|
32
|
+
createModuleNamespace,
|
|
33
|
+
getFirebaseRoot,
|
|
34
|
+
type ModuleConfig,
|
|
35
|
+
} from '@react-native-firebase/app/dist/module/internal';
|
|
36
|
+
import ConfirmationResult from './ConfirmationResult';
|
|
37
|
+
import { PhoneAuthState } from './PhoneAuthState';
|
|
38
|
+
import PhoneAuthListener from './PhoneAuthListener';
|
|
39
|
+
import PhoneMultiFactorGenerator from './PhoneMultiFactorGenerator';
|
|
40
|
+
import TotpMultiFactorGenerator from './TotpMultiFactorGenerator';
|
|
41
|
+
import Settings from './Settings';
|
|
42
|
+
import User from './User';
|
|
43
|
+
import { getMultiFactorResolver } from './getMultiFactorResolver';
|
|
44
|
+
import { MultiFactorUser, multiFactor } from './multiFactor';
|
|
45
|
+
import AppleAuthProvider from './providers/AppleAuthProvider';
|
|
46
|
+
import EmailAuthProvider from './providers/EmailAuthProvider';
|
|
47
|
+
import FacebookAuthProvider from './providers/FacebookAuthProvider';
|
|
48
|
+
import GithubAuthProvider from './providers/GithubAuthProvider';
|
|
49
|
+
import GoogleAuthProvider from './providers/GoogleAuthProvider';
|
|
50
|
+
import OAuthProvider from './providers/OAuthProvider';
|
|
51
|
+
import OIDCAuthProvider from './providers/OIDCAuthProvider';
|
|
52
|
+
import PhoneAuthProvider from './providers/PhoneAuthProvider';
|
|
53
|
+
import TwitterAuthProvider from './providers/TwitterAuthProvider';
|
|
54
|
+
import { version } from './version';
|
|
55
|
+
import fallBackModule from './web/RNFBAuthModule';
|
|
56
|
+
import { PasswordPolicyMixin } from './password-policy/PasswordPolicyMixin';
|
|
57
|
+
import type { CallbackOrObserver, FirebaseAuthTypes } from './types/namespaced';
|
|
58
|
+
import type { EmulatorConfig, Unsubscribe, User as ModularUser } from './types/auth';
|
|
59
|
+
import type {
|
|
60
|
+
AuthIdTokenChangedEventInternal,
|
|
61
|
+
AuthInternal,
|
|
62
|
+
AuthStateChangedEventInternal,
|
|
63
|
+
NativePhoneAuthCredentialInternal,
|
|
64
|
+
NativeUserCredentialInternal,
|
|
65
|
+
NativeUserInternal,
|
|
66
|
+
PasswordPolicyInternal,
|
|
67
|
+
PasswordValidationStatusInternal,
|
|
68
|
+
PhoneAuthStateChangedEventInternal,
|
|
69
|
+
} from './types/internal';
|
|
70
|
+
|
|
71
|
+
type AuthProviderWithObjectInternal = FirebaseAuthTypes.AuthProvider & {
|
|
72
|
+
toObject(): Record<string, unknown>;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
type AuthErrorWithCodeInternal = Error & {
|
|
76
|
+
code?: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const nativeEvents = ['auth_state_changed', 'auth_id_token_changed', 'phone_auth_state_changed'];
|
|
80
|
+
|
|
81
|
+
const statics = {
|
|
82
|
+
AppleAuthProvider,
|
|
83
|
+
EmailAuthProvider,
|
|
84
|
+
PhoneAuthProvider,
|
|
85
|
+
GoogleAuthProvider,
|
|
86
|
+
GithubAuthProvider,
|
|
87
|
+
TwitterAuthProvider,
|
|
88
|
+
FacebookAuthProvider,
|
|
89
|
+
PhoneMultiFactorGenerator,
|
|
90
|
+
TotpMultiFactorGenerator,
|
|
91
|
+
OAuthProvider,
|
|
92
|
+
OIDCAuthProvider,
|
|
93
|
+
PhoneAuthState,
|
|
94
|
+
getMultiFactorResolver,
|
|
95
|
+
multiFactor,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const namespace = 'auth';
|
|
99
|
+
const nativeModuleName = 'RNFBAuthModule';
|
|
100
|
+
|
|
101
|
+
type BeforeAuthStateChangedEntry = {
|
|
102
|
+
callback: (user: ModularUser | null) => void | Promise<void>;
|
|
103
|
+
onAbort?: () => void;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
class FirebaseAuthModule extends FirebaseModule<typeof nativeModuleName> {
|
|
107
|
+
_user: FirebaseAuthTypes.User | null;
|
|
108
|
+
_settings: FirebaseAuthTypes.AuthSettings | null;
|
|
109
|
+
_authResult: boolean;
|
|
110
|
+
_languageCode: string;
|
|
111
|
+
_tenantId: string | null;
|
|
112
|
+
_projectPasswordPolicy: PasswordPolicyInternal | null;
|
|
113
|
+
_tenantPasswordPolicies: Record<string, PasswordPolicyInternal | null>;
|
|
114
|
+
_emulatorConfig: EmulatorConfig | null;
|
|
115
|
+
_authStateReadyPromise: Promise<void> | null;
|
|
116
|
+
_beforeAuthStateChangedCallbacks: BeforeAuthStateChangedEntry[];
|
|
117
|
+
_getPasswordPolicyInternal!: () => PasswordPolicyInternal | null;
|
|
118
|
+
_updatePasswordPolicy!: () => Promise<void>;
|
|
119
|
+
_recachePasswordPolicy!: () => Promise<void>;
|
|
120
|
+
validatePassword!: (password: string) => Promise<PasswordValidationStatusInternal>;
|
|
121
|
+
|
|
122
|
+
constructor(
|
|
123
|
+
app: ReactNativeFirebase.FirebaseAppBase,
|
|
124
|
+
config: ModuleConfig,
|
|
125
|
+
customUrlOrRegion?: string | null,
|
|
126
|
+
) {
|
|
127
|
+
super(app, config, customUrlOrRegion);
|
|
128
|
+
this._user = null;
|
|
129
|
+
this._settings = null;
|
|
130
|
+
this._authResult = false;
|
|
131
|
+
this._languageCode = this.native.APP_LANGUAGE[this.app.name] ?? '';
|
|
132
|
+
this._tenantId = null;
|
|
133
|
+
this._projectPasswordPolicy = null;
|
|
134
|
+
this._tenantPasswordPolicies = {};
|
|
135
|
+
this._emulatorConfig = null;
|
|
136
|
+
this._authStateReadyPromise = null;
|
|
137
|
+
this._beforeAuthStateChangedCallbacks = [];
|
|
138
|
+
|
|
139
|
+
if (!this.languageCode) {
|
|
140
|
+
this._languageCode = this.native.APP_LANGUAGE['[DEFAULT]'] ?? '';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const initialUser = this.native.APP_USER[this.app.name];
|
|
144
|
+
if (initialUser) {
|
|
145
|
+
this._setUser(initialUser);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
this.emitter.addListener(this.eventNameForApp('auth_state_changed'), event => {
|
|
149
|
+
const authEvent = event as AuthStateChangedEventInternal;
|
|
150
|
+
void this._handleAuthStateChanged(authEvent.user);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
this.emitter.addListener(this.eventNameForApp('phone_auth_state_changed'), event => {
|
|
154
|
+
const phoneAuthEvent = event as PhoneAuthStateChangedEventInternal;
|
|
155
|
+
const eventKey = `phone:auth:${phoneAuthEvent.requestKey}:${phoneAuthEvent.type}`;
|
|
156
|
+
this.emitter.emit(eventKey, phoneAuthEvent.state);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
this.emitter.addListener(this.eventNameForApp('auth_id_token_changed'), event => {
|
|
160
|
+
const authEvent = event as AuthIdTokenChangedEventInternal;
|
|
161
|
+
this._setUser(authEvent.user);
|
|
162
|
+
this.emitter.emit(this.eventNameForApp('onIdTokenChanged'), this._user);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
this.native.addAuthStateListener();
|
|
166
|
+
this.native.addIdTokenListener();
|
|
167
|
+
|
|
168
|
+
// custom authDomain in only available from App's FirebaseOptions,
|
|
169
|
+
// but we need it in Auth if it exists. During app configuration we store
|
|
170
|
+
// mappings from app name to authDomain, this auth constructor
|
|
171
|
+
// is a reasonable time to use the mapping and set it into auth natively
|
|
172
|
+
if (!isOther) {
|
|
173
|
+
// Only supported on native platforms
|
|
174
|
+
this.native.configureAuthDomain();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get languageCode(): string {
|
|
179
|
+
return this._languageCode;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
set languageCode(code: string | null) {
|
|
183
|
+
// For modular API, not recommended to set languageCode directly as it should be set in the native SDKs first
|
|
184
|
+
if (!isString(code) && !isNull(code)) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
"firebase.auth().languageCode = (*) expected 'languageCode' to be a string or null value",
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
// as this is a setter, we can't use async/await. So we set it first so it is available immediately
|
|
190
|
+
if (code === null) {
|
|
191
|
+
this._languageCode = this.native.APP_LANGUAGE[this.app.name] ?? '';
|
|
192
|
+
|
|
193
|
+
if (!this.languageCode) {
|
|
194
|
+
this._languageCode = this.native.APP_LANGUAGE['[DEFAULT]'] ?? '';
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
this._languageCode = code;
|
|
198
|
+
}
|
|
199
|
+
// This sets it natively
|
|
200
|
+
void this.setLanguageCode(code);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
get config(): Record<string, never> {
|
|
204
|
+
// Native iOS/Android Firebase Auth SDKs do not expose the firebase-js-sdk config object.
|
|
205
|
+
return {};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
get tenantId(): string | null {
|
|
209
|
+
return this._tenantId;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
set tenantId(tenantId: string | null) {
|
|
213
|
+
void this.setTenantId(tenantId);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
get emulatorConfig(): EmulatorConfig | null {
|
|
217
|
+
return this._emulatorConfig;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
authStateReady(): Promise<void> {
|
|
221
|
+
if (this._authResult) {
|
|
222
|
+
return Promise.resolve();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!this._authStateReadyPromise) {
|
|
226
|
+
this._authStateReadyPromise = new Promise(resolve => {
|
|
227
|
+
const unsubscribe = this.onAuthStateChanged(() => {
|
|
228
|
+
if (this._authResult) {
|
|
229
|
+
unsubscribe();
|
|
230
|
+
resolve();
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (this._authResult) {
|
|
235
|
+
unsubscribe();
|
|
236
|
+
resolve();
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return this._authStateReadyPromise;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
beforeAuthStateChanged(
|
|
245
|
+
callback: (user: ModularUser | null) => void | Promise<void>,
|
|
246
|
+
onAbort?: () => void,
|
|
247
|
+
): Unsubscribe {
|
|
248
|
+
const entry: BeforeAuthStateChangedEntry = { callback, onAbort };
|
|
249
|
+
this._beforeAuthStateChangedCallbacks.push(entry);
|
|
250
|
+
|
|
251
|
+
return () => {
|
|
252
|
+
const index = this._beforeAuthStateChangedCallbacks.indexOf(entry);
|
|
253
|
+
if (index >= 0) {
|
|
254
|
+
this._beforeAuthStateChangedCallbacks.splice(index, 1);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async updateCurrentUser(user: FirebaseAuthTypes.User | null): Promise<void> {
|
|
260
|
+
if (user === null) {
|
|
261
|
+
await this.signOut();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const userInternal = user as unknown as {
|
|
266
|
+
_auth?: AuthInternal;
|
|
267
|
+
_user?: NativeUserInternal;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
if (!userInternal._auth || userInternal._auth !== (this as unknown as AuthInternal)) {
|
|
271
|
+
throw new Error(
|
|
272
|
+
"firebase.auth().updateCurrentUser() expected 'user' to be an Auth instance from the same Firebase App",
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (!userInternal._user) {
|
|
277
|
+
throw new Error("firebase.auth().updateCurrentUser(*) expected 'user' to be a valid User");
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this._setUser(userInternal._user);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async _handleAuthStateChanged(nativeUser?: NativeUserInternal | null): Promise<void> {
|
|
284
|
+
const pendingUser = nativeUser
|
|
285
|
+
? (createDeprecationProxy(
|
|
286
|
+
new User(this as unknown as AuthInternal, nativeUser),
|
|
287
|
+
) as FirebaseAuthTypes.User)
|
|
288
|
+
: null;
|
|
289
|
+
|
|
290
|
+
for (const { callback, onAbort } of [...this._beforeAuthStateChangedCallbacks]) {
|
|
291
|
+
try {
|
|
292
|
+
await callback(pendingUser as ModularUser | null);
|
|
293
|
+
} catch {
|
|
294
|
+
onAbort?.();
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
this._setUser(nativeUser);
|
|
300
|
+
this.emitter.emit(this.eventNameForApp('onAuthStateChanged'), this._user);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
get settings(): FirebaseAuthTypes.AuthSettings {
|
|
304
|
+
if (!this._settings) {
|
|
305
|
+
this._settings = new Settings(
|
|
306
|
+
this as unknown as AuthInternal,
|
|
307
|
+
) as FirebaseAuthTypes.AuthSettings;
|
|
308
|
+
}
|
|
309
|
+
return this._settings;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
get currentUser(): FirebaseAuthTypes.User | null {
|
|
313
|
+
return this._user;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
_setUser(user?: NativeUserInternal | null): FirebaseAuthTypes.User | null {
|
|
317
|
+
this._user = user
|
|
318
|
+
? (createDeprecationProxy(
|
|
319
|
+
new User(this as unknown as AuthInternal, user),
|
|
320
|
+
) as FirebaseAuthTypes.User)
|
|
321
|
+
: null;
|
|
322
|
+
this._authResult = true;
|
|
323
|
+
this.emitter.emit(this.eventNameForApp('onUserChanged'), this._user);
|
|
324
|
+
return this._user;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
_setUserCredential(
|
|
328
|
+
userCredential: NativeUserCredentialInternal,
|
|
329
|
+
): FirebaseAuthTypes.UserCredential {
|
|
330
|
+
const user = createDeprecationProxy(
|
|
331
|
+
new User(this as unknown as AuthInternal, userCredential.user),
|
|
332
|
+
) as FirebaseAuthTypes.User;
|
|
333
|
+
this._user = user;
|
|
334
|
+
this._authResult = true;
|
|
335
|
+
this.emitter.emit(this.eventNameForApp('onUserChanged'), this._user);
|
|
336
|
+
return {
|
|
337
|
+
additionalUserInfo: userCredential.additionalUserInfo,
|
|
338
|
+
user,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async setLanguageCode(code: string | null): Promise<void> {
|
|
343
|
+
if (!isString(code) && !isNull(code)) {
|
|
344
|
+
throw new Error(
|
|
345
|
+
"firebase.auth().setLanguageCode(*) expected 'languageCode' to be a string or null value",
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
await this.native.setLanguageCode(code);
|
|
350
|
+
|
|
351
|
+
if (code === null) {
|
|
352
|
+
this._languageCode = this.native.APP_LANGUAGE[this.app.name] ?? '';
|
|
353
|
+
|
|
354
|
+
if (!this.languageCode) {
|
|
355
|
+
this._languageCode = this.native.APP_LANGUAGE['[DEFAULT]'] ?? '';
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
this._languageCode = code;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async setTenantId(tenantId: string | null): Promise<void> {
|
|
363
|
+
if (!isString(tenantId) && !isNull(tenantId)) {
|
|
364
|
+
throw new Error("firebase.auth().setTenantId(*) expected 'tenantId' to be a string");
|
|
365
|
+
}
|
|
366
|
+
await this.native.setTenantId(tenantId);
|
|
367
|
+
this._tenantId = tenantId;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
onAuthStateChanged(
|
|
371
|
+
listenerOrObserver: CallbackOrObserver<FirebaseAuthTypes.AuthListenerCallback>,
|
|
372
|
+
): () => void {
|
|
373
|
+
const listener = parseListenerOrObserver(
|
|
374
|
+
listenerOrObserver,
|
|
375
|
+
) as FirebaseAuthTypes.AuthListenerCallback;
|
|
376
|
+
const subscription = this.emitter.addListener(
|
|
377
|
+
this.eventNameForApp('onAuthStateChanged'),
|
|
378
|
+
listener,
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
if (this._authResult) {
|
|
382
|
+
Promise.resolve().then(() => {
|
|
383
|
+
listener(this._user || null);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return () => subscription.remove();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
onIdTokenChanged(
|
|
390
|
+
listenerOrObserver: CallbackOrObserver<FirebaseAuthTypes.AuthListenerCallback>,
|
|
391
|
+
): () => void {
|
|
392
|
+
const listener = parseListenerOrObserver(
|
|
393
|
+
listenerOrObserver,
|
|
394
|
+
) as FirebaseAuthTypes.AuthListenerCallback;
|
|
395
|
+
const subscription = this.emitter.addListener(
|
|
396
|
+
this.eventNameForApp('onIdTokenChanged'),
|
|
397
|
+
listener,
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
if (this._authResult) {
|
|
401
|
+
Promise.resolve().then(() => {
|
|
402
|
+
listener(this._user || null);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
return () => subscription.remove();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
onUserChanged(
|
|
409
|
+
listenerOrObserver: CallbackOrObserver<FirebaseAuthTypes.AuthListenerCallback>,
|
|
410
|
+
): () => void {
|
|
411
|
+
const listener = parseListenerOrObserver(
|
|
412
|
+
listenerOrObserver,
|
|
413
|
+
) as FirebaseAuthTypes.AuthListenerCallback;
|
|
414
|
+
const subscription = this.emitter.addListener(this.eventNameForApp('onUserChanged'), listener);
|
|
415
|
+
if (this._authResult) {
|
|
416
|
+
Promise.resolve().then(() => {
|
|
417
|
+
listener(this._user || null);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return () => {
|
|
422
|
+
subscription.remove();
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
signOut(): Promise<void> {
|
|
427
|
+
return this.native.signOut().then(() => {
|
|
428
|
+
this._setUser(null);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
signInAnonymously(): Promise<FirebaseAuthTypes.UserCredential> {
|
|
433
|
+
return this.native
|
|
434
|
+
.signInAnonymously()
|
|
435
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
436
|
+
this._setUserCredential(userCredential),
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
signInWithPhoneNumber(
|
|
441
|
+
phoneNumber: string,
|
|
442
|
+
forceResend?: boolean,
|
|
443
|
+
): Promise<FirebaseAuthTypes.ConfirmationResult> {
|
|
444
|
+
if (isAndroid) {
|
|
445
|
+
return this.native
|
|
446
|
+
.signInWithPhoneNumber(phoneNumber, forceResend || false)
|
|
447
|
+
.then(
|
|
448
|
+
(result: NativePhoneAuthCredentialInternal) =>
|
|
449
|
+
new ConfirmationResult(this as unknown as AuthInternal, result.verificationId),
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return this.native
|
|
454
|
+
.signInWithPhoneNumber(phoneNumber)
|
|
455
|
+
.then(
|
|
456
|
+
(result: NativePhoneAuthCredentialInternal) =>
|
|
457
|
+
new ConfirmationResult(this as unknown as AuthInternal, result.verificationId),
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
verifyPhoneNumber(
|
|
462
|
+
phoneNumber: string,
|
|
463
|
+
autoVerifyTimeoutOrForceResend?: number | boolean,
|
|
464
|
+
forceResend?: boolean,
|
|
465
|
+
): FirebaseAuthTypes.PhoneAuthListener {
|
|
466
|
+
let _forceResend = forceResend;
|
|
467
|
+
let _autoVerifyTimeout: number | undefined = 60;
|
|
468
|
+
|
|
469
|
+
if (isBoolean(autoVerifyTimeoutOrForceResend)) {
|
|
470
|
+
_forceResend = autoVerifyTimeoutOrForceResend;
|
|
471
|
+
} else {
|
|
472
|
+
_autoVerifyTimeout = autoVerifyTimeoutOrForceResend;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return new PhoneAuthListener(
|
|
476
|
+
this as unknown as AuthInternal,
|
|
477
|
+
phoneNumber,
|
|
478
|
+
_autoVerifyTimeout,
|
|
479
|
+
_forceResend,
|
|
480
|
+
) as FirebaseAuthTypes.PhoneAuthListener;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
verifyPhoneNumberWithMultiFactorInfo(
|
|
484
|
+
multiFactorHint: FirebaseAuthTypes.MultiFactorInfo,
|
|
485
|
+
session: FirebaseAuthTypes.MultiFactorSession,
|
|
486
|
+
): Promise<string> {
|
|
487
|
+
return this.native.verifyPhoneNumberWithMultiFactorInfo(multiFactorHint.uid, session);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
verifyPhoneNumberForMultiFactor(
|
|
491
|
+
phoneInfoOptions: FirebaseAuthTypes.PhoneMultiFactorEnrollInfoOptions,
|
|
492
|
+
): Promise<string> {
|
|
493
|
+
const { phoneNumber, session } = phoneInfoOptions;
|
|
494
|
+
return this.native.verifyPhoneNumberForMultiFactor(phoneNumber, session);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
resolveMultiFactorSignIn(
|
|
498
|
+
session: FirebaseAuthTypes.MultiFactorSession,
|
|
499
|
+
verificationId: string,
|
|
500
|
+
verificationCode: string,
|
|
501
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
502
|
+
return this.native
|
|
503
|
+
.resolveMultiFactorSignIn(session, verificationId, verificationCode)
|
|
504
|
+
.then((userCredential: NativeUserCredentialInternal) => {
|
|
505
|
+
return this._setUserCredential(userCredential);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
resolveTotpSignIn(
|
|
510
|
+
session: FirebaseAuthTypes.MultiFactorSession,
|
|
511
|
+
uid: string,
|
|
512
|
+
totpSecret: string,
|
|
513
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
514
|
+
return this.native
|
|
515
|
+
.resolveTotpSignIn(session, uid, totpSecret)
|
|
516
|
+
.then((userCredential: NativeUserCredentialInternal) => {
|
|
517
|
+
return this._setUserCredential(userCredential);
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
createUserWithEmailAndPassword(
|
|
522
|
+
email: string,
|
|
523
|
+
password: string,
|
|
524
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
525
|
+
return (
|
|
526
|
+
this.native
|
|
527
|
+
.createUserWithEmailAndPassword(email, password)
|
|
528
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
529
|
+
this._setUserCredential(userCredential),
|
|
530
|
+
)
|
|
531
|
+
/* istanbul ignore next - native error handling cannot be unit tested */
|
|
532
|
+
.catch((error: AuthErrorWithCodeInternal) => {
|
|
533
|
+
if (error.code === 'auth/password-does-not-meet-requirements') {
|
|
534
|
+
return this._recachePasswordPolicy()
|
|
535
|
+
.catch(() => {
|
|
536
|
+
// Silently ignore recache failures - the original error matters more
|
|
537
|
+
})
|
|
538
|
+
.then(() => {
|
|
539
|
+
throw error;
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
throw error;
|
|
543
|
+
})
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
signInWithEmailAndPassword(
|
|
548
|
+
email: string,
|
|
549
|
+
password: string,
|
|
550
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
551
|
+
return (
|
|
552
|
+
this.native
|
|
553
|
+
.signInWithEmailAndPassword(email, password)
|
|
554
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
555
|
+
this._setUserCredential(userCredential),
|
|
556
|
+
)
|
|
557
|
+
/* istanbul ignore next - native error handling cannot be unit tested */
|
|
558
|
+
.catch((error: AuthErrorWithCodeInternal) => {
|
|
559
|
+
if (error.code === 'auth/password-does-not-meet-requirements') {
|
|
560
|
+
return this._recachePasswordPolicy()
|
|
561
|
+
.catch(() => {
|
|
562
|
+
// Silently ignore recache failures - the original error matters more
|
|
563
|
+
})
|
|
564
|
+
.then(() => {
|
|
565
|
+
throw error;
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
throw error;
|
|
569
|
+
})
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
signInWithCustomToken(customToken: string): Promise<FirebaseAuthTypes.UserCredential> {
|
|
574
|
+
return this.native
|
|
575
|
+
.signInWithCustomToken(customToken)
|
|
576
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
577
|
+
this._setUserCredential(userCredential),
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
signInWithCredential(
|
|
582
|
+
credential: FirebaseAuthTypes.AuthCredential,
|
|
583
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
584
|
+
return this.native
|
|
585
|
+
.signInWithCredential(credential.providerId, credential.token, credential.secret)
|
|
586
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
587
|
+
this._setUserCredential(userCredential),
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
revokeToken(authorizationCode: string): Promise<void> {
|
|
592
|
+
return this.native.revokeToken(authorizationCode);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
sendPasswordResetEmail(
|
|
596
|
+
email: string,
|
|
597
|
+
actionCodeSettings: FirebaseAuthTypes.ActionCodeSettings | null = null,
|
|
598
|
+
): Promise<void> {
|
|
599
|
+
return this.native.sendPasswordResetEmail(email, actionCodeSettings);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
private _resolveActionCodeSettings(
|
|
603
|
+
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings,
|
|
604
|
+
): FirebaseAuthTypes.ActionCodeSettings {
|
|
605
|
+
if (actionCodeSettings && isString(actionCodeSettings.url)) {
|
|
606
|
+
return actionCodeSettings;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const authDomain = this.app.options.authDomain;
|
|
610
|
+
let url = 'https://localhost';
|
|
611
|
+
if (authDomain && isString(authDomain)) {
|
|
612
|
+
url = isValidUrl(authDomain) ? authDomain : `https://${authDomain}`;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return {
|
|
616
|
+
...(actionCodeSettings ?? {}),
|
|
617
|
+
url,
|
|
618
|
+
handleCodeInApp: actionCodeSettings?.handleCodeInApp ?? true,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
sendSignInLinkToEmail(
|
|
623
|
+
email: string,
|
|
624
|
+
actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings,
|
|
625
|
+
): Promise<void> {
|
|
626
|
+
return this.native.sendSignInLinkToEmail(email, this._resolveActionCodeSettings(actionCodeSettings));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
isSignInWithEmailLink(emailLink: string): Promise<boolean> {
|
|
630
|
+
return this.native.isSignInWithEmailLink(emailLink);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
signInWithEmailLink(
|
|
634
|
+
email: string,
|
|
635
|
+
emailLink?: string,
|
|
636
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
637
|
+
return this.native
|
|
638
|
+
.signInWithEmailLink(email, emailLink ?? '')
|
|
639
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
640
|
+
this._setUserCredential(userCredential),
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
confirmPasswordReset(code: string, newPassword: string): Promise<void> {
|
|
645
|
+
return (
|
|
646
|
+
this.native
|
|
647
|
+
.confirmPasswordReset(code, newPassword)
|
|
648
|
+
/* istanbul ignore next - native error handling cannot be unit tested */
|
|
649
|
+
.catch((error: AuthErrorWithCodeInternal) => {
|
|
650
|
+
if (error.code === 'auth/password-does-not-meet-requirements') {
|
|
651
|
+
return this._recachePasswordPolicy()
|
|
652
|
+
.catch(() => {
|
|
653
|
+
// Silently ignore recache failures - the original error matters more
|
|
654
|
+
})
|
|
655
|
+
.then(() => {
|
|
656
|
+
throw error;
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
throw error;
|
|
660
|
+
})
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
applyActionCode(code: string): Promise<void> {
|
|
665
|
+
return this.native.applyActionCode(code).then(user => {
|
|
666
|
+
this._setUser(user);
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
checkActionCode(code: string): Promise<FirebaseAuthTypes.ActionCodeInfo> {
|
|
671
|
+
return this.native.checkActionCode(code);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
fetchSignInMethodsForEmail(email: string): Promise<string[]> {
|
|
675
|
+
return this.native.fetchSignInMethodsForEmail(email);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
verifyPasswordResetCode(code: string): Promise<string> {
|
|
679
|
+
return this.native.verifyPasswordResetCode(code);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
useUserAccessGroup(userAccessGroup: string): Promise<void> {
|
|
683
|
+
if (isAndroid) {
|
|
684
|
+
return Promise.resolve();
|
|
685
|
+
}
|
|
686
|
+
return this.native.useUserAccessGroup(userAccessGroup).then(() => undefined);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
getRedirectResult(): Promise<FirebaseAuthTypes.UserCredential | null> {
|
|
690
|
+
throw new Error(
|
|
691
|
+
'firebase.auth().getRedirectResult() is unsupported by the native Firebase SDKs.',
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
setPersistence(): Promise<void> {
|
|
696
|
+
throw new Error('firebase.auth().setPersistence() is unsupported by the native Firebase SDKs.');
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
signInWithPopup(
|
|
700
|
+
provider: FirebaseAuthTypes.AuthProvider,
|
|
701
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
702
|
+
return this.native
|
|
703
|
+
.signInWithProvider((provider as AuthProviderWithObjectInternal).toObject())
|
|
704
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
705
|
+
this._setUserCredential(userCredential),
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
signInWithRedirect(
|
|
710
|
+
provider: FirebaseAuthTypes.AuthProvider,
|
|
711
|
+
): Promise<FirebaseAuthTypes.UserCredential> {
|
|
712
|
+
return this.native
|
|
713
|
+
.signInWithProvider((provider as AuthProviderWithObjectInternal).toObject())
|
|
714
|
+
.then((userCredential: NativeUserCredentialInternal) =>
|
|
715
|
+
this._setUserCredential(userCredential),
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// firebase issue - https://github.com/invertase/react-native-firebase/pull/655#issuecomment-349904680
|
|
720
|
+
useDeviceLanguage(): void {
|
|
721
|
+
throw new Error(
|
|
722
|
+
'firebase.auth().useDeviceLanguage() is unsupported by the native Firebase SDKs.',
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
useEmulator(url: string, options?: { disableWarnings?: boolean }): void {
|
|
727
|
+
if (!url || !isString(url) || !isValidUrl(url)) {
|
|
728
|
+
throw new Error('firebase.auth().useEmulator() takes a non-empty string URL');
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
let _url = url;
|
|
732
|
+
const androidBypassEmulatorUrlRemap =
|
|
733
|
+
typeof this.firebaseJson.android_bypass_emulator_url_remap === 'boolean' &&
|
|
734
|
+
this.firebaseJson.android_bypass_emulator_url_remap;
|
|
735
|
+
if (!androidBypassEmulatorUrlRemap && isAndroid && _url) {
|
|
736
|
+
if (_url.startsWith('http://localhost')) {
|
|
737
|
+
_url = _url.replace('http://localhost', 'http://10.0.2.2');
|
|
738
|
+
// eslint-disable-next-line no-console
|
|
739
|
+
console.log(
|
|
740
|
+
'Mapping auth host "localhost" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.',
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
if (_url.startsWith('http://127.0.0.1')) {
|
|
744
|
+
_url = _url.replace('http://127.0.0.1', 'http://10.0.2.2');
|
|
745
|
+
// eslint-disable-next-line no-console
|
|
746
|
+
console.log(
|
|
747
|
+
'Mapping auth host "127.0.0.1" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.',
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// Native calls take the host and port split out
|
|
753
|
+
const hostPortRegex = /^http:\/\/([\w\d-.]+):(\d+)$/;
|
|
754
|
+
const urlMatches = _url.match(hostPortRegex);
|
|
755
|
+
if (!urlMatches) {
|
|
756
|
+
throw new Error('firebase.auth().useEmulator() unable to parse host and port from URL');
|
|
757
|
+
}
|
|
758
|
+
const host = urlMatches[1];
|
|
759
|
+
const portString = urlMatches[2];
|
|
760
|
+
if (!host) {
|
|
761
|
+
throw new Error('firebase.auth().useEmulator() unable to parse host from URL');
|
|
762
|
+
}
|
|
763
|
+
const port = portString ? parseInt(portString, 10) : undefined;
|
|
764
|
+
this._emulatorConfig = {
|
|
765
|
+
protocol: 'http',
|
|
766
|
+
host,
|
|
767
|
+
port: port ?? null,
|
|
768
|
+
options: {
|
|
769
|
+
disableWarnings: options?.disableWarnings ?? false,
|
|
770
|
+
},
|
|
771
|
+
};
|
|
772
|
+
this.native.useEmulator(host, port);
|
|
773
|
+
// @ts-ignore - undocumented return, useful for unit testing
|
|
774
|
+
return [host, port];
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
getMultiFactorResolver(
|
|
778
|
+
error: FirebaseAuthTypes.MultiFactorError,
|
|
779
|
+
): FirebaseAuthTypes.MultiFactorResolver {
|
|
780
|
+
return getMultiFactorResolver(
|
|
781
|
+
this as unknown as AuthInternal,
|
|
782
|
+
error,
|
|
783
|
+
) as FirebaseAuthTypes.MultiFactorResolver;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
multiFactor(user: FirebaseAuthTypes.User): FirebaseAuthTypes.MultiFactorUser {
|
|
787
|
+
if (!this.currentUser || user.uid !== this.currentUser.uid) {
|
|
788
|
+
throw new Error('firebase.auth().multiFactor() only operates on currentUser');
|
|
789
|
+
}
|
|
790
|
+
return new MultiFactorUser(
|
|
791
|
+
this as unknown as AuthInternal,
|
|
792
|
+
user,
|
|
793
|
+
) as FirebaseAuthTypes.MultiFactorUser;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
getCustomAuthDomain(): Promise<string> {
|
|
797
|
+
return this.native.getCustomAuthDomain();
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// Apply password policy mixin to FirebaseAuthModule
|
|
802
|
+
Object.assign(FirebaseAuthModule.prototype, PasswordPolicyMixin);
|
|
803
|
+
|
|
804
|
+
// import { SDK_VERSION } from '@react-native-firebase/auth';
|
|
805
|
+
export const SDK_VERSION = version;
|
|
806
|
+
|
|
807
|
+
const authNamespace = createModuleNamespace({
|
|
808
|
+
statics,
|
|
809
|
+
version,
|
|
810
|
+
namespace,
|
|
811
|
+
nativeModuleName,
|
|
812
|
+
nativeEvents,
|
|
813
|
+
hasMultiAppSupport: true,
|
|
814
|
+
hasCustomUrlOrRegionSupport: false,
|
|
815
|
+
ModuleClass: FirebaseAuthModule,
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
type AuthNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
|
|
819
|
+
FirebaseAuthTypes.Module,
|
|
820
|
+
FirebaseAuthTypes.Statics
|
|
821
|
+
> & {
|
|
822
|
+
auth: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
|
|
823
|
+
FirebaseAuthTypes.Module,
|
|
824
|
+
FirebaseAuthTypes.Statics
|
|
825
|
+
>;
|
|
826
|
+
firebase: ReactNativeFirebase.Module;
|
|
827
|
+
app(name?: string): ReactNativeFirebase.FirebaseApp;
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
// import auth from '@react-native-firebase/auth';
|
|
831
|
+
// auth().X(...);
|
|
832
|
+
export default authNamespace as unknown as AuthNamespace;
|
|
833
|
+
|
|
834
|
+
// import auth, { firebase } from '@react-native-firebase/auth';
|
|
835
|
+
// auth().X(...);
|
|
836
|
+
// firebase.auth().X(...);
|
|
837
|
+
export const firebase =
|
|
838
|
+
getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
|
|
839
|
+
'auth',
|
|
840
|
+
FirebaseAuthTypes.Module,
|
|
841
|
+
FirebaseAuthTypes.Statics,
|
|
842
|
+
false
|
|
843
|
+
>;
|
|
844
|
+
|
|
845
|
+
// Register the interop module for non-native platforms.
|
|
846
|
+
setReactNativeModule(nativeModuleName, fallBackModule);
|