@umituz/react-native-auth 1.6.2 → 1.6.3

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": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Authentication service for React Native apps - Secure, type-safe, and production-ready. Provider-agnostic design supports Firebase Auth and can be adapted for Supabase or other providers.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -28,6 +28,9 @@ import {
28
28
  import type { AuthConfig } from "../../domain/value-objects/AuthConfig";
29
29
  import { DEFAULT_AUTH_CONFIG } from "../../domain/value-objects/AuthConfig";
30
30
  import { DeviceEventEmitter } from "react-native";
31
+ import { storageRepository } from "@umituz/react-native-storage";
32
+
33
+ const GUEST_MODE_KEY = "@auth_guest_mode";
31
34
 
32
35
  /**
33
36
  * Validate email format
@@ -207,6 +210,11 @@ export class AuthService implements IAuthService {
207
210
  // Clear guest mode when user signs up
208
211
  if (this.isGuestMode) {
209
212
  this.isGuestMode = false;
213
+ try {
214
+ await storageRepository.removeItem(GUEST_MODE_KEY);
215
+ } catch (error) {
216
+ // Ignore storage errors
217
+ }
210
218
  }
211
219
 
212
220
  // Emit event for AppNavigator to handle navigation
@@ -247,6 +255,11 @@ export class AuthService implements IAuthService {
247
255
  // Clear guest mode when user signs in
248
256
  if (this.isGuestMode) {
249
257
  this.isGuestMode = false;
258
+ try {
259
+ await storageRepository.removeItem(GUEST_MODE_KEY);
260
+ } catch (error) {
261
+ // Ignore storage errors
262
+ }
250
263
  }
251
264
 
252
265
  // Emit event for AppNavigator to handle navigation
@@ -266,13 +279,18 @@ export class AuthService implements IAuthService {
266
279
  if (!auth) {
267
280
  // If auth is not initialized, just clear guest mode
268
281
  this.isGuestMode = false;
282
+ try {
283
+ await storageRepository.removeItem(GUEST_MODE_KEY);
284
+ } catch (error) {
285
+ // Ignore storage errors
286
+ }
269
287
  return;
270
288
  }
271
289
 
272
290
  try {
273
291
  await firebaseSignOut(auth);
274
- this.isGuestMode = false;
275
-
292
+ // Don't clear guest mode on sign out - user might want to continue as guest
293
+ // Guest mode will be cleared when user signs in or signs up
276
294
  } catch (error: any) {
277
295
  throw mapFirebaseAuthError(error);
278
296
  }
@@ -295,6 +313,13 @@ export class AuthService implements IAuthService {
295
313
 
296
314
  this.isGuestMode = true;
297
315
 
316
+ // Persist guest mode to storage
317
+ try {
318
+ await storageRepository.setString(GUEST_MODE_KEY, "true");
319
+ } catch (error) {
320
+ // Ignore storage errors - guest mode will still work in memory
321
+ }
322
+
298
323
  // Emit event for AppNavigator to handle navigation
299
324
  DeviceEventEmitter.emit("guest-mode-enabled");
300
325
  }
@@ -358,17 +383,17 @@ let authServiceInstance: AuthService | null = null;
358
383
  * @param auth - Firebase Auth instance
359
384
  * @param config - Optional auth configuration (defaults to permissive settings)
360
385
  */
361
- export function initializeAuthService(
386
+ export async function initializeAuthService(
362
387
  auth: Auth,
363
388
  config?: AuthConfig
364
- ): AuthService {
389
+ ): Promise<AuthService> {
365
390
  // Use default config if not provided (permissive settings for better UX)
366
391
  const finalConfig = config || DEFAULT_AUTH_CONFIG;
367
392
 
368
393
  if (!authServiceInstance) {
369
394
  authServiceInstance = new AuthService(finalConfig);
370
395
  }
371
- authServiceInstance.initialize(auth);
396
+ await authServiceInstance.initialize(auth);
372
397
  return authServiceInstance;
373
398
  }
374
399
 
@@ -124,6 +124,10 @@ export function useAuth(): UseAuthResult {
124
124
  setLoading(true);
125
125
  setError(null);
126
126
  await service.signUp({ email, password, displayName });
127
+ // Clear guest mode when user signs up
128
+ if (isGuest) {
129
+ setIsGuest(false);
130
+ }
127
131
  // User state is updated by Firebase Auth's onAuthStateChanged
128
132
  } catch (err: any) {
129
133
  const errorMessage = err.message || "Sign up failed";
@@ -132,7 +136,7 @@ export function useAuth(): UseAuthResult {
132
136
  } finally {
133
137
  setLoading(false);
134
138
  }
135
- }, []);
139
+ }, [isGuest]);
136
140
 
137
141
  const signIn = useCallback(async (email: string, password: string) => {
138
142
  const service = getAuthService();
@@ -145,6 +149,10 @@ export function useAuth(): UseAuthResult {
145
149
  setLoading(true);
146
150
  setError(null);
147
151
  await service.signIn({ email, password });
152
+ // Clear guest mode when user signs in
153
+ if (isGuest) {
154
+ setIsGuest(false);
155
+ }
148
156
  // User state is updated by Firebase Auth's onAuthStateChanged
149
157
  } catch (err: any) {
150
158
  const errorMessage = err.message || "Failed to sign in";
@@ -153,7 +161,7 @@ export function useAuth(): UseAuthResult {
153
161
  } finally {
154
162
  setLoading(false);
155
163
  }
156
- }, []);
164
+ }, [isGuest]);
157
165
 
158
166
  const signOut = useCallback(async () => {
159
167
  const service = getAuthService();