@umituz/react-native-auth 3.2.7 → 3.2.8
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.
|
|
3
|
+
"version": "3.2.8",
|
|
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",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import { create } from "zustand";
|
|
20
|
+
import { create, type StoreApi, type UseBoundStore } from "zustand";
|
|
21
21
|
|
|
22
22
|
export type AuthModalMode = "login" | "register";
|
|
23
23
|
|
|
@@ -40,12 +40,21 @@ interface AuthModalActions {
|
|
|
40
40
|
|
|
41
41
|
type AuthModalStore = AuthModalState & AuthModalActions;
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
type SetModalState = (partial: Partial<AuthModalState> | ((state: AuthModalState) => Partial<AuthModalState>)) => void;
|
|
44
|
+
type GetModalState = () => AuthModalStore;
|
|
45
|
+
|
|
46
|
+
export const useAuthModalStore: UseBoundStore<StoreApi<AuthModalStore>> = create<AuthModalStore>((
|
|
47
|
+
set: SetModalState,
|
|
48
|
+
get: GetModalState,
|
|
49
|
+
) => ({
|
|
44
50
|
isVisible: false,
|
|
45
51
|
mode: "login",
|
|
46
52
|
pendingCallback: null,
|
|
47
53
|
|
|
48
|
-
showAuthModal: (
|
|
54
|
+
showAuthModal: (
|
|
55
|
+
callback?: () => void | Promise<void>,
|
|
56
|
+
mode: AuthModalMode = "login",
|
|
57
|
+
) => {
|
|
49
58
|
set({
|
|
50
59
|
isVisible: true,
|
|
51
60
|
mode,
|
|
@@ -57,7 +66,7 @@ export const useAuthModalStore = create<AuthModalStore>((set, get) => ({
|
|
|
57
66
|
set({ isVisible: false });
|
|
58
67
|
},
|
|
59
68
|
|
|
60
|
-
setMode: (mode) => {
|
|
69
|
+
setMode: (mode: AuthModalMode) => {
|
|
61
70
|
set({ mode });
|
|
62
71
|
},
|
|
63
72
|
|
|
@@ -69,7 +78,6 @@ export const useAuthModalStore = create<AuthModalStore>((set, get) => ({
|
|
|
69
78
|
}
|
|
70
79
|
},
|
|
71
80
|
|
|
72
|
-
|
|
73
81
|
clearPendingCallback: () => {
|
|
74
82
|
set({ pendingCallback: null });
|
|
75
83
|
},
|
|
@@ -7,10 +7,20 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { createStore } from "@umituz/react-native-storage";
|
|
10
|
+
import type { User } from "firebase/auth";
|
|
10
11
|
import type { AuthUser } from "../../domain/entities/AuthUser";
|
|
11
12
|
import { mapToAuthUser } from "../../infrastructure/utils/UserMapper";
|
|
12
13
|
import type { AuthState, AuthActions, UserType } from "../../types/auth-store.types";
|
|
13
14
|
import { initialAuthState } from "../../types/auth-store.types";
|
|
15
|
+
|
|
16
|
+
// Type for the combined store
|
|
17
|
+
type AuthStore = AuthState & AuthActions;
|
|
18
|
+
|
|
19
|
+
// Type for set function
|
|
20
|
+
type SetState = (partial: Partial<AuthState>) => void;
|
|
21
|
+
|
|
22
|
+
// Type for get function
|
|
23
|
+
type GetState = () => AuthStore;
|
|
14
24
|
import {
|
|
15
25
|
selectUser,
|
|
16
26
|
selectLoading,
|
|
@@ -63,12 +73,12 @@ export const useAuthStore = createStore<AuthState, AuthActions>({
|
|
|
63
73
|
initialState: initialAuthState,
|
|
64
74
|
persist: true,
|
|
65
75
|
version: 1,
|
|
66
|
-
partialize: (state) => ({
|
|
76
|
+
partialize: (state: AuthState) => ({
|
|
67
77
|
isGuest: state.isGuest,
|
|
68
78
|
initialized: state.initialized,
|
|
69
79
|
}),
|
|
70
|
-
actions: (set, get) => ({
|
|
71
|
-
setFirebaseUser: (firebaseUser) => {
|
|
80
|
+
actions: (set: SetState, get: GetState) => ({
|
|
81
|
+
setFirebaseUser: (firebaseUser: User | null) => {
|
|
72
82
|
const { isGuest } = get();
|
|
73
83
|
|
|
74
84
|
let user: AuthUser | null = null;
|
|
@@ -88,9 +98,9 @@ export const useAuthStore = createStore<AuthState, AuthActions>({
|
|
|
88
98
|
});
|
|
89
99
|
},
|
|
90
100
|
|
|
91
|
-
setLoading: (loading) => set({ loading }),
|
|
101
|
+
setLoading: (loading: boolean) => set({ loading }),
|
|
92
102
|
|
|
93
|
-
setIsGuest: (isGuest) => {
|
|
103
|
+
setIsGuest: (isGuest: boolean) => {
|
|
94
104
|
const { firebaseUser } = get();
|
|
95
105
|
|
|
96
106
|
let user: AuthUser | null = null;
|
|
@@ -105,9 +115,9 @@ export const useAuthStore = createStore<AuthState, AuthActions>({
|
|
|
105
115
|
set({ isGuest, user });
|
|
106
116
|
},
|
|
107
117
|
|
|
108
|
-
setError: (error) => set({ error }),
|
|
118
|
+
setError: (error: string | null) => set({ error }),
|
|
109
119
|
|
|
110
|
-
setInitialized: (initialized) => set({ initialized }),
|
|
120
|
+
setInitialized: (initialized: boolean) => set({ initialized }),
|
|
111
121
|
|
|
112
122
|
reset: () => set(initialAuthState),
|
|
113
123
|
}),
|