@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
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # @chem-po/firebase-native
2
+
3
+ React Native Firebase integration for ChemPo ecosystem.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ ### Prerequisites
8
+
9
+ Before using this package, ensure your React Native app has:
10
+
11
+ 1. **Firebase Project Setup**
12
+
13
+ - Create a Firebase project at https://console.firebase.google.com
14
+ - Enable Authentication with desired providers (Email/Password, Google)
15
+ - Enable Firestore Database
16
+ - Enable Cloud Storage
17
+
18
+ 2. **Platform Configuration**
19
+
20
+ #### iOS Setup
21
+
22
+ 1. Download `GoogleService-Info.plist` from Firebase Console
23
+ 2. Add it to your iOS project root
24
+ 3. Configure URL schemes in `ios/[ProjectName]/Info.plist`:
25
+
26
+ ```xml
27
+ <key>CFBundleURLTypes</key>
28
+ <array>
29
+ <dict>
30
+ <key>CFBundleURLName</key>
31
+ <string>REVERSED_CLIENT_ID</string>
32
+ <key>CFBundleURLSchemes</key>
33
+ <array>
34
+ <string>YOUR_REVERSED_CLIENT_ID</string>
35
+ </array>
36
+ </dict>
37
+ </array>
38
+ ```
39
+
40
+ #### Android Setup
41
+
42
+ 1. Download `google-services.json` from Firebase Console
43
+ 2. Place it in `android/app/google-services.json`
44
+ 3. Ensure package name matches Firebase configuration
45
+
46
+ ### Installation
47
+
48
+ ```bash
49
+ npm install @chem-po/firebase-native
50
+ # or
51
+ yarn add @chem-po/firebase-native
52
+ ```
53
+
54
+ ### Required Peer Dependencies
55
+
56
+ ```bash
57
+ npm install @react-native-firebase/app @react-native-firebase/auth @react-native-firebase/firestore @react-native-firebase/storage @react-native-firebase/functions @react-native-google-signin/google-signin
58
+ ```
59
+
60
+ ## 📱 Configuration
61
+
62
+ ### 1. Firebase Initialization
63
+
64
+ ```typescript
65
+ import { getAuth } from '@react-native-firebase/auth'
66
+ import { getFirestore } from '@react-native-firebase/firestore'
67
+ import { getStorage } from '@react-native-firebase/storage'
68
+ import { getFunctions } from '@react-native-firebase/functions'
69
+ import { getFirebaseAdapter } from '@chem-po/firebase-native'
70
+
71
+ // Initialize Firebase services
72
+ const auth = getAuth()
73
+ const firestore = getFirestore()
74
+ const storage = getStorage()
75
+ const functions = getFunctions()
76
+
77
+ // Create backend adapter
78
+ const backendAdapter = getFirebaseAdapter(
79
+ auth,
80
+ firestore,
81
+ storage,
82
+ functions,
83
+ true // Enable two-factor authentication
84
+ )
85
+ ```
86
+
87
+ ### 2. Google Authentication Setup
88
+
89
+ **⚠️ REQUIRED**: You must provide your Google Web Client ID:
90
+
91
+ ```typescript
92
+ import { GoogleAuthProvider } from '@chem-po/core'
93
+
94
+ // Get this from Firebase Console > Authentication > Sign-in method > Google > Web SDK configuration
95
+ const googleAuthProvider: GoogleAuthProvider = {
96
+ name: 'google',
97
+ webClientId: 'YOUR_GOOGLE_WEB_CLIENT_ID.apps.googleusercontent.com',
98
+ }
99
+ ```
100
+
101
+ ### 3. Provider Setup
102
+
103
+ ```typescript
104
+ import { ChempoNativeProvider } from '@chem-po/react-native'
105
+ import { FirebaseSignIn } from '@chem-po/firebase-native'
106
+
107
+ export default function App() {
108
+ return (
109
+ <ChempoNativeProvider backendAdapter={backendAdapter}>
110
+ <FirebaseSignIn googleProvider={googleAuthProvider} />
111
+ </ChempoNativeProvider>
112
+ )
113
+ }
114
+ ```
115
+
116
+ ## 🔐 Environment Variables
117
+
118
+ For debug logging (optional):
119
+
120
+ ```bash
121
+ EXPO_PUBLIC_DEBUG=true # Enable debug logging
122
+ ```
123
+
124
+ ## 🔧 Configuration Validation
125
+
126
+ Use the built-in validation helper to identify setup issues early:
127
+
128
+ ```typescript
129
+ import { validateAndLogAuthConfig } from '@chem-po/firebase-native'
130
+
131
+ // Validate your auth providers configuration
132
+ const providers = [googleAuthProvider] // Your auth providers
133
+ validateAndLogAuthConfig(providers)
134
+ ```
135
+
136
+ This will output helpful warnings and errors if configuration is missing or incorrect:
137
+
138
+ - ❌ Missing Google webClientId
139
+ - ⚠️ Incorrect webClientId format
140
+ - ⚠️ Missing Firebase configuration files
141
+
142
+ **Tip**: Call this during development to catch configuration issues before they cause runtime errors.
143
+
144
+ ## 🚨 Common Issues
145
+
146
+ ### "Google web client ID is required"
147
+
148
+ - Ensure you've added the `webClientId` to your Google auth provider
149
+ - Verify the client ID matches your Firebase project configuration
150
+ - Use the validation helper to check your configuration
151
+
152
+ ### "No user found"
153
+
154
+ - Check Firebase Authentication is enabled
155
+ - Verify Google Services files are properly configured
156
+ - Ensure bundle ID/package name matches Firebase project
157
+
158
+ ### Multi-factor Authentication Issues
159
+
160
+ - Ensure users have enrolled MFA factors via Firebase Console
161
+ - Check that `twoFactorRequired` parameter matches your requirements
162
+
163
+ ### Google Play Services Issues
164
+
165
+ - Ensure Google Play Services is installed and up to date
166
+ - Check that your app's package name matches Firebase configuration
167
+
168
+ ## 📚 API Reference
169
+
170
+ ### getFirebaseAdapter
171
+
172
+ Creates a Firebase backend adapter with authentication, database, and storage.
173
+
174
+ ```typescript
175
+ getFirebaseAdapter(
176
+ auth: Auth,
177
+ db: Firestore,
178
+ storage: Storage,
179
+ functions: Functions,
180
+ twoFactorRequired: boolean
181
+ ): FirebaseAdapter
182
+ ```
183
+
184
+ ### FirebaseSignIn Component
185
+
186
+ Pre-built authentication component with Google Sign-in support.
187
+
188
+ ```typescript
189
+ <FirebaseSignIn
190
+ googleProvider={googleAuthProvider}
191
+ />
192
+ ```
193
+
194
+ ### Configuration Validation
195
+
196
+ Utility functions to validate your Firebase configuration:
197
+
198
+ ```typescript
199
+ // Validate configuration and get results
200
+ const result = validateAuthConfiguration(providers)
201
+
202
+ // Validate and log results automatically
203
+ validateAndLogAuthConfig(providers)
204
+
205
+ // Custom logging
206
+ logValidationResults(result, 'MyApp')
207
+ ```
208
+
209
+ ## 🤝 Support
210
+
211
+ For issues related to:
212
+
213
+ - Firebase configuration: Check [Firebase Documentation](https://firebase.google.com/docs)
214
+ - React Native Firebase: Check [@react-native-firebase/app](https://rnfirebase.io/)
215
+ - Google Sign-in: Check [@react-native-google-signin](https://github.com/react-native-google-signin/google-signin)
@@ -0,0 +1,431 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getFirebaseAuthAdapter = void 0;
7
+ var _auth = require("@react-native-firebase/auth");
8
+ var _googleSignin = require("@react-native-google-signin/google-signin");
9
+ var _process$env;
10
+ const isDebug = typeof process !== 'undefined' && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.EXPO_PUBLIC_DEBUG) === 'true' || false;
11
+ const debugLog = (message, data) => {
12
+ if (isDebug) {
13
+ console.log(`[FirebaseAuth Debug] ${message}`, data || '');
14
+ }
15
+ };
16
+ const providerInitialized = {};
17
+ const getUserWithRole = async user => {
18
+ debugLog('Getting user with role', {
19
+ uid: user.uid,
20
+ email: user.email
21
+ });
22
+ try {
23
+ var _user$multiFactor, _user$multiFactor2;
24
+ const {
25
+ claims
26
+ } = await (0, _auth.getIdTokenResult)(user);
27
+ debugLog('Retrieved ID token claims', {
28
+ role: claims.role,
29
+ customClaims: Object.keys(claims)
30
+ });
31
+ const userWithRole = {
32
+ ...user,
33
+ role: claims.role ?? 'user',
34
+ multiFactorVerified: !!((_user$multiFactor = user.multiFactor) !== null && _user$multiFactor !== void 0 && _user$multiFactor.enrolledFactors.length)
35
+ };
36
+ debugLog('User with role created', {
37
+ uid: userWithRole.uid,
38
+ role: userWithRole.role,
39
+ multiFactorVerified: userWithRole.multiFactorVerified,
40
+ enrolledFactorsCount: ((_user$multiFactor2 = user.multiFactor) === null || _user$multiFactor2 === void 0 ? void 0 : _user$multiFactor2.enrolledFactors.length) || 0
41
+ });
42
+ return userWithRole;
43
+ } catch (error) {
44
+ debugLog('Error getting user with role', error);
45
+ throw error;
46
+ }
47
+ };
48
+ const toEnrollmentFactor = hint => {
49
+ if (hint.factorId === _auth.PhoneMultiFactorGenerator.FACTOR_ID) {
50
+ return {
51
+ type: 'phone',
52
+ phoneNumber: hint.phoneNumber,
53
+ enrollmentTime: hint.enrollmentTime,
54
+ displayName: hint.displayName,
55
+ uid: hint.uid
56
+ };
57
+ }
58
+ if (hint.factorId === 'totp') {
59
+ return {
60
+ type: 'totp',
61
+ enrollmentTime: hint.enrollmentTime,
62
+ displayName: hint.displayName,
63
+ uid: hint.uid
64
+ };
65
+ }
66
+ throw new Error('Unsupported factor type: ' + hint.factorId);
67
+ };
68
+ const toFirebaseFactor = factor => {
69
+ if (factor.type === 'phone') {
70
+ return {
71
+ factorId: _auth.PhoneMultiFactorGenerator.FACTOR_ID,
72
+ phoneNumber: factor.phoneNumber,
73
+ enrollmentTime: factor.enrollmentTime,
74
+ uid: factor.uid,
75
+ displayName: factor.displayName
76
+ };
77
+ }
78
+ if (factor.type === 'totp') {
79
+ return {
80
+ factorId: 'totp',
81
+ enrollmentTime: factor.enrollmentTime,
82
+ uid: factor.uid,
83
+ displayName: factor.displayName
84
+ };
85
+ }
86
+ throw new Error(`Unsupported factor type: ${factor.factorId ?? 'Missing factor type'}`);
87
+ };
88
+ const sendMultiFactorCode = async (auth, factor, resolver) => {
89
+ debugLog('Sending multi-factor code', {
90
+ factorType: factor.type,
91
+ factorUid: factor.uid
92
+ });
93
+ const sessionId = resolver.session;
94
+ // const verificationId = await new PhoneAuthProvider(auth).verifyPhoneNumber(phoneSignInFactor, sessionId)
95
+ if (factor.type === 'phone') {
96
+ try {
97
+ const verificationId = await auth.verifyPhoneNumberWithMultiFactorInfo(toFirebaseFactor(factor), sessionId);
98
+ debugLog('Multi-factor code sent successfully', {
99
+ verificationId: verificationId.substring(0, 10) + '...'
100
+ });
101
+ return {
102
+ verificationId,
103
+ factor,
104
+ resolver
105
+ };
106
+ } catch (error) {
107
+ debugLog('Error sending multi-factor code', error);
108
+ throw error;
109
+ }
110
+ }
111
+ throw new Error(`Unsupported factor type: ${factor.type ?? 'Missing factor type'}`);
112
+ };
113
+ const getEnrolledFactors = async (auth, error) => {
114
+ debugLog('Getting enrolled factors from error', {
115
+ errorCode: error === null || error === void 0 ? void 0 : error.code
116
+ });
117
+ try {
118
+ const resolver = (0, _auth.getMultiFactorResolver)(auth, error);
119
+ debugLog('Multi-factor resolver created', {
120
+ hintsCount: resolver.hints.length
121
+ });
122
+ if (resolver.hints.length === 0) {
123
+ debugLog('No enrolled factors found');
124
+ throw new Error('No multi-factor verification methods found, please enroll one on the website');
125
+ }
126
+ const enrollmentFactors = resolver.hints.map(toEnrollmentFactor);
127
+ debugLog('Enrollment factors mapped', {
128
+ factors: enrollmentFactors.map(f => ({
129
+ type: f.type,
130
+ uid: f.uid
131
+ }))
132
+ });
133
+ return {
134
+ enrollmentFactors,
135
+ multiFactorResolver: resolver
136
+ };
137
+ } catch (error) {
138
+ debugLog('Error getting enrolled factors', error);
139
+ throw error;
140
+ }
141
+ };
142
+ const verifyMultiFactor = async (verification, code) => {
143
+ debugLog('Verifying multi-factor code', {
144
+ factorType: verification.factor.type,
145
+ codeLength: code.length
146
+ });
147
+ try {
148
+ var _userCredential$user;
149
+ const credential = await _auth.PhoneAuthProvider.credential(verification.verificationId, code);
150
+ debugLog('Phone credential created');
151
+ const assertion = _auth.PhoneMultiFactorGenerator.assertion(credential);
152
+ debugLog('Multi-factor assertion created');
153
+ const resolver = verification.resolver;
154
+ if (!resolver) {
155
+ debugLog('Multi-factor resolver not found');
156
+ throw new Error('Internal error signing in with two factor: resolver not found');
157
+ }
158
+ const userCredential = await resolver.resolveSignIn(assertion);
159
+ debugLog('Multi-factor sign-in resolved', {
160
+ uid: (_userCredential$user = userCredential.user) === null || _userCredential$user === void 0 ? void 0 : _userCredential$user.uid
161
+ });
162
+ const user = userCredential.user;
163
+ if (!user) {
164
+ debugLog('No user found after multi-factor resolution');
165
+ throw new Error('No user found');
166
+ }
167
+ const userWithRole = await getUserWithRole(user);
168
+ debugLog('Multi-factor verification completed successfully');
169
+ return {
170
+ user: userWithRole
171
+ };
172
+ } catch (error) {
173
+ debugLog('Error verifying multi-factor', error);
174
+ throw error;
175
+ }
176
+ };
177
+ const handleSignInError = async error => {
178
+ debugLog('Handling sign-in error', {
179
+ code: error === null || error === void 0 ? void 0 : error.code,
180
+ message: error === null || error === void 0 ? void 0 : error.message
181
+ });
182
+ if (error.code === 'auth/multi-factor-auth-required') {
183
+ debugLog('Multi-factor authentication required');
184
+ return {
185
+ requestArgs: error
186
+ };
187
+ }
188
+ debugLog('Re-throwing sign-in error');
189
+ throw error;
190
+ };
191
+ const initializeProvider = async provider => {
192
+ debugLog('Initializing provider', {
193
+ name: provider.name,
194
+ alreadyInitialized: providerInitialized[provider.name]
195
+ });
196
+ if (providerInitialized[provider.name]) {
197
+ debugLog('Provider already initialized, skipping');
198
+ return;
199
+ }
200
+ switch (provider.name) {
201
+ case 'google':
202
+ debugLog('Initializing Google provider', {
203
+ webClientId: !!provider.webClientId
204
+ });
205
+ if (!provider.webClientId) {
206
+ debugLog('Google web client ID missing');
207
+ 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" }');
208
+ }
209
+ try {
210
+ await _googleSignin.GoogleSignin.hasPlayServices({
211
+ showPlayServicesUpdateDialog: true
212
+ });
213
+ debugLog('Google Play Services available');
214
+ _googleSignin.GoogleSignin.configure({
215
+ webClientId: provider.webClientId
216
+ });
217
+ debugLog('Google Sign-In configured successfully');
218
+ } catch (error) {
219
+ debugLog('Error initializing Google provider', error);
220
+ if (error instanceof Error && error.message.includes('UNAVAILABLE')) {
221
+ 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.');
222
+ }
223
+ throw error;
224
+ }
225
+ break;
226
+ case 'email':
227
+ debugLog('Email provider initialization (no special setup required)');
228
+ // Native SDK doesn't need special initialization
229
+ break;
230
+ default:
231
+ debugLog('Unsupported provider', {
232
+ name: provider.name
233
+ });
234
+ throw new Error(`Unsupported provider: ${provider.name}`);
235
+ }
236
+ providerInitialized[provider.name] = true;
237
+ debugLog('Provider initialization completed', {
238
+ name: provider.name
239
+ });
240
+ };
241
+ const handleInitialLogin = async (userCredential, twoFactorRequired) => {
242
+ var _userCredential$user2, _userCredential$user3;
243
+ debugLog('Handling initial login', {
244
+ uid: (_userCredential$user2 = userCredential.user) === null || _userCredential$user2 === void 0 ? void 0 : _userCredential$user2.uid,
245
+ twoFactorRequired,
246
+ 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
247
+ });
248
+ const user = userCredential.user;
249
+ if (!user) {
250
+ debugLog('No user found in credential');
251
+ throw new Error('No user found');
252
+ }
253
+ if (twoFactorRequired) {
254
+ debugLog('Two-factor authentication is required but user has no enrolled factors');
255
+ throw new Error('This app requires two factor authentication, please enroll a factor on the website and try again');
256
+ }
257
+ const userWithRole = await getUserWithRole(user);
258
+ debugLog('Initial login completed successfully');
259
+ return {
260
+ user: userWithRole
261
+ };
262
+ };
263
+ const loginWithGoogle = async (auth, twoFactorRequired) => {
264
+ debugLog('Starting Google sign-in', {
265
+ twoFactorRequired
266
+ });
267
+ try {
268
+ var _signInResult$data, _signInResult$data2;
269
+ debugLog('Calling GoogleSignin.signIn()');
270
+ const signInResult = await _googleSignin.GoogleSignin.signIn();
271
+ debugLog('Google sign-in result received', {
272
+ hasIdToken: !!((_signInResult$data = signInResult.data) !== null && _signInResult$data !== void 0 && _signInResult$data.idToken)
273
+ });
274
+ const idToken = (_signInResult$data2 = signInResult.data) === null || _signInResult$data2 === void 0 ? void 0 : _signInResult$data2.idToken;
275
+ if (!idToken) {
276
+ debugLog('No ID token found in Google sign-in result');
277
+ throw new Error('No ID token found');
278
+ }
279
+ debugLog('Creating Google credential');
280
+ const googleCredential = _auth.GoogleAuthProvider.credential(idToken);
281
+ debugLog('Signing in with Google credential');
282
+ const userCredential = await (0, _auth.signInWithCredential)(auth, googleCredential);
283
+ return await handleInitialLogin(userCredential, twoFactorRequired);
284
+ } catch (error) {
285
+ debugLog('Error in Google sign-in', error);
286
+ return await handleSignInError(error);
287
+ }
288
+ };
289
+ const getLoginWithPassword = (auth, twoFactorRequired) => async (provider, {
290
+ email,
291
+ password
292
+ }) => {
293
+ debugLog('Starting email/password sign-in', {
294
+ provider: provider.name,
295
+ email,
296
+ twoFactorRequired
297
+ });
298
+ await initializeProvider(provider);
299
+ try {
300
+ var _userCredential$user4;
301
+ debugLog('Calling signInWithEmailAndPassword');
302
+ const userCredential = await (0, _auth.signInWithEmailAndPassword)(auth, email, password);
303
+ debugLog('Email/password sign-in successful', {
304
+ uid: (_userCredential$user4 = userCredential.user) === null || _userCredential$user4 === void 0 ? void 0 : _userCredential$user4.uid
305
+ });
306
+ return await handleInitialLogin(userCredential, twoFactorRequired);
307
+ } catch (error) {
308
+ debugLog('Error in email/password sign-in', error);
309
+ return await handleSignInError(error);
310
+ }
311
+ };
312
+ const getLoginWithPopup = (auth, twoFactorRequired) => async provider => {
313
+ debugLog('Starting popup sign-in', {
314
+ provider: provider.name,
315
+ twoFactorRequired
316
+ });
317
+ await initializeProvider(provider);
318
+ switch (provider.name) {
319
+ case 'google':
320
+ return loginWithGoogle(auth, twoFactorRequired);
321
+ default:
322
+ debugLog('Unsupported popup provider', {
323
+ name: provider.name
324
+ });
325
+ throw new Error(`Unsupported provider: ${provider.name}`);
326
+ }
327
+ };
328
+ const getLoginWithToken = (auth, twoFactorRequired) => async (provider, token) => {
329
+ debugLog('Starting token sign-in', {
330
+ provider: provider.name,
331
+ tokenLength: token.length,
332
+ twoFactorRequired
333
+ });
334
+ await initializeProvider(provider);
335
+ try {
336
+ var _userCredential$user5;
337
+ debugLog('Calling signInWithCustomToken');
338
+ const userCredential = await (0, _auth.signInWithCustomToken)(auth, token);
339
+ debugLog('Token sign-in successful', {
340
+ uid: (_userCredential$user5 = userCredential.user) === null || _userCredential$user5 === void 0 ? void 0 : _userCredential$user5.uid
341
+ });
342
+ return await handleInitialLogin(userCredential, twoFactorRequired);
343
+ } catch (error) {
344
+ debugLog('Error in token sign-in', error);
345
+ return await handleSignInError(error);
346
+ }
347
+ };
348
+ const resetPassword = async (auth, provider, usernameOrEmail) => {
349
+ debugLog('Starting password reset', {
350
+ provider: provider.name,
351
+ email: usernameOrEmail
352
+ });
353
+ await initializeProvider(provider);
354
+ try {
355
+ await (0, _auth.sendPasswordResetEmail)(auth, usernameOrEmail);
356
+ debugLog('Password reset email sent successfully');
357
+ } catch (error) {
358
+ debugLog('Error sending password reset email', error);
359
+ throw error;
360
+ }
361
+ };
362
+ const getFirebaseAuthAdapter = (auth, twoFactorRequired) => {
363
+ debugLog('Creating Firebase Auth Adapter', {
364
+ twoFactorRequired
365
+ });
366
+ return {
367
+ twoFactorRequired,
368
+ getCurrentUser: async () => {
369
+ debugLog('Getting current user');
370
+ const user = auth.currentUser;
371
+ if (!user) {
372
+ debugLog('No current user found');
373
+ return null;
374
+ }
375
+ debugLog('Current user found', {
376
+ uid: user.uid,
377
+ email: user.email
378
+ });
379
+ return getUserWithRole(user);
380
+ },
381
+ loginWithPassword: getLoginWithPassword(auth, twoFactorRequired),
382
+ loginWithPopup: getLoginWithPopup(auth, twoFactorRequired),
383
+ loginWithToken: getLoginWithToken(auth, twoFactorRequired),
384
+ resetPassword: (...args) => {
385
+ return resetPassword(auth, ...args);
386
+ },
387
+ verifyMultiFactor,
388
+ sendMultiFactorCode: (...args) => {
389
+ return sendMultiFactorCode(auth, ...args);
390
+ },
391
+ getEnrolledFactors: (...args) => {
392
+ return getEnrolledFactors(auth, ...args);
393
+ },
394
+ logout: async () => {
395
+ debugLog('Starting logout');
396
+ try {
397
+ await (0, _auth.signOut)(auth);
398
+ debugLog('Logout completed successfully');
399
+ } catch (error) {
400
+ debugLog('Error during logout', error);
401
+ throw error;
402
+ }
403
+ },
404
+ subscribeToUser: callback => {
405
+ debugLog('Setting up user subscription');
406
+ return (0, _auth.onAuthStateChanged)(auth, user => {
407
+ if (!user) {
408
+ debugLog('User state changed: signed out');
409
+ callback(null);
410
+ return;
411
+ }
412
+ debugLog('User state changed: user signed in', {
413
+ uid: user.uid,
414
+ email: user.email
415
+ });
416
+ getUserWithRole(user).then(result => {
417
+ debugLog('User subscription callback completed', {
418
+ uid: result.uid,
419
+ role: result.role
420
+ });
421
+ callback(result);
422
+ }).catch(error => {
423
+ debugLog('Error in user subscription callback', error);
424
+ callback(null);
425
+ });
426
+ });
427
+ }
428
+ };
429
+ };
430
+ exports.getFirebaseAuthAdapter = getFirebaseAuthAdapter;
431
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_auth","require","_googleSignin","_process$env","isDebug","process","env","EXPO_PUBLIC_DEBUG","debugLog","message","data","console","log","providerInitialized","getUserWithRole","user","uid","email","_user$multiFactor","_user$multiFactor2","claims","getIdTokenResult","role","customClaims","Object","keys","userWithRole","multiFactorVerified","multiFactor","enrolledFactors","length","enrolledFactorsCount","error","toEnrollmentFactor","hint","factorId","PhoneMultiFactorGenerator","FACTOR_ID","type","phoneNumber","enrollmentTime","displayName","Error","toFirebaseFactor","factor","sendMultiFactorCode","auth","resolver","factorType","factorUid","sessionId","session","verificationId","verifyPhoneNumberWithMultiFactorInfo","substring","getEnrolledFactors","errorCode","code","getMultiFactorResolver","hintsCount","hints","enrollmentFactors","map","factors","f","multiFactorResolver","verifyMultiFactor","verification","codeLength","_userCredential$user","credential","PhoneAuthProvider","assertion","userCredential","resolveSignIn","handleSignInError","requestArgs","initializeProvider","provider","name","alreadyInitialized","webClientId","GoogleSignin","hasPlayServices","showPlayServicesUpdateDialog","configure","includes","handleInitialLogin","twoFactorRequired","_userCredential$user2","_userCredential$user3","loginWithGoogle","_signInResult$data","_signInResult$data2","signInResult","signIn","hasIdToken","idToken","googleCredential","GoogleAuthProvider","signInWithCredential","getLoginWithPassword","password","_userCredential$user4","signInWithEmailAndPassword","getLoginWithPopup","getLoginWithToken","token","tokenLength","_userCredential$user5","signInWithCustomToken","resetPassword","usernameOrEmail","sendPasswordResetEmail","getFirebaseAuthAdapter","getCurrentUser","currentUser","loginWithPassword","loginWithPopup","loginWithToken","args","logout","signOut","subscribeToUser","callback","onAuthStateChanged","then","result","catch","exports"],"sourceRoot":"..\\..\\..\\src","sources":["adapter/auth.ts"],"mappings":";;;;;;AAWA,IAAAA,KAAA,GAAAC,OAAA;AAeA,IAAAC,aAAA,GAAAD,OAAA;AAAwE,IAAAE,YAAA;AAGxE,MAAMC,OAAO,GACX,OAAOC,OAAO,KAAK,WAAW,IAC9B,EAAAF,YAAA,GAAAE,OAAO,CAACC,GAAG,cAAAH,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