@react-native-firebase/auth 24.1.1 → 25.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -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 +779 -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 +360 -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 +292 -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 +1158 -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 +474 -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
|
@@ -1,58 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
import { Platform } from 'react-native';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
onIdTokenChanged,
|
|
8
|
-
signInAnonymously,
|
|
9
|
-
sendSignInLinkToEmail,
|
|
10
|
-
getAdditionalUserInfo,
|
|
11
|
-
multiFactor,
|
|
12
|
-
getMultiFactorResolver,
|
|
13
|
-
TotpMultiFactorGenerator,
|
|
14
|
-
createUserWithEmailAndPassword,
|
|
15
|
-
signInWithEmailAndPassword,
|
|
16
|
-
isSignInWithEmailLink,
|
|
17
|
-
signInWithEmailLink,
|
|
18
|
-
signInWithCustomToken,
|
|
19
|
-
sendPasswordResetEmail,
|
|
20
|
-
useDeviceLanguage,
|
|
21
|
-
verifyPasswordResetCode,
|
|
22
|
-
connectAuthEmulator,
|
|
23
|
-
fetchSignInMethodsForEmail,
|
|
24
|
-
sendEmailVerification,
|
|
25
|
-
verifyBeforeUpdateEmail,
|
|
26
|
-
confirmPasswordReset,
|
|
27
|
-
updateEmail,
|
|
28
|
-
updatePassword,
|
|
29
|
-
updateProfile,
|
|
30
|
-
updatePhoneNumber,
|
|
31
|
-
signInWithCredential,
|
|
32
|
-
unlink,
|
|
33
|
-
linkWithCredential,
|
|
34
|
-
reauthenticateWithCredential,
|
|
35
|
-
getIdToken,
|
|
36
|
-
getIdTokenResult,
|
|
37
|
-
applyActionCode,
|
|
38
|
-
checkActionCode,
|
|
39
|
-
EmailAuthProvider,
|
|
40
|
-
FacebookAuthProvider,
|
|
41
|
-
GoogleAuthProvider,
|
|
42
|
-
TwitterAuthProvider,
|
|
43
|
-
GithubAuthProvider,
|
|
44
|
-
PhoneAuthProvider,
|
|
45
|
-
OAuthProvider,
|
|
46
|
-
} from '@react-native-firebase/app/dist/module/internal/web/firebaseAuth';
|
|
47
|
-
import {
|
|
48
|
-
guard,
|
|
49
|
-
getWebError,
|
|
50
|
-
emitEvent,
|
|
51
|
-
} from '@react-native-firebase/app/dist/module/internal/web/utils';
|
|
52
|
-
import {
|
|
53
|
-
getReactNativeAsyncStorageInternal,
|
|
54
|
-
isMemoryStorage,
|
|
55
|
-
} from '@react-native-firebase/app/dist/module/internal/asyncStorage';
|
|
4
|
+
import * as firebaseAuthModule from '@react-native-firebase/app/dist/module/internal/web/firebaseAuth';
|
|
5
|
+
import { getApp, initializeAuth, onAuthStateChanged, onIdTokenChanged, signInAnonymously, sendSignInLinkToEmail, getAdditionalUserInfo, multiFactor, getMultiFactorResolver, TotpMultiFactorGenerator, createUserWithEmailAndPassword, signInWithEmailAndPassword, isSignInWithEmailLink, signInWithEmailLink, signInWithCustomToken, sendPasswordResetEmail, useDeviceLanguage, verifyPasswordResetCode, connectAuthEmulator, fetchSignInMethodsForEmail, sendEmailVerification, verifyBeforeUpdateEmail, confirmPasswordReset, updateEmail, updatePassword, updateProfile, updatePhoneNumber, signInWithCredential, unlink, linkWithCredential, reauthenticateWithCredential, getIdToken, getIdTokenResult, applyActionCode, checkActionCode, EmailAuthProvider, FacebookAuthProvider, GoogleAuthProvider, TwitterAuthProvider, GithubAuthProvider, PhoneAuthProvider, OAuthProvider } from '@react-native-firebase/app/dist/module/internal/web/firebaseAuth';
|
|
6
|
+
import { guard, getWebError, emitEvent } from '@react-native-firebase/app/dist/module/internal/web/utils';
|
|
7
|
+
import { getReactNativeAsyncStorageInternal, isMemoryStorage } from '@react-native-firebase/app/dist/module/internal/asyncStorage';
|
|
8
|
+
const getReactNativePersistence = firebaseAuthModule.getReactNativePersistence ?? (storage => storage);
|
|
56
9
|
|
|
57
10
|
/**
|
|
58
11
|
* Resolves or rejects an auth method promise without a user (user was missing).
|
|
@@ -74,16 +27,18 @@ function promiseNoUser(isError = false) {
|
|
|
74
27
|
* @param {string} message - The error message.
|
|
75
28
|
*/
|
|
76
29
|
function rejectPromiseWithCodeAndMessage(code, message) {
|
|
77
|
-
return rejectPromise(getWebError({
|
|
30
|
+
return rejectPromise(getWebError({
|
|
31
|
+
name: 'FirebaseError',
|
|
32
|
+
code: `auth/${code}`,
|
|
33
|
+
message
|
|
34
|
+
}));
|
|
78
35
|
}
|
|
79
|
-
|
|
80
36
|
function rejectWithCodeAndMessage(code, message) {
|
|
81
|
-
return Promise.reject(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
);
|
|
37
|
+
return Promise.reject(getWebError({
|
|
38
|
+
name: 'FirebaseError',
|
|
39
|
+
code,
|
|
40
|
+
message
|
|
41
|
+
}));
|
|
87
42
|
}
|
|
88
43
|
|
|
89
44
|
/**
|
|
@@ -92,15 +47,19 @@ function rejectWithCodeAndMessage(code, message) {
|
|
|
92
47
|
* @returns {never}
|
|
93
48
|
*/
|
|
94
49
|
function rejectPromise(error) {
|
|
95
|
-
const {
|
|
96
|
-
const nativeError = {
|
|
50
|
+
const {
|
|
97
51
|
code,
|
|
98
52
|
message,
|
|
53
|
+
details
|
|
54
|
+
} = error;
|
|
55
|
+
const nativeError = {
|
|
56
|
+
code: code ?? 'auth/unknown',
|
|
57
|
+
message,
|
|
99
58
|
userInfo: {
|
|
100
59
|
code: code ? code.replace('auth/', '') : 'unknown',
|
|
101
60
|
message,
|
|
102
|
-
details
|
|
103
|
-
}
|
|
61
|
+
details
|
|
62
|
+
}
|
|
104
63
|
};
|
|
105
64
|
return Promise.reject(nativeError);
|
|
106
65
|
}
|
|
@@ -119,8 +78,8 @@ function userToObject(user) {
|
|
|
119
78
|
providerData: user.providerData.map(userInfoToObject),
|
|
120
79
|
metadata: userMetadataToObject(user.metadata),
|
|
121
80
|
multiFactor: {
|
|
122
|
-
enrolledFactors: multiFactor(user).enrolledFactors.map(multiFactorInfoToObject)
|
|
123
|
-
}
|
|
81
|
+
enrolledFactors: multiFactor(user).enrolledFactors.map(multiFactorInfoToObject)
|
|
82
|
+
}
|
|
124
83
|
};
|
|
125
84
|
}
|
|
126
85
|
|
|
@@ -135,35 +94,34 @@ function userToObject(user) {
|
|
|
135
94
|
function getAuthCredential(_auth, provider, token, secret) {
|
|
136
95
|
if (provider.startsWith('oidc.')) {
|
|
137
96
|
return new OAuthProvider(provider).credential({
|
|
138
|
-
idToken: token
|
|
97
|
+
idToken: token
|
|
139
98
|
});
|
|
140
99
|
}
|
|
141
|
-
|
|
142
100
|
switch (provider) {
|
|
143
101
|
case 'facebook.com':
|
|
144
|
-
return FacebookAuthProvider
|
|
102
|
+
return FacebookAuthProvider.credential(token);
|
|
145
103
|
case 'google.com':
|
|
146
|
-
return GoogleAuthProvider
|
|
104
|
+
return GoogleAuthProvider.credential(token, secret ?? null);
|
|
147
105
|
case 'twitter.com':
|
|
148
|
-
return TwitterAuthProvider
|
|
106
|
+
return TwitterAuthProvider.credential(token, secret ?? '');
|
|
149
107
|
case 'github.com':
|
|
150
|
-
return GithubAuthProvider
|
|
108
|
+
return GithubAuthProvider.credential(token);
|
|
151
109
|
case 'apple.com':
|
|
152
110
|
return new OAuthProvider(provider).credential({
|
|
153
111
|
idToken: token,
|
|
154
|
-
rawNonce: secret
|
|
112
|
+
rawNonce: secret ?? undefined
|
|
155
113
|
});
|
|
156
114
|
case 'oauth':
|
|
157
|
-
return OAuthProvider(provider).credential({
|
|
158
|
-
idToken: token,
|
|
159
|
-
accessToken: secret
|
|
115
|
+
return new OAuthProvider(provider).credential({
|
|
116
|
+
idToken: token || undefined,
|
|
117
|
+
accessToken: secret ?? undefined
|
|
160
118
|
});
|
|
161
119
|
case 'phone':
|
|
162
|
-
return PhoneAuthProvider.credential(token, secret);
|
|
120
|
+
return PhoneAuthProvider.credential(token, secret ?? '');
|
|
163
121
|
case 'password':
|
|
164
|
-
return EmailAuthProvider.credential(token, secret);
|
|
122
|
+
return EmailAuthProvider.credential(token, secret ?? '');
|
|
165
123
|
case 'emailLink':
|
|
166
|
-
return EmailAuthProvider.credentialWithLink(token, secret);
|
|
124
|
+
return EmailAuthProvider.credentialWithLink(token, secret ?? '');
|
|
167
125
|
default:
|
|
168
126
|
return null;
|
|
169
127
|
}
|
|
@@ -177,12 +135,10 @@ function userInfoToObject(userInfo) {
|
|
|
177
135
|
return {
|
|
178
136
|
providerId: userInfo.providerId,
|
|
179
137
|
uid: userInfo.uid,
|
|
180
|
-
displayName:
|
|
181
|
-
userInfo.displayName !== null && userInfo.displayName !== '' ? userInfo.displayName : null,
|
|
138
|
+
displayName: userInfo.displayName !== null && userInfo.displayName !== '' ? userInfo.displayName : null,
|
|
182
139
|
email: userInfo.email !== null && userInfo.email !== '' ? userInfo.email : null,
|
|
183
140
|
photoURL: userInfo.photoURL !== null && userInfo.photoURL !== '' ? userInfo.photoURL : null,
|
|
184
|
-
phoneNumber:
|
|
185
|
-
userInfo.phoneNumber !== null && userInfo.phoneNumber !== '' ? userInfo.phoneNumber : null,
|
|
141
|
+
phoneNumber: userInfo.phoneNumber !== null && userInfo.phoneNumber !== '' ? userInfo.phoneNumber : null
|
|
186
142
|
};
|
|
187
143
|
}
|
|
188
144
|
|
|
@@ -193,9 +149,7 @@ function userInfoToObject(userInfo) {
|
|
|
193
149
|
function userMetadataToObject(metadata) {
|
|
194
150
|
return {
|
|
195
151
|
creationTime: metadata.creationTime ? new Date(metadata.creationTime).toISOString() : null,
|
|
196
|
-
lastSignInTime: metadata.lastSignInTime
|
|
197
|
-
? new Date(metadata.lastSignInTime).toISOString()
|
|
198
|
-
: null,
|
|
152
|
+
lastSignInTime: metadata.lastSignInTime ? new Date(metadata.lastSignInTime).toISOString() : null
|
|
199
153
|
};
|
|
200
154
|
}
|
|
201
155
|
|
|
@@ -208,14 +162,13 @@ function multiFactorInfoToObject(multiFactorInfo) {
|
|
|
208
162
|
displayName: multiFactorInfo.displayName,
|
|
209
163
|
enrollmentTime: multiFactorInfo.enrollmentTime,
|
|
210
164
|
factorId: multiFactorInfo.factorId,
|
|
211
|
-
uid: multiFactorInfo.uid
|
|
165
|
+
uid: multiFactorInfo.uid
|
|
212
166
|
};
|
|
213
167
|
|
|
214
168
|
// If https://firebase.google.com/docs/reference/js/auth.phonemultifactorinfo
|
|
215
169
|
if ('phoneNumber' in multiFactorInfo) {
|
|
216
170
|
obj.phoneNumber = multiFactorInfo.phoneNumber;
|
|
217
171
|
}
|
|
218
|
-
|
|
219
172
|
return obj;
|
|
220
173
|
}
|
|
221
174
|
|
|
@@ -227,15 +180,14 @@ function authResultToObject(userCredential) {
|
|
|
227
180
|
const additional = getAdditionalUserInfo(userCredential);
|
|
228
181
|
return {
|
|
229
182
|
user: userToObject(userCredential.user),
|
|
230
|
-
additionalUserInfo: {
|
|
183
|
+
additionalUserInfo: additional ? {
|
|
231
184
|
isNewUser: additional.isNewUser,
|
|
232
|
-
profile: additional.profile,
|
|
185
|
+
profile: additional.profile ?? null,
|
|
233
186
|
providerId: additional.providerId,
|
|
234
|
-
username: additional.username
|
|
235
|
-
}
|
|
187
|
+
username: additional.username
|
|
188
|
+
} : null
|
|
236
189
|
};
|
|
237
190
|
}
|
|
238
|
-
|
|
239
191
|
const instances = {};
|
|
240
192
|
const authStateListeners = {};
|
|
241
193
|
const idTokenListeners = {};
|
|
@@ -249,22 +201,8 @@ function getCachedAuthInstance(appName) {
|
|
|
249
201
|
if (isMemoryStorage()) {
|
|
250
202
|
// Warn auth persistence is is disabled unless Async Storage implementation is provided.
|
|
251
203
|
// eslint-disable-next-line no-console
|
|
252
|
-
console.warn(
|
|
253
|
-
'Firebase Auth persistence is disabled. To enable persistence, provide an Async Storage implementation.\n' +
|
|
254
|
-
'\n' +
|
|
255
|
-
'For example, to use React Native Async Storage:\n' +
|
|
256
|
-
'\n' +
|
|
257
|
-
" import AsyncStorage from '@react-native-async-storage/async-storage';\n" +
|
|
258
|
-
'\n' +
|
|
259
|
-
' // Before initializing Firebase set the Async Storage implementation\n' +
|
|
260
|
-
' // that will be used to persist user sessions.\n' +
|
|
261
|
-
' firebase.setReactNativeAsyncStorage(AsyncStorage);\n' +
|
|
262
|
-
'\n' +
|
|
263
|
-
' // Then initialize Firebase as normal.\n' +
|
|
264
|
-
' await firebase.initializeApp({ ... });\n',
|
|
265
|
-
);
|
|
204
|
+
console.warn('Firebase Auth persistence is disabled. To enable persistence, provide an Async Storage implementation.\n' + '\n' + 'For example, to use React Native Async Storage:\n' + '\n' + " import AsyncStorage from '@react-native-async-storage/async-storage';\n" + '\n' + ' // Before initializing Firebase set the Async Storage implementation\n' + ' // that will be used to persist user sessions.\n' + ' firebase.setReactNativeAsyncStorage(AsyncStorage);\n' + '\n' + ' // Then initialize Firebase as normal.\n' + ' await firebase.initializeApp({ ... });\n');
|
|
266
205
|
}
|
|
267
|
-
|
|
268
206
|
const authOptions = {};
|
|
269
207
|
if (Platform.OS !== 'web') {
|
|
270
208
|
// Non-web platforms pull the react-native export from package.json and
|
|
@@ -272,7 +210,6 @@ function getCachedAuthInstance(appName) {
|
|
|
272
210
|
// do *not* have that method defined. So we only call it for non-web platforms
|
|
273
211
|
authOptions.persistence = getReactNativePersistence(getReactNativeAsyncStorageInternal());
|
|
274
212
|
}
|
|
275
|
-
|
|
276
213
|
instances[appName] = initializeAuth(getApp(appName), authOptions);
|
|
277
214
|
}
|
|
278
215
|
return instances[appName];
|
|
@@ -281,7 +218,7 @@ function getCachedAuthInstance(appName) {
|
|
|
281
218
|
// getConstants
|
|
282
219
|
const CONSTANTS = {
|
|
283
220
|
APP_LANGUAGE: {},
|
|
284
|
-
APP_USER: {}
|
|
221
|
+
APP_USER: {}
|
|
285
222
|
};
|
|
286
223
|
|
|
287
224
|
// Not required for web, since it's dynamic initialization
|
|
@@ -304,25 +241,15 @@ const CONSTANTS = {
|
|
|
304
241
|
export default {
|
|
305
242
|
// Expose all the constants.
|
|
306
243
|
...CONSTANTS,
|
|
307
|
-
|
|
308
244
|
async useUserAccessGroup() {
|
|
309
245
|
// noop
|
|
310
246
|
},
|
|
311
|
-
|
|
312
247
|
configureAuthDomain() {
|
|
313
|
-
return rejectPromiseWithCodeAndMessage(
|
|
314
|
-
'unsupported',
|
|
315
|
-
'This operation is not supported in this environment.',
|
|
316
|
-
);
|
|
248
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
317
249
|
},
|
|
318
|
-
|
|
319
250
|
async getCustomAuthDomain() {
|
|
320
|
-
return rejectPromiseWithCodeAndMessage(
|
|
321
|
-
'unsupported',
|
|
322
|
-
'This operation is not supported in this environment.',
|
|
323
|
-
);
|
|
251
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
324
252
|
},
|
|
325
|
-
|
|
326
253
|
/**
|
|
327
254
|
* Create a new auth state listener instance for a given app.
|
|
328
255
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -332,19 +259,16 @@ export default {
|
|
|
332
259
|
if (authStateListeners[appName]) {
|
|
333
260
|
return;
|
|
334
261
|
}
|
|
335
|
-
|
|
336
262
|
return guard(async () => {
|
|
337
263
|
const auth = getCachedAuthInstance(appName);
|
|
338
|
-
|
|
339
264
|
authStateListeners[appName] = onAuthStateChanged(auth, user => {
|
|
340
265
|
emitEvent('auth_state_changed', {
|
|
341
266
|
appName,
|
|
342
|
-
user: user ? userToObject(user) : null
|
|
267
|
+
user: user ? userToObject(user) : null
|
|
343
268
|
});
|
|
344
269
|
});
|
|
345
270
|
});
|
|
346
271
|
},
|
|
347
|
-
|
|
348
272
|
/**
|
|
349
273
|
* Remove an auth state listener instance for a given app.
|
|
350
274
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -356,7 +280,6 @@ export default {
|
|
|
356
280
|
delete authStateListeners[appName];
|
|
357
281
|
}
|
|
358
282
|
},
|
|
359
|
-
|
|
360
283
|
/**
|
|
361
284
|
* Create a new ID token listener instance for a given app.
|
|
362
285
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -366,20 +289,17 @@ export default {
|
|
|
366
289
|
if (idTokenListeners[appName]) {
|
|
367
290
|
return;
|
|
368
291
|
}
|
|
369
|
-
|
|
370
292
|
return guard(async () => {
|
|
371
293
|
const auth = getCachedAuthInstance(appName);
|
|
372
|
-
|
|
373
294
|
idTokenListeners[appName] = onIdTokenChanged(auth, user => {
|
|
374
295
|
emitEvent('auth_id_token_changed', {
|
|
375
296
|
authenticated: !!user,
|
|
376
297
|
appName,
|
|
377
|
-
user: user ? userToObject(user) : null
|
|
298
|
+
user: user ? userToObject(user) : null
|
|
378
299
|
});
|
|
379
300
|
});
|
|
380
301
|
});
|
|
381
302
|
},
|
|
382
|
-
|
|
383
303
|
/**
|
|
384
304
|
* Remove an ID token listener instance for a given app.
|
|
385
305
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -391,28 +311,15 @@ export default {
|
|
|
391
311
|
delete idTokenListeners[appName];
|
|
392
312
|
}
|
|
393
313
|
},
|
|
394
|
-
|
|
395
314
|
async forceRecaptchaFlowForTesting() {
|
|
396
|
-
return rejectPromiseWithCodeAndMessage(
|
|
397
|
-
'unsupported',
|
|
398
|
-
'This operation is not supported in this environment.',
|
|
399
|
-
);
|
|
315
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
400
316
|
},
|
|
401
|
-
|
|
402
317
|
async setAutoRetrievedSmsCodeForPhoneNumber() {
|
|
403
|
-
return rejectPromiseWithCodeAndMessage(
|
|
404
|
-
'unsupported',
|
|
405
|
-
'This operation is not supported in this environment.',
|
|
406
|
-
);
|
|
318
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
407
319
|
},
|
|
408
|
-
|
|
409
320
|
async setAppVerificationDisabledForTesting() {
|
|
410
|
-
return rejectPromiseWithCodeAndMessage(
|
|
411
|
-
'unsupported',
|
|
412
|
-
'This operation is not supported in this environment.',
|
|
413
|
-
);
|
|
321
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
414
322
|
},
|
|
415
|
-
|
|
416
323
|
/**
|
|
417
324
|
* Sign out the current user.
|
|
418
325
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -421,16 +328,13 @@ export default {
|
|
|
421
328
|
signOut(appName) {
|
|
422
329
|
return guard(async () => {
|
|
423
330
|
const auth = getCachedAuthInstance(appName);
|
|
424
|
-
|
|
425
331
|
if (auth.currentUser === null) {
|
|
426
332
|
return promiseNoUser(true);
|
|
427
333
|
}
|
|
428
|
-
|
|
429
334
|
await auth.signOut();
|
|
430
335
|
return promiseNoUser();
|
|
431
336
|
});
|
|
432
337
|
},
|
|
433
|
-
|
|
434
338
|
/**
|
|
435
339
|
* Sign in anonymously.
|
|
436
340
|
* @param {*} appName - The name of the app to get the auth instance for.
|
|
@@ -443,7 +347,6 @@ export default {
|
|
|
443
347
|
return authResultToObject(credential);
|
|
444
348
|
});
|
|
445
349
|
},
|
|
446
|
-
|
|
447
350
|
/**
|
|
448
351
|
* Sign in with email and password.
|
|
449
352
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -458,7 +361,6 @@ export default {
|
|
|
458
361
|
return authResultToObject(credential);
|
|
459
362
|
});
|
|
460
363
|
},
|
|
461
|
-
|
|
462
364
|
/**
|
|
463
365
|
* Sign in with email and password.
|
|
464
366
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -474,23 +376,19 @@ export default {
|
|
|
474
376
|
// later if needed. So we handle the error custom here.
|
|
475
377
|
// return guard(async () => {
|
|
476
378
|
try {
|
|
477
|
-
const credential = await signInWithEmailAndPassword(
|
|
478
|
-
getCachedAuthInstance(appName),
|
|
479
|
-
email,
|
|
480
|
-
password,
|
|
481
|
-
);
|
|
379
|
+
const credential = await signInWithEmailAndPassword(getCachedAuthInstance(appName), email, password);
|
|
482
380
|
return authResultToObject(credential);
|
|
483
381
|
} catch (e) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
382
|
+
const error = e;
|
|
383
|
+
error.userInfo = {
|
|
384
|
+
code: error.code?.split('/')[1] ?? 'unknown',
|
|
385
|
+
message: error.message,
|
|
386
|
+
customData: error.customData
|
|
488
387
|
};
|
|
489
|
-
throw
|
|
388
|
+
throw error;
|
|
490
389
|
}
|
|
491
390
|
// });
|
|
492
391
|
},
|
|
493
|
-
|
|
494
392
|
/**
|
|
495
393
|
* Check if a sign in with email link is valid
|
|
496
394
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -503,7 +401,6 @@ export default {
|
|
|
503
401
|
return await isSignInWithEmailLink(auth, emailLink);
|
|
504
402
|
});
|
|
505
403
|
},
|
|
506
|
-
|
|
507
404
|
/**
|
|
508
405
|
* Sign in with email link.
|
|
509
406
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -518,7 +415,6 @@ export default {
|
|
|
518
415
|
return authResultToObject(credential);
|
|
519
416
|
});
|
|
520
417
|
},
|
|
521
|
-
|
|
522
418
|
/**
|
|
523
419
|
* Sign in with a custom token.
|
|
524
420
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -532,14 +428,12 @@ export default {
|
|
|
532
428
|
return authResultToObject(credential);
|
|
533
429
|
});
|
|
534
430
|
},
|
|
535
|
-
|
|
536
431
|
/**
|
|
537
432
|
* Not implemented on web.
|
|
538
433
|
*/
|
|
539
434
|
async revokeToken() {
|
|
540
435
|
return promiseNoUser();
|
|
541
436
|
},
|
|
542
|
-
|
|
543
437
|
/**
|
|
544
438
|
* Send a password reset email.
|
|
545
439
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -554,7 +448,6 @@ export default {
|
|
|
554
448
|
return promiseNoUser();
|
|
555
449
|
});
|
|
556
450
|
},
|
|
557
|
-
|
|
558
451
|
/**
|
|
559
452
|
* Send a sign in link to an email.
|
|
560
453
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -569,7 +462,6 @@ export default {
|
|
|
569
462
|
return promiseNoUser();
|
|
570
463
|
});
|
|
571
464
|
},
|
|
572
|
-
|
|
573
465
|
/* ----------------------
|
|
574
466
|
* .currentUser methods
|
|
575
467
|
* ---------------------- */
|
|
@@ -582,16 +474,13 @@ export default {
|
|
|
582
474
|
async delete(appName) {
|
|
583
475
|
return guard(async () => {
|
|
584
476
|
const auth = getCachedAuthInstance(appName);
|
|
585
|
-
|
|
586
477
|
if (auth.currentUser === null) {
|
|
587
478
|
return promiseNoUser(true);
|
|
588
479
|
}
|
|
589
|
-
|
|
590
480
|
await auth.currentUser.delete();
|
|
591
481
|
return promiseNoUser();
|
|
592
482
|
});
|
|
593
483
|
},
|
|
594
|
-
|
|
595
484
|
/**
|
|
596
485
|
* Reload the current user.
|
|
597
486
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -600,16 +489,13 @@ export default {
|
|
|
600
489
|
async reload(appName) {
|
|
601
490
|
return guard(async () => {
|
|
602
491
|
const auth = getCachedAuthInstance(appName);
|
|
603
|
-
|
|
604
492
|
if (auth.currentUser === null) {
|
|
605
493
|
return promiseNoUser(true);
|
|
606
494
|
}
|
|
607
|
-
|
|
608
495
|
await auth.currentUser.reload();
|
|
609
496
|
return userToObject(auth.currentUser);
|
|
610
497
|
});
|
|
611
498
|
},
|
|
612
|
-
|
|
613
499
|
/**
|
|
614
500
|
* Send a verification email to the current user.
|
|
615
501
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -619,16 +505,13 @@ export default {
|
|
|
619
505
|
async sendEmailVerification(appName, actionCodeSettings) {
|
|
620
506
|
return guard(async () => {
|
|
621
507
|
const auth = getCachedAuthInstance(appName);
|
|
622
|
-
|
|
623
508
|
if (auth.currentUser === null) {
|
|
624
509
|
return promiseNoUser(true);
|
|
625
510
|
}
|
|
626
|
-
|
|
627
511
|
await sendEmailVerification(auth.currentUser, actionCodeSettings);
|
|
628
512
|
return userToObject(auth.currentUser);
|
|
629
513
|
});
|
|
630
514
|
},
|
|
631
|
-
|
|
632
515
|
/**
|
|
633
516
|
* Verify the email before updating it.
|
|
634
517
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -639,16 +522,13 @@ export default {
|
|
|
639
522
|
async verifyBeforeUpdateEmail(appName, email, actionCodeSettings) {
|
|
640
523
|
return guard(async () => {
|
|
641
524
|
const auth = getCachedAuthInstance(appName);
|
|
642
|
-
|
|
643
525
|
if (auth.currentUser === null) {
|
|
644
526
|
return promiseNoUser(true);
|
|
645
527
|
}
|
|
646
|
-
|
|
647
528
|
await verifyBeforeUpdateEmail(auth.currentUser, email, actionCodeSettings);
|
|
648
529
|
return userToObject(auth.currentUser);
|
|
649
530
|
});
|
|
650
531
|
},
|
|
651
|
-
|
|
652
532
|
/**
|
|
653
533
|
* Update the current user's email.
|
|
654
534
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -658,16 +538,13 @@ export default {
|
|
|
658
538
|
async updateEmail(appName, email) {
|
|
659
539
|
return guard(async () => {
|
|
660
540
|
const auth = getCachedAuthInstance(appName);
|
|
661
|
-
|
|
662
541
|
if (auth.currentUser === null) {
|
|
663
542
|
return promiseNoUser(true);
|
|
664
543
|
}
|
|
665
|
-
|
|
666
544
|
await updateEmail(auth.currentUser, email);
|
|
667
545
|
return userToObject(auth.currentUser);
|
|
668
546
|
});
|
|
669
547
|
},
|
|
670
|
-
|
|
671
548
|
/**
|
|
672
549
|
* Update the current user's password.
|
|
673
550
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -677,16 +554,13 @@ export default {
|
|
|
677
554
|
async updatePassword(appName, password) {
|
|
678
555
|
return guard(async () => {
|
|
679
556
|
const auth = getCachedAuthInstance(appName);
|
|
680
|
-
|
|
681
557
|
if (auth.currentUser === null) {
|
|
682
558
|
return promiseNoUser(true);
|
|
683
559
|
}
|
|
684
|
-
|
|
685
560
|
await updatePassword(auth.currentUser, password);
|
|
686
561
|
return userToObject(auth.currentUser);
|
|
687
562
|
});
|
|
688
563
|
},
|
|
689
|
-
|
|
690
564
|
/**
|
|
691
565
|
* Update the current user's phone number.
|
|
692
566
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -698,33 +572,20 @@ export default {
|
|
|
698
572
|
async updatePhoneNumber(appName, provider, authToken, authSecret) {
|
|
699
573
|
return guard(async () => {
|
|
700
574
|
const auth = getCachedAuthInstance(appName);
|
|
701
|
-
|
|
702
575
|
if (auth.currentUser === null) {
|
|
703
576
|
return promiseNoUser(true);
|
|
704
577
|
}
|
|
705
|
-
|
|
706
578
|
if (provider !== 'phone') {
|
|
707
|
-
return rejectPromiseWithCodeAndMessage(
|
|
708
|
-
'invalid-credential',
|
|
709
|
-
'The supplied auth credential does not have a phone provider.',
|
|
710
|
-
);
|
|
579
|
+
return rejectPromiseWithCodeAndMessage('invalid-credential', 'The supplied auth credential does not have a phone provider.');
|
|
711
580
|
}
|
|
712
|
-
|
|
713
581
|
const credential = getAuthCredential(auth, provider, authToken, authSecret);
|
|
714
|
-
|
|
715
582
|
if (!credential) {
|
|
716
|
-
return rejectPromiseWithCodeAndMessage(
|
|
717
|
-
'invalid-credential',
|
|
718
|
-
'The supplied auth credential is malformed, has expired or is not currently supported.',
|
|
719
|
-
);
|
|
583
|
+
return rejectPromiseWithCodeAndMessage('invalid-credential', 'The supplied auth credential is malformed, has expired or is not currently supported.');
|
|
720
584
|
}
|
|
721
|
-
|
|
722
585
|
await updatePhoneNumber(auth.currentUser, credential);
|
|
723
|
-
|
|
724
586
|
return userToObject(auth.currentUser);
|
|
725
587
|
});
|
|
726
588
|
},
|
|
727
|
-
|
|
728
589
|
/**
|
|
729
590
|
* Update the current user's profile.
|
|
730
591
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -734,20 +595,16 @@ export default {
|
|
|
734
595
|
async updateProfile(appName, props) {
|
|
735
596
|
return guard(async () => {
|
|
736
597
|
const auth = getCachedAuthInstance(appName);
|
|
737
|
-
|
|
738
598
|
if (auth.currentUser === null) {
|
|
739
599
|
return promiseNoUser(true);
|
|
740
600
|
}
|
|
741
|
-
|
|
742
601
|
await updateProfile(auth.currentUser, {
|
|
743
602
|
displayName: props.displayName,
|
|
744
|
-
photoURL: props.photoURL
|
|
603
|
+
photoURL: props.photoURL
|
|
745
604
|
});
|
|
746
|
-
|
|
747
605
|
return userToObject(auth.currentUser);
|
|
748
606
|
});
|
|
749
607
|
},
|
|
750
|
-
|
|
751
608
|
/**
|
|
752
609
|
* Sign in with a credential.
|
|
753
610
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -760,33 +617,19 @@ export default {
|
|
|
760
617
|
return guard(async () => {
|
|
761
618
|
const auth = getCachedAuthInstance(appName);
|
|
762
619
|
const credential = getAuthCredential(auth, provider, authToken, authSecret);
|
|
763
|
-
|
|
764
620
|
if (credential === null) {
|
|
765
|
-
return rejectPromiseWithCodeAndMessage(
|
|
766
|
-
'invalid-credential',
|
|
767
|
-
'The supplied auth credential is malformed, has expired or is not currently supported.',
|
|
768
|
-
);
|
|
621
|
+
return rejectPromiseWithCodeAndMessage('invalid-credential', 'The supplied auth credential is malformed, has expired or is not currently supported.');
|
|
769
622
|
}
|
|
770
|
-
|
|
771
623
|
const credentialResult = await signInWithCredential(auth, credential);
|
|
772
624
|
return authResultToObject(credentialResult);
|
|
773
625
|
});
|
|
774
626
|
},
|
|
775
|
-
|
|
776
627
|
async signInWithProvider() {
|
|
777
|
-
return rejectPromiseWithCodeAndMessage(
|
|
778
|
-
'unsupported',
|
|
779
|
-
'This operation is not supported in this environment.',
|
|
780
|
-
);
|
|
628
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
781
629
|
},
|
|
782
|
-
|
|
783
630
|
async signInWithPhoneNumber() {
|
|
784
|
-
return rejectPromiseWithCodeAndMessage(
|
|
785
|
-
'unsupported',
|
|
786
|
-
'This operation is not supported in this environment.',
|
|
787
|
-
);
|
|
631
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
788
632
|
},
|
|
789
|
-
|
|
790
633
|
/**
|
|
791
634
|
* Get a multi-factor session.
|
|
792
635
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -795,57 +638,33 @@ export default {
|
|
|
795
638
|
async getSession(appName) {
|
|
796
639
|
return guard(async () => {
|
|
797
640
|
const auth = getCachedAuthInstance(appName);
|
|
798
|
-
|
|
799
641
|
if (auth.currentUser === null) {
|
|
800
642
|
return promiseNoUser(true);
|
|
801
643
|
}
|
|
802
|
-
|
|
803
644
|
const session = await multiFactor(auth.currentUser).getSession();
|
|
804
645
|
|
|
805
646
|
// Increment the session ID.
|
|
806
647
|
sessionId++;
|
|
807
|
-
|
|
808
648
|
const key = `${sessionId}`;
|
|
809
649
|
sessionMap.set(key, session);
|
|
810
650
|
return key;
|
|
811
651
|
});
|
|
812
652
|
},
|
|
813
|
-
|
|
814
653
|
verifyPhoneNumberForMultiFactor() {
|
|
815
|
-
return rejectPromiseWithCodeAndMessage(
|
|
816
|
-
'unsupported',
|
|
817
|
-
'This operation is not supported in this environment.',
|
|
818
|
-
);
|
|
654
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
819
655
|
},
|
|
820
|
-
|
|
821
656
|
finalizeMultiFactorEnrollment() {
|
|
822
|
-
return rejectPromiseWithCodeAndMessage(
|
|
823
|
-
'unsupported',
|
|
824
|
-
'This operation is not supported in this environment.',
|
|
825
|
-
);
|
|
657
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
826
658
|
},
|
|
827
|
-
|
|
828
659
|
resolveMultiFactorSignIn() {
|
|
829
|
-
return rejectPromiseWithCodeAndMessage(
|
|
830
|
-
'unsupported',
|
|
831
|
-
'This operation is not supported in this environment.',
|
|
832
|
-
);
|
|
660
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
833
661
|
},
|
|
834
|
-
|
|
835
662
|
confirmationResultConfirm() {
|
|
836
|
-
return rejectPromiseWithCodeAndMessage(
|
|
837
|
-
'unsupported',
|
|
838
|
-
'This operation is not supported in this environment.',
|
|
839
|
-
);
|
|
663
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
840
664
|
},
|
|
841
|
-
|
|
842
665
|
verifyPhoneNumber() {
|
|
843
|
-
return rejectPromiseWithCodeAndMessage(
|
|
844
|
-
'unsupported',
|
|
845
|
-
'This operation is not supported in this environment.',
|
|
846
|
-
);
|
|
666
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
847
667
|
},
|
|
848
|
-
|
|
849
668
|
/**
|
|
850
669
|
* Confirm the password reset code.
|
|
851
670
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -860,7 +679,6 @@ export default {
|
|
|
860
679
|
return promiseNoUser();
|
|
861
680
|
});
|
|
862
681
|
},
|
|
863
|
-
|
|
864
682
|
/**
|
|
865
683
|
* Apply an action code.
|
|
866
684
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -873,7 +691,6 @@ export default {
|
|
|
873
691
|
await applyActionCode(auth, code);
|
|
874
692
|
});
|
|
875
693
|
},
|
|
876
|
-
|
|
877
694
|
/**
|
|
878
695
|
* Check an action code.
|
|
879
696
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -884,18 +701,16 @@ export default {
|
|
|
884
701
|
return guard(async () => {
|
|
885
702
|
const auth = getCachedAuthInstance(appName);
|
|
886
703
|
const result = await checkActionCode(auth, code);
|
|
887
|
-
|
|
888
704
|
return {
|
|
889
705
|
operation: result.operation,
|
|
890
706
|
data: {
|
|
891
707
|
email: result.data.email,
|
|
892
|
-
fromEmail: result.data.previousEmail
|
|
708
|
+
fromEmail: result.data.previousEmail
|
|
893
709
|
// multiFactorInfo - not implemented
|
|
894
|
-
}
|
|
710
|
+
}
|
|
895
711
|
};
|
|
896
712
|
});
|
|
897
713
|
},
|
|
898
|
-
|
|
899
714
|
/**
|
|
900
715
|
* Link a credential to the current user.
|
|
901
716
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -908,30 +723,19 @@ export default {
|
|
|
908
723
|
return guard(async () => {
|
|
909
724
|
const auth = getCachedAuthInstance(appName);
|
|
910
725
|
const credential = getAuthCredential(auth, provider, authToken, authSecret);
|
|
911
|
-
|
|
912
726
|
if (credential === null) {
|
|
913
|
-
return rejectPromiseWithCodeAndMessage(
|
|
914
|
-
'invalid-credential',
|
|
915
|
-
'The supplied auth credential is malformed, has expired or is not currently supported.',
|
|
916
|
-
);
|
|
727
|
+
return rejectPromiseWithCodeAndMessage('invalid-credential', 'The supplied auth credential is malformed, has expired or is not currently supported.');
|
|
917
728
|
}
|
|
918
|
-
|
|
919
729
|
if (auth.currentUser === null) {
|
|
920
730
|
return promiseNoUser(true);
|
|
921
731
|
}
|
|
922
|
-
|
|
923
732
|
return authResultToObject(await linkWithCredential(auth.currentUser, credential));
|
|
924
733
|
});
|
|
925
734
|
},
|
|
926
|
-
|
|
927
735
|
async linkWithProvider() {
|
|
928
736
|
// TODO: We could check if window is available here, but for now it's not supported.
|
|
929
|
-
return rejectPromiseWithCodeAndMessage(
|
|
930
|
-
'unsupported',
|
|
931
|
-
'This operation is not supported in this environment.',
|
|
932
|
-
);
|
|
737
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
933
738
|
},
|
|
934
|
-
|
|
935
739
|
/**
|
|
936
740
|
* Unlink a provider from the current user.
|
|
937
741
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -941,16 +745,13 @@ export default {
|
|
|
941
745
|
async unlink(appName, providerId) {
|
|
942
746
|
return guard(async () => {
|
|
943
747
|
const auth = getCachedAuthInstance(appName);
|
|
944
|
-
|
|
945
748
|
if (auth.currentUser === null) {
|
|
946
749
|
return promiseNoUser(true);
|
|
947
750
|
}
|
|
948
|
-
|
|
949
751
|
const user = await unlink(auth.currentUser, providerId);
|
|
950
752
|
return userToObject(user);
|
|
951
753
|
});
|
|
952
754
|
},
|
|
953
|
-
|
|
954
755
|
/**
|
|
955
756
|
* Reauthenticate with a credential.
|
|
956
757
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -963,30 +764,19 @@ export default {
|
|
|
963
764
|
return guard(async () => {
|
|
964
765
|
const auth = getCachedAuthInstance(appName);
|
|
965
766
|
const credential = getAuthCredential(auth, provider, authToken, authSecret);
|
|
966
|
-
|
|
967
767
|
if (credential === null) {
|
|
968
|
-
return rejectPromiseWithCodeAndMessage(
|
|
969
|
-
'invalid-credential',
|
|
970
|
-
'The supplied auth credential is malformed, has expired or is not currently supported.',
|
|
971
|
-
);
|
|
768
|
+
return rejectPromiseWithCodeAndMessage('invalid-credential', 'The supplied auth credential is malformed, has expired or is not currently supported.');
|
|
972
769
|
}
|
|
973
|
-
|
|
974
770
|
if (auth.currentUser === null) {
|
|
975
771
|
return promiseNoUser(true);
|
|
976
772
|
}
|
|
977
|
-
|
|
978
773
|
return authResultToObject(await reauthenticateWithCredential(auth.currentUser, credential));
|
|
979
774
|
});
|
|
980
775
|
},
|
|
981
|
-
|
|
982
776
|
async reauthenticateWithProvider() {
|
|
983
777
|
// TODO: We could check if window is available here, but for now it's not supported.
|
|
984
|
-
return rejectPromiseWithCodeAndMessage(
|
|
985
|
-
'unsupported',
|
|
986
|
-
'This operation is not supported in this environment.',
|
|
987
|
-
);
|
|
778
|
+
return rejectPromiseWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
988
779
|
},
|
|
989
|
-
|
|
990
780
|
/**
|
|
991
781
|
* Get the ID token for the current user.
|
|
992
782
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -996,16 +786,13 @@ export default {
|
|
|
996
786
|
async getIdToken(appName, forceRefresh) {
|
|
997
787
|
return guard(async () => {
|
|
998
788
|
const auth = getCachedAuthInstance(appName);
|
|
999
|
-
|
|
1000
789
|
if (auth.currentUser === null) {
|
|
1001
790
|
return promiseNoUser(true);
|
|
1002
791
|
}
|
|
1003
|
-
|
|
1004
792
|
const token = await getIdToken(auth.currentUser, forceRefresh);
|
|
1005
793
|
return token;
|
|
1006
794
|
});
|
|
1007
795
|
},
|
|
1008
|
-
|
|
1009
796
|
/**
|
|
1010
797
|
* Get the ID token result for the current user.
|
|
1011
798
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -1015,11 +802,9 @@ export default {
|
|
|
1015
802
|
async getIdTokenResult(appName, forceRefresh) {
|
|
1016
803
|
return guard(async () => {
|
|
1017
804
|
const auth = getCachedAuthInstance(appName);
|
|
1018
|
-
|
|
1019
805
|
if (auth.currentUser === null) {
|
|
1020
806
|
return promiseNoUser(true);
|
|
1021
807
|
}
|
|
1022
|
-
|
|
1023
808
|
const result = await getIdTokenResult(auth.currentUser, forceRefresh);
|
|
1024
809
|
|
|
1025
810
|
// TODO(ehesp): Result looks expected, might be safer to keep fixed object?
|
|
@@ -1029,11 +814,10 @@ export default {
|
|
|
1029
814
|
issuedAtTime: result.issuedAtTime,
|
|
1030
815
|
claims: result.claims,
|
|
1031
816
|
signInProvider: result.signInProvider,
|
|
1032
|
-
token: result.token
|
|
817
|
+
token: result.token
|
|
1033
818
|
};
|
|
1034
819
|
});
|
|
1035
820
|
},
|
|
1036
|
-
|
|
1037
821
|
/**
|
|
1038
822
|
* Get a MultiFactorResolver from the underlying SDK
|
|
1039
823
|
* @param {*} _appName the name of the app to get the auth instance for
|
|
@@ -1044,7 +828,6 @@ export default {
|
|
|
1044
828
|
assertionForSignIn(_appName, uid, code) {
|
|
1045
829
|
return TotpMultiFactorGenerator.assertionForSignIn(uid, code);
|
|
1046
830
|
},
|
|
1047
|
-
|
|
1048
831
|
/**
|
|
1049
832
|
* Get a MultiFactorResolver from the underlying SDK
|
|
1050
833
|
* @param {*} appName the name of the app to get the auth instance for
|
|
@@ -1054,7 +837,6 @@ export default {
|
|
|
1054
837
|
getMultiFactorResolver(appName, error) {
|
|
1055
838
|
return getMultiFactorResolver(getCachedAuthInstance(appName), error);
|
|
1056
839
|
},
|
|
1057
|
-
|
|
1058
840
|
/**
|
|
1059
841
|
* generate a TOTP secret
|
|
1060
842
|
* @param {*} _appName - The name of the app to get the auth instance for.
|
|
@@ -1063,12 +845,17 @@ export default {
|
|
|
1063
845
|
*/
|
|
1064
846
|
async generateTotpSecret(_appName, session) {
|
|
1065
847
|
return guard(async () => {
|
|
1066
|
-
const
|
|
848
|
+
const mappedSession = sessionMap.get(session);
|
|
849
|
+
if (!mappedSession) {
|
|
850
|
+
return rejectPromiseWithCodeAndMessage('invalid-multi-factor-session', 'The supplied multi-factor session is invalid or has expired.');
|
|
851
|
+
}
|
|
852
|
+
const totpSecret = await TotpMultiFactorGenerator.generateSecret(mappedSession);
|
|
1067
853
|
totpSecretMap.set(totpSecret.secretKey, totpSecret);
|
|
1068
|
-
return {
|
|
854
|
+
return {
|
|
855
|
+
secretKey: totpSecret.secretKey
|
|
856
|
+
};
|
|
1069
857
|
});
|
|
1070
858
|
},
|
|
1071
|
-
|
|
1072
859
|
/**
|
|
1073
860
|
* unenroll from TOTP
|
|
1074
861
|
* @param {*} appName - The name of the app to get the auth instance for.
|
|
@@ -1082,9 +869,9 @@ export default {
|
|
|
1082
869
|
return promiseNoUser(true);
|
|
1083
870
|
}
|
|
1084
871
|
await multiFactor(auth.currentUser).unenroll(enrollmentId);
|
|
872
|
+
return promiseNoUser();
|
|
1085
873
|
});
|
|
1086
874
|
},
|
|
1087
|
-
|
|
1088
875
|
/**
|
|
1089
876
|
* finalize a TOTP enrollment
|
|
1090
877
|
* @param {*} appName - The name of the app to get the auth instance for.
|
|
@@ -1099,14 +886,15 @@ export default {
|
|
|
1099
886
|
if (auth.currentUser === null) {
|
|
1100
887
|
return promiseNoUser(true);
|
|
1101
888
|
}
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
889
|
+
const totpSecret = totpSecretMap.get(secretKey);
|
|
890
|
+
if (!totpSecret) {
|
|
891
|
+
return rejectPromiseWithCodeAndMessage('invalid-multi-factor-secret', "can't find secret for provided key");
|
|
892
|
+
}
|
|
893
|
+
const multiFactorAssertion = TotpMultiFactorGenerator.assertionForEnrollment(totpSecret, verificationCode);
|
|
1106
894
|
await multiFactor(auth.currentUser).enroll(multiFactorAssertion, displayName);
|
|
895
|
+
return promiseNoUser();
|
|
1107
896
|
});
|
|
1108
897
|
},
|
|
1109
|
-
|
|
1110
898
|
/**
|
|
1111
899
|
* generate a TOTP QR Code URL
|
|
1112
900
|
* @param {*} _appName - The name of the app to get the auth instance for.
|
|
@@ -1116,9 +904,12 @@ export default {
|
|
|
1116
904
|
* @returns QR Code URL
|
|
1117
905
|
*/
|
|
1118
906
|
generateQrCodeUrl(_appName, secretKey, accountName, issuer) {
|
|
1119
|
-
|
|
907
|
+
const totpSecret = totpSecretMap.get(secretKey);
|
|
908
|
+
if (!totpSecret) {
|
|
909
|
+
return rejectPromiseWithCodeAndMessage('invalid-multi-factor-secret', "can't find secret for provided key");
|
|
910
|
+
}
|
|
911
|
+
return totpSecret.generateQrCodeUrl(accountName, issuer);
|
|
1120
912
|
},
|
|
1121
|
-
|
|
1122
913
|
/**
|
|
1123
914
|
* open a QR Code URL in an app directly
|
|
1124
915
|
* @param {*} appName - The name of the app to get the auth instance for.
|
|
@@ -1126,12 +917,8 @@ export default {
|
|
|
1126
917
|
* @throws Error not supported in this environment
|
|
1127
918
|
*/
|
|
1128
919
|
openInOtpApp() {
|
|
1129
|
-
return rejectWithCodeAndMessage(
|
|
1130
|
-
'unsupported',
|
|
1131
|
-
'This operation is not supported in this environment.',
|
|
1132
|
-
);
|
|
920
|
+
return rejectWithCodeAndMessage('unsupported', 'This operation is not supported in this environment.');
|
|
1133
921
|
},
|
|
1134
|
-
|
|
1135
922
|
/* ----------------------
|
|
1136
923
|
* other methods
|
|
1137
924
|
* ---------------------- */
|
|
@@ -1149,7 +936,6 @@ export default {
|
|
|
1149
936
|
return methods;
|
|
1150
937
|
});
|
|
1151
938
|
},
|
|
1152
|
-
|
|
1153
939
|
/**
|
|
1154
940
|
* Set the language code.
|
|
1155
941
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -1162,7 +948,6 @@ export default {
|
|
|
1162
948
|
auth.languageCode = code;
|
|
1163
949
|
});
|
|
1164
950
|
},
|
|
1165
|
-
|
|
1166
951
|
/**
|
|
1167
952
|
* Set the tenant ID.
|
|
1168
953
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -1175,7 +960,6 @@ export default {
|
|
|
1175
960
|
auth.tenantId = tenantId;
|
|
1176
961
|
});
|
|
1177
962
|
},
|
|
1178
|
-
|
|
1179
963
|
/**
|
|
1180
964
|
* Use the device language.
|
|
1181
965
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -1187,7 +971,6 @@ export default {
|
|
|
1187
971
|
useDeviceLanguage(auth);
|
|
1188
972
|
});
|
|
1189
973
|
},
|
|
1190
|
-
|
|
1191
974
|
/**
|
|
1192
975
|
* Verify the provided password reset code.
|
|
1193
976
|
* @returns {string} - The users email address if valid.
|
|
@@ -1199,7 +982,6 @@ export default {
|
|
|
1199
982
|
return email;
|
|
1200
983
|
});
|
|
1201
984
|
},
|
|
1202
|
-
|
|
1203
985
|
/**
|
|
1204
986
|
* Connect to the auth emulator.
|
|
1205
987
|
* @param {string} appName - The name of the app to get the auth instance for.
|
|
@@ -1212,5 +994,6 @@ export default {
|
|
|
1212
994
|
const auth = getCachedAuthInstance(appName);
|
|
1213
995
|
connectAuthEmulator(auth, `http://${host}:${port}`);
|
|
1214
996
|
});
|
|
1215
|
-
}
|
|
997
|
+
}
|
|
1216
998
|
};
|
|
999
|
+
//# sourceMappingURL=RNFBAuthModule.js.map
|