@umituz/react-native-auth 4.3.32 → 4.3.34
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 +1 -1
- package/src/__tests__/services/AnonymousModeService.test.ts +3 -16
- package/src/infrastructure/services/AnonymousModeService.ts +0 -11
- package/src/infrastructure/services/AuthService.ts +1 -2
- package/src/presentation/hooks/useAuth.ts +4 -1
- package/src/presentation/stores/auth.selectors.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-auth",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.34",
|
|
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",
|
|
@@ -44,23 +44,10 @@ describe('AnonymousModeService', () => {
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
describe('auth integration', () => {
|
|
47
|
-
it('should enable
|
|
48
|
-
|
|
49
|
-
await anonymousModeService.enable(mockStorageProvider
|
|
50
|
-
expect(mockAuth.signOut).toHaveBeenCalled();
|
|
47
|
+
it('should enable anonymous mode', async () => {
|
|
48
|
+
mockStorageProvider.set.mockResolvedValue(undefined);
|
|
49
|
+
await anonymousModeService.enable(mockStorageProvider);
|
|
51
50
|
expect(anonymousModeService.getIsAnonymousMode()).toBe(true);
|
|
52
51
|
});
|
|
53
|
-
|
|
54
|
-
it('should wrap auth state callback correctly', () => {
|
|
55
|
-
const callback = jest.fn();
|
|
56
|
-
const wrapped = anonymousModeService.wrapAuthStateCallback(callback);
|
|
57
|
-
|
|
58
|
-
wrapped({ uid: 'u' } as any);
|
|
59
|
-
expect(callback).toHaveBeenCalledWith({ uid: 'u' });
|
|
60
|
-
|
|
61
|
-
anonymousModeService.setAnonymousMode(true);
|
|
62
|
-
wrapped({ uid: 'u' } as any);
|
|
63
|
-
expect(callback).toHaveBeenCalledWith(null);
|
|
64
|
-
});
|
|
65
52
|
});
|
|
66
53
|
});
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Handles anonymous mode functionality
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { AuthUser } from "../../domain/entities/AuthUser";
|
|
7
6
|
import { emitAnonymousModeEnabled } from "./AuthEventService";
|
|
8
7
|
import type { IStorageProvider } from "../types/Storage.types";
|
|
9
8
|
|
|
@@ -69,14 +68,4 @@ export class AnonymousModeService {
|
|
|
69
68
|
this.isAnonymousMode = enabled;
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
wrapAuthStateCallback(
|
|
73
|
-
callback: (user: AuthUser | null) => void
|
|
74
|
-
): (user: AuthUser | null) => void {
|
|
75
|
-
return (user: AuthUser | null) => {
|
|
76
|
-
// In anonymous mode, still pass the actual Firebase user
|
|
77
|
-
// The store will handle setting the isAnonymous flag appropriately
|
|
78
|
-
// This allows proper anonymous to registered user conversion
|
|
79
|
-
callback(user);
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
71
|
}
|
|
@@ -104,8 +104,7 @@ export class AuthService {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
onAuthStateChange(callback: (user: AuthUser | null) => void): () => void {
|
|
107
|
-
|
|
108
|
-
return this.repositoryInstance.onAuthStateChange(wrappedCallback);
|
|
107
|
+
return this.repositoryInstance.onAuthStateChange(callback);
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
getConfig(): AuthConfig { return this.config; }
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
selectSetError,
|
|
14
14
|
selectSetIsAnonymous,
|
|
15
15
|
selectIsAuthenticated,
|
|
16
|
+
selectHasFirebaseUser,
|
|
16
17
|
selectUserId,
|
|
17
18
|
selectUserType,
|
|
18
19
|
selectIsAnonymous,
|
|
@@ -36,6 +37,7 @@ export interface UseAuthResult {
|
|
|
36
37
|
isAuthReady: boolean;
|
|
37
38
|
isAnonymous: boolean;
|
|
38
39
|
isAuthenticated: boolean;
|
|
40
|
+
hasFirebaseUser: boolean;
|
|
39
41
|
isRegisteredUser: boolean;
|
|
40
42
|
error: string | null;
|
|
41
43
|
signUp: (email: string, password: string, displayName?: string) => Promise<void>;
|
|
@@ -50,6 +52,7 @@ export function useAuth(): UseAuthResult {
|
|
|
50
52
|
const loading = useAuthStore(selectLoading);
|
|
51
53
|
const error = useAuthStore(selectError);
|
|
52
54
|
const isAuthenticated = useAuthStore(selectIsAuthenticated);
|
|
55
|
+
const hasFirebaseUser = useAuthStore(selectHasFirebaseUser);
|
|
53
56
|
const userId = useAuthStore(selectUserId);
|
|
54
57
|
const userType = useAuthStore(selectUserType);
|
|
55
58
|
const isAnonymous = useAuthStore(selectIsAnonymous);
|
|
@@ -130,7 +133,7 @@ export function useAuth(): UseAuthResult {
|
|
|
130
133
|
}, [setIsAnonymous, setLoading, setError, anonymousModeMutation]);
|
|
131
134
|
|
|
132
135
|
return {
|
|
133
|
-
user, userId, userType, loading, isAuthReady, isAnonymous, isAuthenticated, isRegisteredUser, error,
|
|
136
|
+
user, userId, userType, loading, isAuthReady, isAnonymous, isAuthenticated, hasFirebaseUser, isRegisteredUser, error,
|
|
134
137
|
signUp, signIn, signOut, continueAnonymously, setError,
|
|
135
138
|
};
|
|
136
139
|
}
|
|
@@ -87,6 +87,10 @@ export const selectIsAuthenticated = (state: AuthStore): boolean => {
|
|
|
87
87
|
return hasFirebaseUser && isNotAnonymous;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
export const selectHasFirebaseUser = (state: AuthStore): boolean => {
|
|
91
|
+
return !!state.firebaseUser;
|
|
92
|
+
};
|
|
93
|
+
|
|
90
94
|
/**
|
|
91
95
|
* Check if user is anonymous
|
|
92
96
|
* Uses firebaseUser as single source of truth
|