@chem-po/firebase-native 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.md +215 -0
  2. package/lib/commonjs/adapter/auth.js +431 -0
  3. package/lib/commonjs/adapter/auth.js.map +1 -0
  4. package/lib/commonjs/adapter/db.js +103 -0
  5. package/lib/commonjs/adapter/db.js.map +1 -0
  6. package/lib/commonjs/adapter/index.js +16 -0
  7. package/lib/commonjs/adapter/index.js.map +1 -0
  8. package/lib/commonjs/adapter/storage.js +52 -0
  9. package/lib/commonjs/adapter/storage.js.map +1 -0
  10. package/lib/commonjs/auth/functions.js +11 -0
  11. package/lib/commonjs/auth/functions.js.map +1 -0
  12. package/lib/commonjs/auth/index.js +17 -0
  13. package/lib/commonjs/auth/index.js.map +1 -0
  14. package/lib/commonjs/components/AuthenticatorVerify.js +90 -0
  15. package/lib/commonjs/components/AuthenticatorVerify.js.map +1 -0
  16. package/lib/commonjs/components/FirebaseSignIn.js +196 -0
  17. package/lib/commonjs/components/FirebaseSignIn.js.map +1 -0
  18. package/lib/commonjs/components/PhoneVerify.js +123 -0
  19. package/lib/commonjs/components/PhoneVerify.js.map +1 -0
  20. package/lib/commonjs/components/TwoFactorAuthModal.js +118 -0
  21. package/lib/commonjs/components/TwoFactorAuthModal.js.map +1 -0
  22. package/lib/commonjs/components/index.js +28 -0
  23. package/lib/commonjs/components/index.js.map +1 -0
  24. package/lib/commonjs/contexts/FirebaseContext.js +48 -0
  25. package/lib/commonjs/contexts/FirebaseContext.js.map +1 -0
  26. package/lib/commonjs/contexts/index.js +17 -0
  27. package/lib/commonjs/contexts/index.js.map +1 -0
  28. package/lib/commonjs/db/index.js +17 -0
  29. package/lib/commonjs/db/index.js.map +1 -0
  30. package/lib/commonjs/db/utils.js +120 -0
  31. package/lib/commonjs/db/utils.js.map +1 -0
  32. package/lib/commonjs/hooks/backend.js +12 -0
  33. package/lib/commonjs/hooks/backend.js.map +1 -0
  34. package/lib/commonjs/hooks/index.js +17 -0
  35. package/lib/commonjs/hooks/index.js.map +1 -0
  36. package/lib/commonjs/hooks/useAuthenticatorVerify.js +52 -0
  37. package/lib/commonjs/hooks/useAuthenticatorVerify.js.map +1 -0
  38. package/lib/commonjs/hooks/usePhoneVerify.js +83 -0
  39. package/lib/commonjs/hooks/usePhoneVerify.js.map +1 -0
  40. package/lib/commonjs/icons/Google.js +29 -0
  41. package/lib/commonjs/icons/Google.js.map +1 -0
  42. package/lib/commonjs/index.js +105 -0
  43. package/lib/commonjs/index.js.map +1 -0
  44. package/lib/commonjs/storage/index.js +17 -0
  45. package/lib/commonjs/storage/index.js.map +1 -0
  46. package/lib/commonjs/storage/utils.js +37 -0
  47. package/lib/commonjs/storage/utils.js.map +1 -0
  48. package/lib/commonjs/types/adapter.js +6 -0
  49. package/lib/commonjs/types/adapter.js.map +1 -0
  50. package/lib/commonjs/types/auth.js +6 -0
  51. package/lib/commonjs/types/auth.js.map +1 -0
  52. package/lib/commonjs/types/db.js +6 -0
  53. package/lib/commonjs/types/db.js.map +1 -0
  54. package/lib/commonjs/types/functions.js +6 -0
  55. package/lib/commonjs/types/functions.js.map +1 -0
  56. package/lib/commonjs/types/index.js +6 -0
  57. package/lib/commonjs/types/index.js.map +1 -0
  58. package/lib/commonjs/types/storage.js +6 -0
  59. package/lib/commonjs/types/storage.js.map +1 -0
  60. package/lib/commonjs/utils/validation.js +71 -0
  61. package/lib/commonjs/utils/validation.js.map +1 -0
  62. package/lib/module/adapter/auth.js +424 -0
  63. package/lib/module/adapter/auth.js.map +1 -0
  64. package/lib/module/adapter/db.js +96 -0
  65. package/lib/module/adapter/db.js.map +1 -0
  66. package/lib/module/adapter/index.js +9 -0
  67. package/lib/module/adapter/index.js.map +1 -0
  68. package/lib/module/adapter/storage.js +45 -0
  69. package/lib/module/adapter/storage.js.map +1 -0
  70. package/lib/module/auth/functions.js +3 -0
  71. package/lib/module/auth/functions.js.map +1 -0
  72. package/lib/module/auth/index.js +2 -0
  73. package/lib/module/auth/index.js.map +1 -0
  74. package/lib/module/components/AuthenticatorVerify.js +82 -0
  75. package/lib/module/components/AuthenticatorVerify.js.map +1 -0
  76. package/lib/module/components/FirebaseSignIn.js +187 -0
  77. package/lib/module/components/FirebaseSignIn.js.map +1 -0
  78. package/lib/module/components/PhoneVerify.js +116 -0
  79. package/lib/module/components/PhoneVerify.js.map +1 -0
  80. package/lib/module/components/TwoFactorAuthModal.js +110 -0
  81. package/lib/module/components/TwoFactorAuthModal.js.map +1 -0
  82. package/lib/module/components/index.js +3 -0
  83. package/lib/module/components/index.js.map +1 -0
  84. package/lib/module/contexts/FirebaseContext.js +39 -0
  85. package/lib/module/contexts/FirebaseContext.js.map +1 -0
  86. package/lib/module/contexts/index.js +2 -0
  87. package/lib/module/contexts/index.js.map +1 -0
  88. package/lib/module/db/index.js +2 -0
  89. package/lib/module/db/index.js.map +1 -0
  90. package/lib/module/db/utils.js +111 -0
  91. package/lib/module/db/utils.js.map +1 -0
  92. package/lib/module/hooks/backend.js +5 -0
  93. package/lib/module/hooks/backend.js.map +1 -0
  94. package/lib/module/hooks/index.js +2 -0
  95. package/lib/module/hooks/index.js.map +1 -0
  96. package/lib/module/hooks/useAuthenticatorVerify.js +45 -0
  97. package/lib/module/hooks/useAuthenticatorVerify.js.map +1 -0
  98. package/lib/module/hooks/usePhoneVerify.js +76 -0
  99. package/lib/module/hooks/usePhoneVerify.js.map +1 -0
  100. package/lib/module/icons/Google.js +22 -0
  101. package/lib/module/icons/Google.js.map +1 -0
  102. package/lib/module/index.js +10 -0
  103. package/lib/module/index.js.map +1 -0
  104. package/lib/module/storage/index.js +2 -0
  105. package/lib/module/storage/index.js.map +1 -0
  106. package/lib/module/storage/utils.js +30 -0
  107. package/lib/module/storage/utils.js.map +1 -0
  108. package/lib/module/types/adapter.js +2 -0
  109. package/lib/module/types/adapter.js.map +1 -0
  110. package/lib/module/types/auth.js +2 -0
  111. package/lib/module/types/auth.js.map +1 -0
  112. package/lib/module/types/db.js +2 -0
  113. package/lib/module/types/db.js.map +1 -0
  114. package/lib/module/types/functions.js +2 -0
  115. package/lib/module/types/functions.js.map +1 -0
  116. package/lib/module/types/index.js +2 -0
  117. package/lib/module/types/index.js.map +1 -0
  118. package/lib/module/types/storage.js +2 -0
  119. package/lib/module/types/storage.js.map +1 -0
  120. package/lib/module/utils/validation.js +62 -0
  121. package/lib/module/utils/validation.js.map +1 -0
  122. package/lib/typescript/adapter/auth.d.ts +7 -0
  123. package/lib/typescript/adapter/auth.d.ts.map +1 -0
  124. package/lib/typescript/adapter/db.d.ts +5 -0
  125. package/lib/typescript/adapter/db.d.ts.map +1 -0
  126. package/lib/typescript/adapter/index.d.ts +9 -0
  127. package/lib/typescript/adapter/index.d.ts.map +1 -0
  128. package/lib/typescript/adapter/storage.d.ts +4 -0
  129. package/lib/typescript/adapter/storage.d.ts.map +1 -0
  130. package/lib/typescript/auth/functions.d.ts +4 -0
  131. package/lib/typescript/auth/functions.d.ts.map +1 -0
  132. package/lib/typescript/auth/index.d.ts +2 -0
  133. package/lib/typescript/auth/index.d.ts.map +1 -0
  134. package/lib/typescript/components/AuthenticatorVerify.d.ts +3 -0
  135. package/lib/typescript/components/AuthenticatorVerify.d.ts.map +1 -0
  136. package/lib/typescript/components/FirebaseSignIn.d.ts +6 -0
  137. package/lib/typescript/components/FirebaseSignIn.d.ts.map +1 -0
  138. package/lib/typescript/components/PhoneVerify.d.ts +6 -0
  139. package/lib/typescript/components/PhoneVerify.d.ts.map +1 -0
  140. package/lib/typescript/components/TwoFactorAuthModal.d.ts +3 -0
  141. package/lib/typescript/components/TwoFactorAuthModal.d.ts.map +1 -0
  142. package/lib/typescript/components/index.d.ts +3 -0
  143. package/lib/typescript/components/index.d.ts.map +1 -0
  144. package/lib/typescript/contexts/FirebaseContext.d.ts +9 -0
  145. package/lib/typescript/contexts/FirebaseContext.d.ts.map +1 -0
  146. package/lib/typescript/contexts/index.d.ts +2 -0
  147. package/lib/typescript/contexts/index.d.ts.map +1 -0
  148. package/lib/typescript/db/index.d.ts +2 -0
  149. package/lib/typescript/db/index.d.ts.map +1 -0
  150. package/lib/typescript/db/utils.d.ts +6 -0
  151. package/lib/typescript/db/utils.d.ts.map +1 -0
  152. package/lib/typescript/hooks/backend.d.ts +2 -0
  153. package/lib/typescript/hooks/backend.d.ts.map +1 -0
  154. package/lib/typescript/hooks/index.d.ts +2 -0
  155. package/lib/typescript/hooks/index.d.ts.map +1 -0
  156. package/lib/typescript/hooks/useAuthenticatorVerify.d.ts +8 -0
  157. package/lib/typescript/hooks/useAuthenticatorVerify.d.ts.map +1 -0
  158. package/lib/typescript/hooks/usePhoneVerify.d.ts +9 -0
  159. package/lib/typescript/hooks/usePhoneVerify.d.ts.map +1 -0
  160. package/lib/typescript/icons/Google.d.ts +5 -0
  161. package/lib/typescript/icons/Google.d.ts.map +1 -0
  162. package/lib/typescript/index.d.ts +10 -0
  163. package/lib/typescript/index.d.ts.map +1 -0
  164. package/lib/typescript/storage/index.d.ts +2 -0
  165. package/lib/typescript/storage/index.d.ts.map +1 -0
  166. package/lib/typescript/storage/utils.d.ts +4 -0
  167. package/lib/typescript/storage/utils.d.ts.map +1 -0
  168. package/lib/typescript/types/adapter.d.ts +6 -0
  169. package/lib/typescript/types/adapter.d.ts.map +1 -0
  170. package/lib/typescript/types/auth.d.ts +12 -0
  171. package/lib/typescript/types/auth.d.ts.map +1 -0
  172. package/lib/typescript/types/db.d.ts +8 -0
  173. package/lib/typescript/types/db.d.ts.map +1 -0
  174. package/lib/typescript/types/functions.d.ts +3 -0
  175. package/lib/typescript/types/functions.d.ts.map +1 -0
  176. package/lib/typescript/types/index.d.ts +24 -0
  177. package/lib/typescript/types/index.d.ts.map +1 -0
  178. package/lib/typescript/types/storage.d.ts +3 -0
  179. package/lib/typescript/types/storage.d.ts.map +1 -0
  180. package/lib/typescript/utils/validation.d.ts +21 -0
  181. package/lib/typescript/utils/validation.d.ts.map +1 -0
  182. package/package.json +29 -12
  183. package/src/adapter/auth.ts +474 -0
  184. package/src/adapter/db.ts +146 -0
  185. package/src/adapter/index.ts +30 -0
  186. package/src/adapter/storage.ts +58 -0
  187. package/src/auth/functions.ts +7 -0
  188. package/src/auth/index.ts +1 -0
  189. package/src/components/AuthenticatorVerify.tsx +75 -0
  190. package/src/components/FirebaseSignIn.tsx +187 -0
  191. package/src/components/PhoneVerify.tsx +102 -0
  192. package/src/components/TwoFactorAuthModal.tsx +133 -0
  193. package/src/components/index.ts +2 -0
  194. package/src/contexts/FirebaseContext.tsx +54 -0
  195. package/src/contexts/index.ts +1 -0
  196. package/src/db/index.ts +1 -0
  197. package/src/db/utils.ts +142 -0
  198. package/src/hooks/backend.ts +4 -0
  199. package/src/hooks/index.ts +1 -0
  200. package/src/hooks/useAuthenticatorVerify.ts +45 -0
  201. package/src/hooks/usePhoneVerify.ts +76 -0
  202. package/src/icons/Google.tsx +24 -0
  203. package/src/index.ts +9 -0
  204. package/src/storage/index.ts +1 -0
  205. package/src/storage/utils.ts +29 -0
  206. package/src/types/adapter.ts +13 -0
  207. package/src/types/auth.ts +13 -0
  208. package/src/types/db.ts +10 -0
  209. package/src/types/functions.ts +3 -0
  210. package/src/types/index.ts +26 -0
  211. package/src/types/storage.ts +3 -0
  212. package/src/utils/validation.ts +85 -0
@@ -0,0 +1,424 @@
1
+ var _process$env;
2
+ import { getIdTokenResult, getMultiFactorResolver, GoogleAuthProvider, onAuthStateChanged, PhoneAuthProvider, PhoneMultiFactorGenerator, sendPasswordResetEmail, signInWithCredential, signInWithCustomToken, signInWithEmailAndPassword, signOut } from '@react-native-firebase/auth';
3
+ import { GoogleSignin } from '@react-native-google-signin/google-signin';
4
+ const isDebug = typeof process !== 'undefined' && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.EXPO_PUBLIC_DEBUG) === 'true' || false;
5
+ const debugLog = (message, data) => {
6
+ if (isDebug) {
7
+ console.log(`[FirebaseAuth Debug] ${message}`, data || '');
8
+ }
9
+ };
10
+ const providerInitialized = {};
11
+ const getUserWithRole = async user => {
12
+ debugLog('Getting user with role', {
13
+ uid: user.uid,
14
+ email: user.email
15
+ });
16
+ try {
17
+ var _user$multiFactor, _user$multiFactor2;
18
+ const {
19
+ claims
20
+ } = await getIdTokenResult(user);
21
+ debugLog('Retrieved ID token claims', {
22
+ role: claims.role,
23
+ customClaims: Object.keys(claims)
24
+ });
25
+ const userWithRole = {
26
+ ...user,
27
+ role: claims.role ?? 'user',
28
+ multiFactorVerified: !!((_user$multiFactor = user.multiFactor) !== null && _user$multiFactor !== void 0 && _user$multiFactor.enrolledFactors.length)
29
+ };
30
+ debugLog('User with role created', {
31
+ uid: userWithRole.uid,
32
+ role: userWithRole.role,
33
+ multiFactorVerified: userWithRole.multiFactorVerified,
34
+ enrolledFactorsCount: ((_user$multiFactor2 = user.multiFactor) === null || _user$multiFactor2 === void 0 ? void 0 : _user$multiFactor2.enrolledFactors.length) || 0
35
+ });
36
+ return userWithRole;
37
+ } catch (error) {
38
+ debugLog('Error getting user with role', error);
39
+ throw error;
40
+ }
41
+ };
42
+ const toEnrollmentFactor = hint => {
43
+ if (hint.factorId === PhoneMultiFactorGenerator.FACTOR_ID) {
44
+ return {
45
+ type: 'phone',
46
+ phoneNumber: hint.phoneNumber,
47
+ enrollmentTime: hint.enrollmentTime,
48
+ displayName: hint.displayName,
49
+ uid: hint.uid
50
+ };
51
+ }
52
+ if (hint.factorId === 'totp') {
53
+ return {
54
+ type: 'totp',
55
+ enrollmentTime: hint.enrollmentTime,
56
+ displayName: hint.displayName,
57
+ uid: hint.uid
58
+ };
59
+ }
60
+ throw new Error('Unsupported factor type: ' + hint.factorId);
61
+ };
62
+ const toFirebaseFactor = factor => {
63
+ if (factor.type === 'phone') {
64
+ return {
65
+ factorId: PhoneMultiFactorGenerator.FACTOR_ID,
66
+ phoneNumber: factor.phoneNumber,
67
+ enrollmentTime: factor.enrollmentTime,
68
+ uid: factor.uid,
69
+ displayName: factor.displayName
70
+ };
71
+ }
72
+ if (factor.type === 'totp') {
73
+ return {
74
+ factorId: 'totp',
75
+ enrollmentTime: factor.enrollmentTime,
76
+ uid: factor.uid,
77
+ displayName: factor.displayName
78
+ };
79
+ }
80
+ throw new Error(`Unsupported factor type: ${factor.factorId ?? 'Missing factor type'}`);
81
+ };
82
+ const sendMultiFactorCode = async (auth, factor, resolver) => {
83
+ debugLog('Sending multi-factor code', {
84
+ factorType: factor.type,
85
+ factorUid: factor.uid
86
+ });
87
+ const sessionId = resolver.session;
88
+ // const verificationId = await new PhoneAuthProvider(auth).verifyPhoneNumber(phoneSignInFactor, sessionId)
89
+ if (factor.type === 'phone') {
90
+ try {
91
+ const verificationId = await auth.verifyPhoneNumberWithMultiFactorInfo(toFirebaseFactor(factor), sessionId);
92
+ debugLog('Multi-factor code sent successfully', {
93
+ verificationId: verificationId.substring(0, 10) + '...'
94
+ });
95
+ return {
96
+ verificationId,
97
+ factor,
98
+ resolver
99
+ };
100
+ } catch (error) {
101
+ debugLog('Error sending multi-factor code', error);
102
+ throw error;
103
+ }
104
+ }
105
+ throw new Error(`Unsupported factor type: ${factor.type ?? 'Missing factor type'}`);
106
+ };
107
+ const getEnrolledFactors = async (auth, error) => {
108
+ debugLog('Getting enrolled factors from error', {
109
+ errorCode: error === null || error === void 0 ? void 0 : error.code
110
+ });
111
+ try {
112
+ const resolver = getMultiFactorResolver(auth, error);
113
+ debugLog('Multi-factor resolver created', {
114
+ hintsCount: resolver.hints.length
115
+ });
116
+ if (resolver.hints.length === 0) {
117
+ debugLog('No enrolled factors found');
118
+ throw new Error('No multi-factor verification methods found, please enroll one on the website');
119
+ }
120
+ const enrollmentFactors = resolver.hints.map(toEnrollmentFactor);
121
+ debugLog('Enrollment factors mapped', {
122
+ factors: enrollmentFactors.map(f => ({
123
+ type: f.type,
124
+ uid: f.uid
125
+ }))
126
+ });
127
+ return {
128
+ enrollmentFactors,
129
+ multiFactorResolver: resolver
130
+ };
131
+ } catch (error) {
132
+ debugLog('Error getting enrolled factors', error);
133
+ throw error;
134
+ }
135
+ };
136
+ const verifyMultiFactor = async (verification, code) => {
137
+ debugLog('Verifying multi-factor code', {
138
+ factorType: verification.factor.type,
139
+ codeLength: code.length
140
+ });
141
+ try {
142
+ var _userCredential$user;
143
+ const credential = await PhoneAuthProvider.credential(verification.verificationId, code);
144
+ debugLog('Phone credential created');
145
+ const assertion = PhoneMultiFactorGenerator.assertion(credential);
146
+ debugLog('Multi-factor assertion created');
147
+ const resolver = verification.resolver;
148
+ if (!resolver) {
149
+ debugLog('Multi-factor resolver not found');
150
+ throw new Error('Internal error signing in with two factor: resolver not found');
151
+ }
152
+ const userCredential = await resolver.resolveSignIn(assertion);
153
+ debugLog('Multi-factor sign-in resolved', {
154
+ uid: (_userCredential$user = userCredential.user) === null || _userCredential$user === void 0 ? void 0 : _userCredential$user.uid
155
+ });
156
+ const user = userCredential.user;
157
+ if (!user) {
158
+ debugLog('No user found after multi-factor resolution');
159
+ throw new Error('No user found');
160
+ }
161
+ const userWithRole = await getUserWithRole(user);
162
+ debugLog('Multi-factor verification completed successfully');
163
+ return {
164
+ user: userWithRole
165
+ };
166
+ } catch (error) {
167
+ debugLog('Error verifying multi-factor', error);
168
+ throw error;
169
+ }
170
+ };
171
+ const handleSignInError = async error => {
172
+ debugLog('Handling sign-in error', {
173
+ code: error === null || error === void 0 ? void 0 : error.code,
174
+ message: error === null || error === void 0 ? void 0 : error.message
175
+ });
176
+ if (error.code === 'auth/multi-factor-auth-required') {
177
+ debugLog('Multi-factor authentication required');
178
+ return {
179
+ requestArgs: error
180
+ };
181
+ }
182
+ debugLog('Re-throwing sign-in error');
183
+ throw error;
184
+ };
185
+ const initializeProvider = async provider => {
186
+ debugLog('Initializing provider', {
187
+ name: provider.name,
188
+ alreadyInitialized: providerInitialized[provider.name]
189
+ });
190
+ if (providerInitialized[provider.name]) {
191
+ debugLog('Provider already initialized, skipping');
192
+ return;
193
+ }
194
+ switch (provider.name) {
195
+ case 'google':
196
+ debugLog('Initializing Google provider', {
197
+ webClientId: !!provider.webClientId
198
+ });
199
+ if (!provider.webClientId) {
200
+ debugLog('Google web client ID missing');
201
+ throw new Error('Google web client ID is required when using Google Auth. ' + 'Get your webClientId from Firebase Console > Authentication > Sign-in method > Google > Web SDK configuration. ' + 'Then provide it in your GoogleAuthProvider: { name: "google", webClientId: "YOUR_CLIENT_ID" }');
202
+ }
203
+ try {
204
+ await GoogleSignin.hasPlayServices({
205
+ showPlayServicesUpdateDialog: true
206
+ });
207
+ debugLog('Google Play Services available');
208
+ GoogleSignin.configure({
209
+ webClientId: provider.webClientId
210
+ });
211
+ debugLog('Google Sign-In configured successfully');
212
+ } catch (error) {
213
+ debugLog('Error initializing Google provider', error);
214
+ if (error instanceof Error && error.message.includes('UNAVAILABLE')) {
215
+ throw new Error('Google Play Services is not available or needs to be updated. ' + 'Please ensure Google Play Services is installed and up to date on this device.');
216
+ }
217
+ throw error;
218
+ }
219
+ break;
220
+ case 'email':
221
+ debugLog('Email provider initialization (no special setup required)');
222
+ // Native SDK doesn't need special initialization
223
+ break;
224
+ default:
225
+ debugLog('Unsupported provider', {
226
+ name: provider.name
227
+ });
228
+ throw new Error(`Unsupported provider: ${provider.name}`);
229
+ }
230
+ providerInitialized[provider.name] = true;
231
+ debugLog('Provider initialization completed', {
232
+ name: provider.name
233
+ });
234
+ };
235
+ const handleInitialLogin = async (userCredential, twoFactorRequired) => {
236
+ var _userCredential$user2, _userCredential$user3;
237
+ debugLog('Handling initial login', {
238
+ uid: (_userCredential$user2 = userCredential.user) === null || _userCredential$user2 === void 0 ? void 0 : _userCredential$user2.uid,
239
+ twoFactorRequired,
240
+ enrolledFactorsCount: ((_userCredential$user3 = userCredential.user) === null || _userCredential$user3 === void 0 || (_userCredential$user3 = _userCredential$user3.multiFactor) === null || _userCredential$user3 === void 0 ? void 0 : _userCredential$user3.enrolledFactors.length) || 0
241
+ });
242
+ const user = userCredential.user;
243
+ if (!user) {
244
+ debugLog('No user found in credential');
245
+ throw new Error('No user found');
246
+ }
247
+ if (twoFactorRequired) {
248
+ debugLog('Two-factor authentication is required but user has no enrolled factors');
249
+ throw new Error('This app requires two factor authentication, please enroll a factor on the website and try again');
250
+ }
251
+ const userWithRole = await getUserWithRole(user);
252
+ debugLog('Initial login completed successfully');
253
+ return {
254
+ user: userWithRole
255
+ };
256
+ };
257
+ const loginWithGoogle = async (auth, twoFactorRequired) => {
258
+ debugLog('Starting Google sign-in', {
259
+ twoFactorRequired
260
+ });
261
+ try {
262
+ var _signInResult$data, _signInResult$data2;
263
+ debugLog('Calling GoogleSignin.signIn()');
264
+ const signInResult = await GoogleSignin.signIn();
265
+ debugLog('Google sign-in result received', {
266
+ hasIdToken: !!((_signInResult$data = signInResult.data) !== null && _signInResult$data !== void 0 && _signInResult$data.idToken)
267
+ });
268
+ const idToken = (_signInResult$data2 = signInResult.data) === null || _signInResult$data2 === void 0 ? void 0 : _signInResult$data2.idToken;
269
+ if (!idToken) {
270
+ debugLog('No ID token found in Google sign-in result');
271
+ throw new Error('No ID token found');
272
+ }
273
+ debugLog('Creating Google credential');
274
+ const googleCredential = GoogleAuthProvider.credential(idToken);
275
+ debugLog('Signing in with Google credential');
276
+ const userCredential = await signInWithCredential(auth, googleCredential);
277
+ return await handleInitialLogin(userCredential, twoFactorRequired);
278
+ } catch (error) {
279
+ debugLog('Error in Google sign-in', error);
280
+ return await handleSignInError(error);
281
+ }
282
+ };
283
+ const getLoginWithPassword = (auth, twoFactorRequired) => async (provider, {
284
+ email,
285
+ password
286
+ }) => {
287
+ debugLog('Starting email/password sign-in', {
288
+ provider: provider.name,
289
+ email,
290
+ twoFactorRequired
291
+ });
292
+ await initializeProvider(provider);
293
+ try {
294
+ var _userCredential$user4;
295
+ debugLog('Calling signInWithEmailAndPassword');
296
+ const userCredential = await signInWithEmailAndPassword(auth, email, password);
297
+ debugLog('Email/password sign-in successful', {
298
+ uid: (_userCredential$user4 = userCredential.user) === null || _userCredential$user4 === void 0 ? void 0 : _userCredential$user4.uid
299
+ });
300
+ return await handleInitialLogin(userCredential, twoFactorRequired);
301
+ } catch (error) {
302
+ debugLog('Error in email/password sign-in', error);
303
+ return await handleSignInError(error);
304
+ }
305
+ };
306
+ const getLoginWithPopup = (auth, twoFactorRequired) => async provider => {
307
+ debugLog('Starting popup sign-in', {
308
+ provider: provider.name,
309
+ twoFactorRequired
310
+ });
311
+ await initializeProvider(provider);
312
+ switch (provider.name) {
313
+ case 'google':
314
+ return loginWithGoogle(auth, twoFactorRequired);
315
+ default:
316
+ debugLog('Unsupported popup provider', {
317
+ name: provider.name
318
+ });
319
+ throw new Error(`Unsupported provider: ${provider.name}`);
320
+ }
321
+ };
322
+ const getLoginWithToken = (auth, twoFactorRequired) => async (provider, token) => {
323
+ debugLog('Starting token sign-in', {
324
+ provider: provider.name,
325
+ tokenLength: token.length,
326
+ twoFactorRequired
327
+ });
328
+ await initializeProvider(provider);
329
+ try {
330
+ var _userCredential$user5;
331
+ debugLog('Calling signInWithCustomToken');
332
+ const userCredential = await signInWithCustomToken(auth, token);
333
+ debugLog('Token sign-in successful', {
334
+ uid: (_userCredential$user5 = userCredential.user) === null || _userCredential$user5 === void 0 ? void 0 : _userCredential$user5.uid
335
+ });
336
+ return await handleInitialLogin(userCredential, twoFactorRequired);
337
+ } catch (error) {
338
+ debugLog('Error in token sign-in', error);
339
+ return await handleSignInError(error);
340
+ }
341
+ };
342
+ const resetPassword = async (auth, provider, usernameOrEmail) => {
343
+ debugLog('Starting password reset', {
344
+ provider: provider.name,
345
+ email: usernameOrEmail
346
+ });
347
+ await initializeProvider(provider);
348
+ try {
349
+ await sendPasswordResetEmail(auth, usernameOrEmail);
350
+ debugLog('Password reset email sent successfully');
351
+ } catch (error) {
352
+ debugLog('Error sending password reset email', error);
353
+ throw error;
354
+ }
355
+ };
356
+ export const getFirebaseAuthAdapter = (auth, twoFactorRequired) => {
357
+ debugLog('Creating Firebase Auth Adapter', {
358
+ twoFactorRequired
359
+ });
360
+ return {
361
+ twoFactorRequired,
362
+ getCurrentUser: async () => {
363
+ debugLog('Getting current user');
364
+ const user = auth.currentUser;
365
+ if (!user) {
366
+ debugLog('No current user found');
367
+ return null;
368
+ }
369
+ debugLog('Current user found', {
370
+ uid: user.uid,
371
+ email: user.email
372
+ });
373
+ return getUserWithRole(user);
374
+ },
375
+ loginWithPassword: getLoginWithPassword(auth, twoFactorRequired),
376
+ loginWithPopup: getLoginWithPopup(auth, twoFactorRequired),
377
+ loginWithToken: getLoginWithToken(auth, twoFactorRequired),
378
+ resetPassword: (...args) => {
379
+ return resetPassword(auth, ...args);
380
+ },
381
+ verifyMultiFactor,
382
+ sendMultiFactorCode: (...args) => {
383
+ return sendMultiFactorCode(auth, ...args);
384
+ },
385
+ getEnrolledFactors: (...args) => {
386
+ return getEnrolledFactors(auth, ...args);
387
+ },
388
+ logout: async () => {
389
+ debugLog('Starting logout');
390
+ try {
391
+ await signOut(auth);
392
+ debugLog('Logout completed successfully');
393
+ } catch (error) {
394
+ debugLog('Error during logout', error);
395
+ throw error;
396
+ }
397
+ },
398
+ subscribeToUser: callback => {
399
+ debugLog('Setting up user subscription');
400
+ return onAuthStateChanged(auth, user => {
401
+ if (!user) {
402
+ debugLog('User state changed: signed out');
403
+ callback(null);
404
+ return;
405
+ }
406
+ debugLog('User state changed: user signed in', {
407
+ uid: user.uid,
408
+ email: user.email
409
+ });
410
+ getUserWithRole(user).then(result => {
411
+ debugLog('User subscription callback completed', {
412
+ uid: result.uid,
413
+ role: result.role
414
+ });
415
+ callback(result);
416
+ }).catch(error => {
417
+ debugLog('Error in user subscription callback', error);
418
+ callback(null);
419
+ });
420
+ });
421
+ }
422
+ };
423
+ };
424
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getIdTokenResult","getMultiFactorResolver","GoogleAuthProvider","onAuthStateChanged","PhoneAuthProvider","PhoneMultiFactorGenerator","sendPasswordResetEmail","signInWithCredential","signInWithCustomToken","signInWithEmailAndPassword","signOut","GoogleSignin","isDebug","process","_process$env","env","EXPO_PUBLIC_DEBUG","debugLog","message","data","console","log","providerInitialized","getUserWithRole","user","uid","email","_user$multiFactor","_user$multiFactor2","claims","role","customClaims","Object","keys","userWithRole","multiFactorVerified","multiFactor","enrolledFactors","length","enrolledFactorsCount","error","toEnrollmentFactor","hint","factorId","FACTOR_ID","type","phoneNumber","enrollmentTime","displayName","Error","toFirebaseFactor","factor","sendMultiFactorCode","auth","resolver","factorType","factorUid","sessionId","session","verificationId","verifyPhoneNumberWithMultiFactorInfo","substring","getEnrolledFactors","errorCode","code","hintsCount","hints","enrollmentFactors","map","factors","f","multiFactorResolver","verifyMultiFactor","verification","codeLength","_userCredential$user","credential","assertion","userCredential","resolveSignIn","handleSignInError","requestArgs","initializeProvider","provider","name","alreadyInitialized","webClientId","hasPlayServices","showPlayServicesUpdateDialog","configure","includes","handleInitialLogin","twoFactorRequired","_userCredential$user2","_userCredential$user3","loginWithGoogle","_signInResult$data","_signInResult$data2","signInResult","signIn","hasIdToken","idToken","googleCredential","getLoginWithPassword","password","_userCredential$user4","getLoginWithPopup","getLoginWithToken","token","tokenLength","_userCredential$user5","resetPassword","usernameOrEmail","getFirebaseAuthAdapter","getCurrentUser","currentUser","loginWithPassword","loginWithPopup","loginWithToken","args","logout","subscribeToUser","callback","then","result","catch"],"sourceRoot":"..\\..\\..\\src","sources":["adapter/auth.ts"],"mappings":";AAWA,SAEEA,gBAAgB,EAChBC,sBAAsB,EACtBC,kBAAkB,EAClBC,kBAAkB,EAClBC,iBAAiB,EACjBC,yBAAyB,EACzBC,sBAAsB,EACtBC,oBAAoB,EACpBC,qBAAqB,EACrBC,0BAA0B,EAC1BC,OAAO,QACF,6BAA6B;AAEpC,SAASC,YAAY,QAAQ,2CAA2C;AAGxE,MAAMC,OAAO,GACX,OAAOC,OAAO,KAAK,WAAW,IAC9B,EAAAC,YAAA,GAAAD,OAAO,CAACE,GAAG,cAAAD,YAAA,uBAAXA,YAAA,CAAaE,iBAAiB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C,CAAC;IACDC,MAAM,EAAE,MAAAA,CAAA,KAAY;MAClBvG,QAAQ,CAAC,iBAAiB,CAAC;MAC3B,IAAI;QACF,MAAMP,OAAO,CAAC2C,IAAI,CAAC;QACnBpC,QAAQ,CAAC,+BAA+B,CAAC;MAC3C,CAAC,CAAC,OAAOuB,KAAK,EAAE;QACdvB,QAAQ,CAAC,qBAAqB,EAAEuB,KAAK,CAAC;QACtC,MAAMA,KAAK;MACb;IACF,CAAC;IACDiF,eAAe,EAAGC,QAAQ,IAAK;MAC7BzG,QAAQ,CAAC,8BAA8B,CAAC;MACxC,OAAOd,kBAAkB,CAACkD,IAAI,EAAG7B,IAAI,IAAK;QACxC,IAAI,CAACA,IAAI,EAAE;UACTP,QAAQ,CAAC,gCAAgC,CAAC;UAC1CyG,QAAQ,CAAC,IAAI,CAAC;UACd;QACF;QACAzG,QAAQ,CAAC,oCAAoC,EAAE;UAAEQ,GAAG,EAAED,IAAI,CAACC,GAAG;UAAEC,KAAK,EAAEF,IAAI,CAACE;QAAM,CAAC,CAAC;QACpFH,eAAe,CAACC,IAAI,CAAC,CAACmG,IAAI,CAAEC,MAAM,IAAK;UACrC3G,QAAQ,CAAC,sCAAsC,EAAE;YAAEQ,GAAG,EAAEmG,MAAM,CAACnG,GAAG;YAAEK,IAAI,EAAE8F,MAAM,CAAC9F;UAAK,CAAC,CAAC;UACxF4F,QAAQ,CAACE,MAAM,CAAC;QAClB,CAAC,CAAC,CAACC,KAAK,CAAErF,KAAK,IAAK;UAClBvB,QAAQ,CAAC,qCAAqC,EAAEuB,KAAK,CAAC;UACtDkF,QAAQ,CAAC,IAAI,CAAC;QAChB,CAAC,CAAC;MACJ,CAAC,CAAC;IACJ;EACF,CAAC;AACH,CAAC","ignoreList":[]}
@@ -0,0 +1,96 @@
1
+ import { addMetadata } from '@chem-po/core';
2
+ import { useAuth } from '@chem-po/react';
3
+ import { deleteDoc, doc, getDoc, getDocs, onSnapshot, setDoc } from '@react-native-firebase/firestore';
4
+ import { httpsCallable } from '@react-native-firebase/functions';
5
+ import { toCursorQuery, toFirestoreQuery } from '../db/utils';
6
+ // import { BaseQuery, FirestoreCursor } from '../types/db'
7
+
8
+ const handleFirestoreError = error => ({
9
+ code: (error === null || error === void 0 ? void 0 : error.code) ?? 'unknown',
10
+ message: (error === null || error === void 0 ? void 0 : error.name) ?? 'Unknown Error',
11
+ description: (error === null || error === void 0 ? void 0 : error.message) ?? 'An unknown error occurred'
12
+ });
13
+ const toDBItem = doc => ({
14
+ ...doc.data(),
15
+ id: doc.id
16
+ });
17
+ const getSubscribeToQuery = db => (baseQuery, onData, onError) => {
18
+ const q = toFirestoreQuery(db, baseQuery);
19
+ return onSnapshot(q, snapshot => {
20
+ const items = snapshot.docs.map(doc => toDBItem(doc));
21
+ onData(items, snapshot.docs[snapshot.docs.length - 1]);
22
+ }, error => onError(handleFirestoreError(error)));
23
+ };
24
+ const getFetchNextCursor = db => async baseQuery => {
25
+ const {
26
+ cursor
27
+ } = baseQuery;
28
+ const cursorDoc = cursor ? await getDoc(doc(db, baseQuery.collection, cursor.id)) : null;
29
+ const q = toCursorQuery(db, baseQuery, cursorDoc);
30
+ const snapshot = await getDocs(q);
31
+ return snapshot.docs[0] ?? null;
32
+ };
33
+ const getFetchCount = functions => async baseQuery => {
34
+ const fetchCountFunc = httpsCallable(functions, 'getQueryCount');
35
+ const {
36
+ data
37
+ } = await fetchCountFunc(baseQuery);
38
+ return data.count;
39
+ };
40
+ const getFetchItem = db => async path => {
41
+ const docRef = doc(db, path);
42
+ const docSnap = await getDoc(docRef);
43
+ const data = docSnap.data();
44
+ return data ? {
45
+ ...data,
46
+ id: docSnap.id
47
+ } : null;
48
+ };
49
+ const getFetchItems = db => async baseQuery => {
50
+ const q = toFirestoreQuery(db, baseQuery);
51
+ const snapshot = await getDocs(q);
52
+ return snapshot.docs.map(doc => ({
53
+ ...doc.data(),
54
+ id: doc.id
55
+ }));
56
+ };
57
+ const getCreateItem = db => async (path, item) => {
58
+ const docRef = doc(db, path);
59
+ const data = addMetadata(useAuth.getState().user, item, true);
60
+ await setDoc(docRef, data, {
61
+ merge: true
62
+ });
63
+ return docRef.id;
64
+ };
65
+ const getDeleteItem = db => async path => {
66
+ const docRef = doc(db, path);
67
+ await deleteDoc(docRef);
68
+ };
69
+ const getUpdateItem = db => async (path, item) => {
70
+ const docRef = doc(db, path);
71
+ await setDoc(docRef, item, {
72
+ merge: true
73
+ });
74
+ };
75
+ const getSubscribeToItem = db => (path, onData, onError) => {
76
+ const docRef = doc(db, path);
77
+ return onSnapshot(docRef, snapshot => {
78
+ const data = snapshot.data();
79
+ onData(data ? {
80
+ ...data,
81
+ id: snapshot.id
82
+ } : null);
83
+ }, error => onError(handleFirestoreError(error)));
84
+ };
85
+ export const getFirebaseDatabaseAdapter = (db, functions) => ({
86
+ fetchNextCursor: getFetchNextCursor(db),
87
+ fetchCount: getFetchCount(functions),
88
+ fetchItem: getFetchItem(db),
89
+ fetchItems: getFetchItems(db),
90
+ createItem: getCreateItem(db),
91
+ deleteItem: getDeleteItem(db),
92
+ updateItem: getUpdateItem(db),
93
+ subscribeToItem: getSubscribeToItem(db),
94
+ subscribeToQuery: getSubscribeToQuery(db)
95
+ });
96
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["addMetadata","useAuth","deleteDoc","doc","getDoc","getDocs","onSnapshot","setDoc","httpsCallable","toCursorQuery","toFirestoreQuery","handleFirestoreError","error","code","message","name","description","toDBItem","data","id","getSubscribeToQuery","db","baseQuery","onData","onError","q","snapshot","items","docs","map","length","getFetchNextCursor","cursor","cursorDoc","collection","getFetchCount","functions","fetchCountFunc","count","getFetchItem","path","docRef","docSnap","getFetchItems","getCreateItem","item","getState","user","merge","getDeleteItem","getUpdateItem","getSubscribeToItem","getFirebaseDatabaseAdapter","fetchNextCursor","fetchCount","fetchItem","fetchItems","createItem","deleteItem","updateItem","subscribeToItem","subscribeToQuery"],"sourceRoot":"..\\..\\..\\src","sources":["ad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AAOlC,UAAU,CACfmC,MAAM,EACNf,QAAQ,IAAI;IACV,MAAMR,IAAI,GAAGQ,QAAQ,CAACR,IAAI,CAAC,CAAC;IAC5BK,MAAM,CAACL,IAAI,GAAI;MAAE,GAAGA,IAAI;MAAEC,EAAE,EAAEO,QAAQ,CAACP;IAAG,CAAC,GAAiB,IAAI,CAAC;EACnE,CAAC,EACDP,KAAK,IAAIY,OAAO,CAACb,oBAAoB,CAACC,KAAK,CAAC,CAC9C,CAAC;AACH,CAAC;AAEH,OAAO,MAAMwC,0BAA0B,GAAGA,CACxC/B,EAAa,EACbe,SAAoB,MACkB;EACtCiB,eAAe,EAAEtB,kBAAkB,CAACV,EAAE,CAAC;EACvCiC,UAAU,EAAEnB,aAAa,CAACC,SAAS,CAAC;EACpCmB,SAAS,EAAEhB,YAAY,CAAClB,EAAE,CAAC;EAC3BmC,UAAU,EAAEb,aAAa,CAACtB,EAAE,CAAC;EAC7BoC,UAAU,EAAEb,aAAa,CAACvB,EAAE,CAAC;EAC7BqC,UAAU,EAAET,aAAa,CAAC5B,EAAE,CAAC;EAC7BsC,UAAU,EAAET,aAAa,CAAC7B,EAAE,CAAC;EAC7BuC,eAAe,EAAET,kBAAkB,CAAC9B,EAAE,CAAC;EACvCwC,gBAAgB,EAAEzC,mBAAmB,CAACC,EAAE;AAC1C,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import { getFirebaseAuthAdapter } from './auth';
2
+ import { getFirebaseDatabaseAdapter } from './db';
3
+ import { getFirebaseStorageAdapter } from './storage';
4
+ export const getFirebaseAdapter = (auth, db, storage, functions, twoFactorRequired) => ({
5
+ auth: getFirebaseAuthAdapter(auth, twoFactorRequired),
6
+ db: getFirebaseDatabaseAdapter(db, functions),
7
+ storage: getFirebaseStorageAdapter(storage)
8
+ });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getFirebaseAuthAdapter","getFirebaseDatabaseAdapter","getFirebaseStorageAdapter","getFirebaseAdapter","auth","db","storage","functions","twoFactorRequired"],"sourceRoot":"..\\..\\..\\src","sources":["adapter/index.ts"],"mappings":"AAMA,SAASA,sBAAsB,QAAQ,QAAQ;AAC/C,SAASC,0BAA0B,QAAQ,MAAM;AACjD,SAASC,yBAAyB,QAAQ,WAAW;AAWrD,OAAO,MAAMC,kBAAkB,GAAGA,CAChCC,IAAU,EACVC,EAAa,EACbC,OAAgB,EAChBC,SAAoB,EACpBC,iBAA0B,MACS;EACnCJ,IAAI,EAAEJ,sBAAsB,CAACI,IAAI,EAAEI,iBAAiB,CAAC;EACrDH,EAAE,EAAEJ,0BAA0B,CAACI,EAAE,EAAEE,SAAS,CAAC;EAC7CD,OAAO,EAAEJ,yBAAyB,CAACI,OAAO;AAC5C,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ import { deleteObject, getDownloadURL, getMetadata, ref, uploadBytesResumable } from '@react-native-firebase/storage';
2
+ export const getFirebaseStorageAdapter = storage => ({
3
+ delete: async path => {
4
+ const storageRef = ref(storage, path);
5
+ await deleteObject(storageRef);
6
+ },
7
+ fetchObject: async path => {
8
+ const storageRef = ref(storage, path);
9
+ const url = await getDownloadURL(storageRef);
10
+ const response = await fetch(url);
11
+ return await response.blob();
12
+ },
13
+ fetchMetadata: async path => {
14
+ const storageRef = ref(storage, path);
15
+ return await getMetadata(storageRef);
16
+ },
17
+ getObjectUrl: async path => {
18
+ const storageRef = ref(storage, path);
19
+ return await getDownloadURL(storageRef);
20
+ },
21
+ upload: async (path, data, onUploadProgress) => {
22
+ const storageRef = ref(storage, path);
23
+ // Convert dataUrl to Blob
24
+ const blob = await fetch(data.dataUrl).then(res => res.blob());
25
+ const uploadTask = uploadBytesResumable(storageRef, blob);
26
+ return new Promise((resolve, reject) => {
27
+ uploadTask.on('state_changed', snapshot => {
28
+ const progress = snapshot.bytesTransferred / snapshot.totalBytes * 100;
29
+ onUploadProgress({
30
+ loaded: snapshot.bytesTransferred,
31
+ total: snapshot.totalBytes,
32
+ percent: progress
33
+ });
34
+ }, error => reject(error), () => {
35
+ const fileValue = {
36
+ filename: data.filename,
37
+ type: data.type,
38
+ storagePath: path
39
+ };
40
+ resolve(fileValue);
41
+ });
42
+ });
43
+ }
44
+ });
45
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["deleteObject","getDownloadURL","getMetadata","ref","uploadBytesResumable","getFirebaseStorageAdapter","storage","delete","path","storageRef","fetchObject","url","response","fetch","blob","fetchMetadata","getObjectUrl","upload","data","onUploadProgress","dataUrl","then","res","uploadTask","Promise","resolve","reject","on","snapshot","progress","bytesTransferred","totalBytes","loaded","total","percent","error","fileValue","filename","type","storagePath"],"sourceRoot":"..\\..\\..\\src","sources":["adapter/storage.ts"],"mappings":"AACA,SACEA,YAAY,EACZC,cAAc,EACdC,WAAW,EACXC,GAAG,EACHC,oBAAoB,QACf,gCAAgC;AAGvC,OAAO,MAAMC,yBAAyB,GAAIC,OAAgB,KAAiC;EACzFC,MAAM,EAAE,MAAMC,IAAI,IAAI;IACpB,MAAMC,UAAU,GAAGN,GAAG,CAACG,OAAO,EAAEE,IAAI,CAAC;IACrC,MAAMR,YAAY,CAACS,UAAU,CAAC;EAChC,CAAC;EACDC,WAAW,EAAE,MAAMF,IAAI,IAAI;IACzB,MAAMC,UAAU,GAAGN,GAAG,CAACG,OAAO,EAAEE,IAAI,CAAC;IACrC,MAAMG,GAAG,GAAG,MAAMV,cAAc,CAACQ,UAAU,CAAC;IAC5C,MAAMG,QAAQ,GAAG,MAAMC,KAAK,CAACF,GAAG,CAAC;IACjC,OAAO,MAAMC,QAAQ,CAACE,IAAI,CAAC,CAAC;EAC9B,CAAC;EACDC,aAAa,EAAE,MAAMP,IAAI,IAAI;IAC3B,MAAMC,UAAU,GAAGN,GAAG,CAACG,OAAO,EAAEE,IAAI,CAAC;IACrC,OAAO,MAAMN,WAAW,CAACO,UAAU,CAAC;EACtC,CAAC;EACDO,YAAY,EAA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const getThirdPartyAuthToken = functions => functions.httpsCallable('getThirdPartyAuthToken');
3
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getThirdPartyAuthUrl","functions","httpsCallable","getThirdPartyAuthToken"],"sourceRoot":"..\\..\\..\\src","sources":["auth/functions.ts"],"mappings":"AAEA,OAAO,MAAMA,oBAAoB,GAAIC,SAAwC,IAC3EA,SAAS,CAACC,aAAa,CAAC,sBAAsB,CAAC;AAEjD,OAAO,MAAMC,sBAAsB,GAAIF,SAAwC,IAC7EA,SAAS,CAACC,aAAa,CAAC,wBAAwB,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export * from './functions';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"..\\..\\..\\src","sources":["auth/index.ts"],"mappings":"AAAA,cAAc,aAAa","ignoreList":[]}