@umituz/react-native-auth 3.2.6 → 3.2.7

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": "3.2.6",
3
+ "version": "3.2.7",
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",
@@ -9,6 +9,13 @@
9
9
  import { useCallback } from "react";
10
10
  import {
11
11
  useAuthStore,
12
+ selectUser,
13
+ selectLoading,
14
+ selectIsGuest,
15
+ selectError,
16
+ selectSetLoading,
17
+ selectSetError,
18
+ selectSetIsGuest,
12
19
  selectIsAuthenticated,
13
20
  selectUserId,
14
21
  selectUserType,
@@ -62,21 +69,21 @@ export interface UseAuthResult {
62
69
  * Must call initializeAuthListener() once in app root.
63
70
  */
64
71
  export function useAuth(): UseAuthResult {
65
- // State from store
66
- const user = useAuthStore((state) => state.user);
67
- const loading = useAuthStore((state) => state.loading);
68
- const isGuest = useAuthStore((state) => state.isGuest);
69
- const error = useAuthStore((state) => state.error);
72
+ // State from store - using typed selectors
73
+ const user = useAuthStore(selectUser);
74
+ const loading = useAuthStore(selectLoading);
75
+ const isGuest = useAuthStore(selectIsGuest);
76
+ const error = useAuthStore(selectError);
70
77
  const isAuthenticated = useAuthStore(selectIsAuthenticated);
71
78
  const userId = useAuthStore(selectUserId);
72
79
  const userType = useAuthStore(selectUserType);
73
80
  const isAnonymous = useAuthStore(selectIsAnonymous);
74
81
  const isAuthReady = useAuthStore(selectIsAuthReady);
75
82
 
76
- // Actions from store
77
- const setLoading = useAuthStore((state) => state.setLoading);
78
- const setError = useAuthStore((state) => state.setError);
79
- const setIsGuest = useAuthStore((state) => state.setIsGuest);
83
+ // Actions from store - using typed selectors
84
+ const setLoading = useAuthStore(selectSetLoading);
85
+ const setError = useAuthStore(selectSetError);
86
+ const setIsGuest = useAuthStore(selectSetIsGuest);
80
87
 
81
88
  // Mutations
82
89
  const signInMutation = useSignInMutation();
@@ -17,8 +17,9 @@
17
17
  */
18
18
 
19
19
  import { useCallback } from "react";
20
- import { useAuthStore, selectIsAuthenticated } from "../stores/authStore";
20
+ import { useAuthStore, selectIsAuthenticated, selectLoading, selectFirebaseUserId } from "../stores/authStore";
21
21
  import { useAuthModalStore } from "../stores/authModalStore";
22
+ import { selectShowAuthModal } from "../stores/auth.selectors";
22
23
 
23
24
  export interface UseAuthRequiredResult {
24
25
  /** Whether user is authenticated (not guest, not anonymous) */
@@ -38,9 +39,9 @@ export interface UseAuthRequiredResult {
38
39
  */
39
40
  export function useAuthRequired(): UseAuthRequiredResult {
40
41
  const isAllowed = useAuthStore(selectIsAuthenticated);
41
- const isLoading = useAuthStore((state) => state.loading);
42
- const userId = useAuthStore((state) => state.firebaseUser?.uid ?? null);
43
- const showAuthModal = useAuthModalStore((state) => state.showAuthModal);
42
+ const isLoading = useAuthStore(selectLoading);
43
+ const userId = useAuthStore(selectFirebaseUserId);
44
+ const showAuthModal = useAuthModalStore(selectShowAuthModal);
44
45
 
45
46
  const requireAuth = useCallback(() => {
46
47
  showAuthModal(undefined, "login");
@@ -10,7 +10,7 @@
10
10
  * ```
11
11
  */
12
12
 
13
- import { useAuthStore, selectIsAuthenticated } from "../stores/authStore";
13
+ import { useAuthStore, selectIsAuthenticated, selectFirebaseUserId } from "../stores/authStore";
14
14
 
15
15
  /**
16
16
  * Get userId or throw if not authenticated
@@ -18,7 +18,7 @@ import { useAuthStore, selectIsAuthenticated } from "../stores/authStore";
18
18
  */
19
19
  export function useRequireAuth(): string {
20
20
  const isAuthenticated = useAuthStore(selectIsAuthenticated);
21
- const userId = useAuthStore((state) => state.firebaseUser?.uid ?? null);
21
+ const userId = useAuthStore(selectFirebaseUserId);
22
22
 
23
23
  if (!isAuthenticated || !userId) {
24
24
  throw new Error("User not authenticated. This component requires auth.");
@@ -31,5 +31,5 @@ export function useRequireAuth(): string {
31
31
  * Get userId safely (returns null if not authenticated)
32
32
  */
33
33
  export function useUserId(): string | null {
34
- return useAuthStore((state) => state.firebaseUser?.uid ?? null);
34
+ return useAuthStore(selectFirebaseUserId);
35
35
  }
@@ -3,33 +3,97 @@
3
3
  * Pure functions for deriving state from auth store
4
4
  */
5
5
 
6
- import type { AuthState, UserType } from "../../types/auth-store.types";
6
+ import type { AuthState, AuthActions, UserType } from "../../types/auth-store.types";
7
+ import type { AuthUser } from "../../domain/entities/AuthUser";
8
+
9
+ // Combined store type for selectors
10
+ type AuthStore = AuthState & AuthActions;
11
+
12
+ // =============================================================================
13
+ // STATE SELECTORS
14
+ // =============================================================================
15
+
16
+ /**
17
+ * Select current user
18
+ */
19
+ export const selectUser = (state: AuthStore): AuthUser | null => state.user;
20
+
21
+ /**
22
+ * Select loading state
23
+ */
24
+ export const selectLoading = (state: AuthStore): boolean => state.loading;
25
+
26
+ /**
27
+ * Select guest mode
28
+ */
29
+ export const selectIsGuest = (state: AuthStore): boolean => state.isGuest;
30
+
31
+ /**
32
+ * Select error
33
+ */
34
+ export const selectError = (state: AuthStore): string | null => state.error;
35
+
36
+ /**
37
+ * Select firebase user uid
38
+ */
39
+ export const selectFirebaseUserId = (state: AuthStore): string | null =>
40
+ state.firebaseUser?.uid ?? null;
41
+
42
+ // =============================================================================
43
+ // ACTION SELECTORS
44
+ // =============================================================================
45
+
46
+ /**
47
+ * Select setLoading action
48
+ */
49
+ export const selectSetLoading = (state: AuthStore) => state.setLoading;
50
+
51
+ /**
52
+ * Select setError action
53
+ */
54
+ export const selectSetError = (state: AuthStore) => state.setError;
55
+
56
+ /**
57
+ * Select setIsGuest action
58
+ */
59
+ export const selectSetIsGuest = (state: AuthStore) => state.setIsGuest;
60
+
61
+ /**
62
+ * Select showAuthModal action (from authModalStore)
63
+ */
64
+ export type AuthModalMode = "login" | "register";
65
+ export const selectShowAuthModal = (state: { showAuthModal: (callback?: () => void | Promise<void>, mode?: AuthModalMode) => void }) =>
66
+ state.showAuthModal;
67
+
68
+ // =============================================================================
69
+ // DERIVED SELECTORS
70
+ // =============================================================================
7
71
 
8
72
  /**
9
73
  * Get current user ID
10
74
  */
11
- export const selectUserId = (state: AuthState): string | null => {
75
+ export const selectUserId = (state: AuthStore): string | null => {
12
76
  return state.firebaseUser?.uid ?? state.user?.uid ?? null;
13
77
  };
14
78
 
15
79
  /**
16
80
  * Check if user is authenticated (not guest, not anonymous)
17
81
  */
18
- export const selectIsAuthenticated = (state: AuthState): boolean => {
82
+ export const selectIsAuthenticated = (state: AuthStore): boolean => {
19
83
  return !!state.user && !state.isGuest && !state.user.isAnonymous;
20
84
  };
21
85
 
22
86
  /**
23
87
  * Check if user is anonymous
24
88
  */
25
- export const selectIsAnonymous = (state: AuthState): boolean => {
89
+ export const selectIsAnonymous = (state: AuthStore): boolean => {
26
90
  return state.firebaseUser?.isAnonymous ?? state.user?.isAnonymous ?? false;
27
91
  };
28
92
 
29
93
  /**
30
94
  * Get current user type
31
95
  */
32
- export const selectUserType = (state: AuthState): UserType => {
96
+ export const selectUserType = (state: AuthStore): UserType => {
33
97
  if (!state.firebaseUser && !state.user) {
34
98
  return "none";
35
99
  }
@@ -43,6 +107,6 @@ export const selectUserType = (state: AuthState): UserType => {
43
107
  /**
44
108
  * Check if auth is ready (initialized and not loading)
45
109
  */
46
- export const selectIsAuthReady = (state: AuthState): boolean => {
110
+ export const selectIsAuthReady = (state: AuthStore): boolean => {
47
111
  return state.initialized && !state.loading;
48
112
  };
@@ -12,6 +12,14 @@ import { mapToAuthUser } from "../../infrastructure/utils/UserMapper";
12
12
  import type { AuthState, AuthActions, UserType } from "../../types/auth-store.types";
13
13
  import { initialAuthState } from "../../types/auth-store.types";
14
14
  import {
15
+ selectUser,
16
+ selectLoading,
17
+ selectIsGuest,
18
+ selectError,
19
+ selectFirebaseUserId,
20
+ selectSetLoading,
21
+ selectSetError,
22
+ selectSetIsGuest,
15
23
  selectUserId,
16
24
  selectIsAuthenticated,
17
25
  selectIsAnonymous,
@@ -24,6 +32,14 @@ export type { AuthState, AuthActions, UserType };
24
32
 
25
33
  // Re-export selectors
26
34
  export {
35
+ selectUser,
36
+ selectLoading,
37
+ selectIsGuest,
38
+ selectError,
39
+ selectFirebaseUserId,
40
+ selectSetLoading,
41
+ selectSetError,
42
+ selectSetIsGuest,
27
43
  selectUserId,
28
44
  selectIsAuthenticated,
29
45
  selectIsAnonymous,