@umituz/react-native-auth 4.3.83 → 4.3.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-auth",
3
- "version": "4.3.83",
3
+ "version": "4.3.85",
4
4
  "description": "Authentication service for React Native apps - Secure, type-safe, and production-ready. Provider-agnostic design with dependency injection, configurable validation, and comprehensive error handling.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -26,7 +26,24 @@ export class AuthService {
26
26
  }
27
27
 
28
28
  private get repositoryInstance(): AuthRepository {
29
- if (!this.initialized) throw new Error("AuthService not initialized");
29
+ if (!this.initialized) {
30
+ // Only auto-initialize in development for better DX
31
+ if (__DEV__) {
32
+ console.warn('[AuthService] Not initialized - auto-initializing for development. In production, call initialize() explicitly before using auth methods.');
33
+ this.initialize().catch((error) => {
34
+ console.error('[AuthService] Auto-initialization failed:', error);
35
+ throw new Error("AuthService not initialized. Please ensure Firebase Auth is properly configured.");
36
+ });
37
+ // Create repository immediately for synchronous operations
38
+ if (!this.repository) {
39
+ this.repository = new AuthRepository(this.config);
40
+ this.initialized = true;
41
+ }
42
+ } else {
43
+ // In production, fail fast with clear error
44
+ throw new Error("AuthService not initialized. Please call initializeAuth() during app startup.");
45
+ }
46
+ }
30
47
  return this.repository;
31
48
  }
32
49
 
@@ -133,7 +150,26 @@ export async function initializeAuthService(
133
150
  }
134
151
 
135
152
  export function getAuthService(): AuthService | null {
136
- return (authServiceInstance && authServiceInstance.isInitialized()) ? authServiceInstance : null;
153
+ if (!authServiceInstance) {
154
+ if (__DEV__) {
155
+ console.warn('[AuthService] Auto-creating service instance. Call initializeAuth() explicitly in production.');
156
+ }
157
+ authServiceInstance = new AuthService();
158
+ }
159
+
160
+ // Only attempt auto-initialization in development
161
+ if (!authServiceInstance.isInitialized() && __DEV__) {
162
+ authServiceInstance.initialize().catch(() => {
163
+ // Error handled by service
164
+ });
165
+ }
166
+
167
+ // In production, return null if not initialized to fail fast
168
+ if (!authServiceInstance.isInitialized()) {
169
+ return null;
170
+ }
171
+
172
+ return authServiceInstance;
137
173
  }
138
174
 
139
175
  export function resetAuthService(): void {
@@ -73,7 +73,7 @@ export function createAuthInitModule(
73
73
  storageProvider,
74
74
  onRestorePurchases,
75
75
  onUserConverted,
76
- critical = false,
76
+ critical = true, // Auth is CRITICAL for app functionality
77
77
  dependsOn = ['firebase'],
78
78
  } = config;
79
79
 
@@ -12,7 +12,9 @@ export const useSignUpMutation = () => {
12
12
  return useMutation({
13
13
  mutationFn: async (params: SignUpCredentials): Promise<AuthUser> => {
14
14
  const service = getAuthService();
15
- if (!service) throw new Error("Auth Service not initialized");
15
+ if (!service) {
16
+ throw new Error("Authentication service not available. Please check your internet connection and restart the app.");
17
+ }
16
18
  return service.signUp(params);
17
19
  },
18
20
  });
@@ -22,7 +24,9 @@ export const useSignInMutation = () => {
22
24
  return useMutation({
23
25
  mutationFn: async (params: AuthCredentials): Promise<AuthUser> => {
24
26
  const service = getAuthService();
25
- if (!service) throw new Error("Auth Service not initialized");
27
+ if (!service) {
28
+ throw new Error("Authentication service not available. Please check your internet connection and restart the app.");
29
+ }
26
30
  return service.signIn(params);
27
31
  },
28
32
  });
@@ -32,7 +36,9 @@ export const useSignOutMutation = () => {
32
36
  return useMutation({
33
37
  mutationFn: async (): Promise<void> => {
34
38
  const service = getAuthService();
35
- if (!service) throw new Error("Auth Service not initialized");
39
+ if (!service) {
40
+ throw new Error("Authentication service not available. Please restart the app.");
41
+ }
36
42
  return service.signOut();
37
43
  },
38
44
  });
@@ -42,7 +48,9 @@ export const useAnonymousModeMutation = () => {
42
48
  return useMutation({
43
49
  mutationFn: async (): Promise<void> => {
44
50
  const service = getAuthService();
45
- if (!service) throw new Error("Auth Service not initialized");
51
+ if (!service) {
52
+ throw new Error("Authentication service not available. Please restart the app.");
53
+ }
46
54
  return service.setAnonymousMode();
47
55
  },
48
56
  });