@umituz/react-native-auth 1.6.1 → 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.
|
|
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
|
|
@@ -204,6 +207,16 @@ export class AuthService implements IAuthService {
|
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
209
|
|
|
210
|
+
// Clear guest mode when user signs up
|
|
211
|
+
if (this.isGuestMode) {
|
|
212
|
+
this.isGuestMode = false;
|
|
213
|
+
try {
|
|
214
|
+
await storageRepository.removeItem(GUEST_MODE_KEY);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
// Ignore storage errors
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
207
220
|
// Emit event for AppNavigator to handle navigation
|
|
208
221
|
DeviceEventEmitter.emit("user-authenticated", { userId: userCredential.user.uid });
|
|
209
222
|
|
|
@@ -242,6 +255,11 @@ export class AuthService implements IAuthService {
|
|
|
242
255
|
// Clear guest mode when user signs in
|
|
243
256
|
if (this.isGuestMode) {
|
|
244
257
|
this.isGuestMode = false;
|
|
258
|
+
try {
|
|
259
|
+
await storageRepository.removeItem(GUEST_MODE_KEY);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
// Ignore storage errors
|
|
262
|
+
}
|
|
245
263
|
}
|
|
246
264
|
|
|
247
265
|
// Emit event for AppNavigator to handle navigation
|
|
@@ -261,13 +279,18 @@ export class AuthService implements IAuthService {
|
|
|
261
279
|
if (!auth) {
|
|
262
280
|
// If auth is not initialized, just clear guest mode
|
|
263
281
|
this.isGuestMode = false;
|
|
282
|
+
try {
|
|
283
|
+
await storageRepository.removeItem(GUEST_MODE_KEY);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
// Ignore storage errors
|
|
286
|
+
}
|
|
264
287
|
return;
|
|
265
288
|
}
|
|
266
289
|
|
|
267
290
|
try {
|
|
268
291
|
await firebaseSignOut(auth);
|
|
269
|
-
|
|
270
|
-
|
|
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
|
|
271
294
|
} catch (error: any) {
|
|
272
295
|
throw mapFirebaseAuthError(error);
|
|
273
296
|
}
|
|
@@ -290,6 +313,13 @@ export class AuthService implements IAuthService {
|
|
|
290
313
|
|
|
291
314
|
this.isGuestMode = true;
|
|
292
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
|
+
|
|
293
323
|
// Emit event for AppNavigator to handle navigation
|
|
294
324
|
DeviceEventEmitter.emit("guest-mode-enabled");
|
|
295
325
|
}
|
|
@@ -353,17 +383,17 @@ let authServiceInstance: AuthService | null = null;
|
|
|
353
383
|
* @param auth - Firebase Auth instance
|
|
354
384
|
* @param config - Optional auth configuration (defaults to permissive settings)
|
|
355
385
|
*/
|
|
356
|
-
export function initializeAuthService(
|
|
386
|
+
export async function initializeAuthService(
|
|
357
387
|
auth: Auth,
|
|
358
388
|
config?: AuthConfig
|
|
359
|
-
): AuthService {
|
|
389
|
+
): Promise<AuthService> {
|
|
360
390
|
// Use default config if not provided (permissive settings for better UX)
|
|
361
391
|
const finalConfig = config || DEFAULT_AUTH_CONFIG;
|
|
362
392
|
|
|
363
393
|
if (!authServiceInstance) {
|
|
364
394
|
authServiceInstance = new AuthService(finalConfig);
|
|
365
395
|
}
|
|
366
|
-
authServiceInstance.initialize(auth);
|
|
396
|
+
await authServiceInstance.initialize(auth);
|
|
367
397
|
return authServiceInstance;
|
|
368
398
|
}
|
|
369
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();
|