@umituz/react-native-auth 3.2.11 → 3.2.13
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 +197 -0
- package/src/__tests__/services/AuthPackage.test.ts +18 -18
- package/src/application/ports/IAuthService.ts +4 -4
- package/src/domain/utils/{guestNameGenerator.ts → anonymousNameGenerator.ts} +11 -11
- package/src/index.ts +3 -4
- package/src/infrastructure/services/{GuestModeService.ts → AnonymousModeService.ts} +19 -19
- package/src/infrastructure/services/AuthEventService.ts +6 -6
- package/src/infrastructure/services/AuthPackage.ts +4 -4
- package/src/infrastructure/services/AuthService.ts +19 -30
- package/src/infrastructure/storage/{GuestModeStorage.ts → AnonymousModeStorage.ts} +9 -9
- package/src/infrastructure/utils/AuthEventEmitter.ts +2 -2
- package/src/presentation/components/AuthBottomSheet.tsx +3 -3
- package/src/presentation/components/SocialLoginButtons.tsx +3 -2
- package/src/presentation/hooks/mutations/useAuthMutations.ts +2 -2
- package/src/presentation/hooks/useAuth.ts +17 -26
- package/src/presentation/hooks/useAuthRequired.ts +1 -1
- package/src/presentation/hooks/useLoginForm.ts +7 -7
- package/src/presentation/hooks/useUserProfile.ts +8 -8
- package/src/presentation/stores/auth.selectors.ts +6 -6
- package/src/presentation/stores/authStore.ts +12 -18
- package/src/presentation/stores/initializeAuthListener.ts +5 -5
- package/src/types/auth-store.types.ts +5 -5
- package/src/__tests__/services/GuestModeService.test.ts +0 -194
|
@@ -21,8 +21,8 @@ export interface AuthState {
|
|
|
21
21
|
firebaseUser: User | null;
|
|
22
22
|
/** Loading state during auth operations */
|
|
23
23
|
loading: boolean;
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/** Anonymous mode (user using anonymous auth) */
|
|
25
|
+
isAnonymous: boolean;
|
|
26
26
|
/** Error message from last auth operation */
|
|
27
27
|
error: string | null;
|
|
28
28
|
/** Whether auth listener has initialized */
|
|
@@ -37,8 +37,8 @@ export interface AuthActions {
|
|
|
37
37
|
setFirebaseUser: (user: User | null) => void;
|
|
38
38
|
/** Set loading state */
|
|
39
39
|
setLoading: (loading: boolean) => void;
|
|
40
|
-
/** Set
|
|
41
|
-
|
|
40
|
+
/** Set anonymous mode */
|
|
41
|
+
setIsAnonymous: (isAnonymous: boolean) => void;
|
|
42
42
|
/** Set error message */
|
|
43
43
|
setError: (error: string | null) => void;
|
|
44
44
|
/** Mark as initialized */
|
|
@@ -54,7 +54,7 @@ export const initialAuthState: AuthState = {
|
|
|
54
54
|
user: null,
|
|
55
55
|
firebaseUser: null,
|
|
56
56
|
loading: true,
|
|
57
|
-
|
|
57
|
+
isAnonymous: false,
|
|
58
58
|
error: null,
|
|
59
59
|
initialized: false,
|
|
60
60
|
};
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GuestModeService Tests
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { GuestModeService } from '../../../src/infrastructure/services/GuestModeService';
|
|
6
|
-
import type { IStorageProvider } from '../../../src/infrastructure/services/GuestModeService';
|
|
7
|
-
|
|
8
|
-
describe('GuestModeService', () => {
|
|
9
|
-
let guestModeService: GuestModeService;
|
|
10
|
-
let mockStorageProvider: jest.Mocked<IStorageProvider>;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
mockStorageProvider = {
|
|
14
|
-
get: jest.fn(),
|
|
15
|
-
set: jest.fn(),
|
|
16
|
-
remove: jest.fn(),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
guestModeService = new GuestModeService('@test_guest_mode');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('constructor', () => {
|
|
23
|
-
it('should use default storage key when none provided', () => {
|
|
24
|
-
const service = new GuestModeService();
|
|
25
|
-
expect(service.getIsGuestMode()).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should use custom storage key when provided', () => {
|
|
29
|
-
const service = new GuestModeService('@custom_key');
|
|
30
|
-
expect(service.getIsGuestMode()).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('load', () => {
|
|
35
|
-
it('should load false when storage returns null', async () => {
|
|
36
|
-
mockStorageProvider.get.mockResolvedValue(null);
|
|
37
|
-
|
|
38
|
-
const result = await guestModeService.load(mockStorageProvider);
|
|
39
|
-
|
|
40
|
-
expect(result).toBe(false);
|
|
41
|
-
expect(mockStorageProvider.get).toHaveBeenCalledWith('@test_guest_mode');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should load false when storage returns "false"', async () => {
|
|
45
|
-
mockStorageProvider.get.mockResolvedValue('false');
|
|
46
|
-
|
|
47
|
-
const result = await guestModeService.load(mockStorageProvider);
|
|
48
|
-
|
|
49
|
-
expect(result).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should load true when storage returns "true"', async () => {
|
|
53
|
-
mockStorageProvider.get.mockResolvedValue('true');
|
|
54
|
-
|
|
55
|
-
const result = await guestModeService.load(mockStorageProvider);
|
|
56
|
-
|
|
57
|
-
expect(result).toBe(true);
|
|
58
|
-
expect(guestModeService.getIsGuestMode()).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should handle storage errors gracefully', async () => {
|
|
62
|
-
mockStorageProvider.get.mockRejectedValue(new Error('Storage error'));
|
|
63
|
-
|
|
64
|
-
const result = await guestModeService.load(mockStorageProvider);
|
|
65
|
-
|
|
66
|
-
expect(result).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('save', () => {
|
|
71
|
-
it('should save true to storage when guest mode is enabled', async () => {
|
|
72
|
-
guestModeService.setGuestMode(true);
|
|
73
|
-
|
|
74
|
-
await guestModeService.save(mockStorageProvider);
|
|
75
|
-
|
|
76
|
-
expect(mockStorageProvider.set).toHaveBeenCalledWith('@test_guest_mode', 'true');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should remove from storage when guest mode is disabled', async () => {
|
|
80
|
-
guestModeService.setGuestMode(false);
|
|
81
|
-
|
|
82
|
-
await guestModeService.save(mockStorageProvider);
|
|
83
|
-
|
|
84
|
-
expect(mockStorageProvider.remove).toHaveBeenCalledWith('@test_guest_mode');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should handle storage errors gracefully', async () => {
|
|
88
|
-
guestModeService.setGuestMode(true);
|
|
89
|
-
mockStorageProvider.set.mockRejectedValue(new Error('Storage error'));
|
|
90
|
-
|
|
91
|
-
await expect(guestModeService.save(mockStorageProvider)).resolves.not.toThrow();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('clear', () => {
|
|
96
|
-
it('should clear guest mode and remove from storage', async () => {
|
|
97
|
-
guestModeService.setGuestMode(true);
|
|
98
|
-
|
|
99
|
-
await guestModeService.clear(mockStorageProvider);
|
|
100
|
-
|
|
101
|
-
expect(guestModeService.getIsGuestMode()).toBe(false);
|
|
102
|
-
expect(mockStorageProvider.remove).toHaveBeenCalledWith('@test_guest_mode');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should handle storage errors gracefully', async () => {
|
|
106
|
-
mockStorageProvider.remove.mockRejectedValue(new Error('Storage error'));
|
|
107
|
-
|
|
108
|
-
await expect(guestModeService.clear(mockStorageProvider)).resolves.not.toThrow();
|
|
109
|
-
expect(guestModeService.getIsGuestMode()).toBe(false);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('enable', () => {
|
|
114
|
-
let mockAuthProvider: any;
|
|
115
|
-
|
|
116
|
-
beforeEach(() => {
|
|
117
|
-
mockAuthProvider = {
|
|
118
|
-
getCurrentUser: jest.fn(),
|
|
119
|
-
signOut: jest.fn(),
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should enable guest mode without provider', async () => {
|
|
124
|
-
await guestModeService.enable(mockStorageProvider);
|
|
125
|
-
|
|
126
|
-
expect(guestModeService.getIsGuestMode()).toBe(true);
|
|
127
|
-
expect(mockStorageProvider.set).toHaveBeenCalledWith('@test_guest_mode', 'true');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should sign out provider if user is logged in', async () => {
|
|
131
|
-
mockAuthProvider.getCurrentUser.mockReturnValue({ uid: 'test-user' });
|
|
132
|
-
mockAuthProvider.signOut.mockResolvedValue(undefined);
|
|
133
|
-
|
|
134
|
-
await guestModeService.enable(mockStorageProvider, mockAuthProvider);
|
|
135
|
-
|
|
136
|
-
expect(mockAuthProvider.signOut).toHaveBeenCalled();
|
|
137
|
-
expect(guestModeService.getIsGuestMode()).toBe(true);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should ignore sign out errors', async () => {
|
|
141
|
-
mockAuthProvider.getCurrentUser.mockReturnValue({ uid: 'test-user' });
|
|
142
|
-
mockAuthProvider.signOut.mockRejectedValue(new Error('Sign out error'));
|
|
143
|
-
|
|
144
|
-
await expect(guestModeService.enable(mockStorageProvider, mockAuthProvider)).resolves.not.toThrow();
|
|
145
|
-
expect(guestModeService.getIsGuestMode()).toBe(true);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('wrapAuthStateCallback', () => {
|
|
150
|
-
it('should call callback with user when not in guest mode', () => {
|
|
151
|
-
const callback = jest.fn();
|
|
152
|
-
const wrappedCallback = guestModeService.wrapAuthStateCallback(callback);
|
|
153
|
-
const mockUser = { uid: 'test-user' };
|
|
154
|
-
|
|
155
|
-
wrappedCallback(mockUser);
|
|
156
|
-
|
|
157
|
-
expect(callback).toHaveBeenCalledWith(mockUser);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should call callback with null when in guest mode', () => {
|
|
161
|
-
guestModeService.setGuestMode(true);
|
|
162
|
-
const callback = jest.fn();
|
|
163
|
-
const wrappedCallback = guestModeService.wrapAuthStateCallback(callback);
|
|
164
|
-
const mockUser = { uid: 'test-user' };
|
|
165
|
-
|
|
166
|
-
wrappedCallback(mockUser);
|
|
167
|
-
|
|
168
|
-
expect(callback).toHaveBeenCalledWith(null);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should call callback with null when user is null', () => {
|
|
172
|
-
const callback = jest.fn();
|
|
173
|
-
const wrappedCallback = guestModeService.wrapAuthStateCallback(callback);
|
|
174
|
-
|
|
175
|
-
wrappedCallback(null);
|
|
176
|
-
|
|
177
|
-
expect(callback).toHaveBeenCalledWith(null);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('getIsGuestMode and setGuestMode', () => {
|
|
182
|
-
it('should return initial guest mode state', () => {
|
|
183
|
-
expect(guestModeService.getIsGuestMode()).toBe(false);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should set and get guest mode state', () => {
|
|
187
|
-
guestModeService.setGuestMode(true);
|
|
188
|
-
expect(guestModeService.getIsGuestMode()).toBe(true);
|
|
189
|
-
|
|
190
|
-
guestModeService.setGuestMode(false);
|
|
191
|
-
expect(guestModeService.getIsGuestMode()).toBe(false);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|