@umituz/react-native-auth 3.6.21 → 3.6.22

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.6.21",
3
+ "version": "3.6.22",
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",
package/src/index.ts CHANGED
@@ -213,3 +213,9 @@ export type { AuthListenerOptions } from './types/auth-store.types';
213
213
 
214
214
  // UTILITIES
215
215
  export { getAuthErrorLocalizationKey } from './presentation/utils/getAuthErrorMessage';
216
+
217
+ // Init Module Factory
218
+ export {
219
+ createAuthInitModule,
220
+ type AuthInitModuleConfig,
221
+ } from './init';
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Auth Init Module Factory
3
+ * Creates a ready-to-use InitModule for app initialization
4
+ */
5
+
6
+ import { initializeAuth } from '../infrastructure/services/initializeAuth';
7
+ import type { InitializeAuthOptions } from '../infrastructure/services/initializeAuth';
8
+ import { SubscriptionManager } from '@umituz/react-native-subscription';
9
+
10
+ declare const __DEV__: boolean;
11
+
12
+ /**
13
+ * InitModule interface (from @umituz/react-native-design-system)
14
+ */
15
+ export interface InitModule {
16
+ name: string;
17
+ init: () => Promise<boolean>;
18
+ critical?: boolean;
19
+ dependsOn?: string[];
20
+ }
21
+
22
+ export interface AuthInitModuleConfig {
23
+ /**
24
+ * Firestore collection name for user documents
25
+ * @default "users"
26
+ */
27
+ userCollection?: string;
28
+
29
+ /**
30
+ * Whether to auto sign-in as anonymous user
31
+ * @default true
32
+ */
33
+ autoAnonymousSignIn?: boolean;
34
+
35
+ /**
36
+ * Function to collect device extras for user document
37
+ */
38
+ collectExtras?: () => Promise<Record<string, unknown>>;
39
+
40
+ /**
41
+ * Storage provider for auth persistence
42
+ */
43
+ storageProvider?: InitializeAuthOptions['storageProvider'];
44
+
45
+ /**
46
+ * Whether to restore purchases after user conversion
47
+ * @default true
48
+ */
49
+ restorePurchasesOnConversion?: boolean;
50
+
51
+ /**
52
+ * Custom callback when user converts from anonymous to authenticated
53
+ */
54
+ onUserConverted?: (anonymousId: string, authenticatedId: string) => Promise<void>;
55
+
56
+ /**
57
+ * Whether this module is critical for app startup
58
+ * @default true
59
+ */
60
+ critical?: boolean;
61
+
62
+ /**
63
+ * Module dependencies
64
+ * @default ["firebase"]
65
+ */
66
+ dependsOn?: string[];
67
+ }
68
+
69
+ /**
70
+ * Creates an Auth initialization module for use with createAppInitializer
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * import { createAppInitializer } from "@umituz/react-native-design-system";
75
+ * import { createFirebaseInitModule } from "@umituz/react-native-firebase";
76
+ * import { createAuthInitModule } from "@umituz/react-native-auth";
77
+ * import { storageRepository, collectDeviceExtras } from "@umituz/react-native-design-system";
78
+ *
79
+ * export const initializeApp = createAppInitializer({
80
+ * modules: [
81
+ * createFirebaseInitModule(),
82
+ * createAuthInitModule({
83
+ * userCollection: "users",
84
+ * collectExtras: collectDeviceExtras,
85
+ * storageProvider: storageRepository,
86
+ * }),
87
+ * ],
88
+ * });
89
+ * ```
90
+ */
91
+ export function createAuthInitModule(
92
+ config: AuthInitModuleConfig = {}
93
+ ): InitModule {
94
+ const {
95
+ userCollection = 'users',
96
+ autoAnonymousSignIn = true,
97
+ collectExtras,
98
+ storageProvider,
99
+ restorePurchasesOnConversion = true,
100
+ onUserConverted,
101
+ critical = true,
102
+ dependsOn = ['firebase'],
103
+ } = config;
104
+
105
+ return {
106
+ name: 'auth',
107
+ critical,
108
+ dependsOn,
109
+ init: async () => {
110
+ try {
111
+ await initializeAuth({
112
+ userCollection,
113
+ autoAnonymousSignIn,
114
+ collectExtras,
115
+ storageProvider,
116
+ onUserConverted: async (anonymousId: string, authenticatedId: string) => {
117
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
118
+ console.log('[createAuthInitModule] User converted:', {
119
+ anonymousId: anonymousId.slice(0, 8),
120
+ authenticatedId: authenticatedId.slice(0, 8),
121
+ });
122
+ }
123
+
124
+ // Restore purchases after conversion
125
+ if (restorePurchasesOnConversion) {
126
+ try {
127
+ const result = await SubscriptionManager.restore();
128
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
129
+ console.log('[createAuthInitModule] Restore purchases result:', result);
130
+ }
131
+ } catch (error) {
132
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
133
+ console.error('[createAuthInitModule] Restore failed:', error);
134
+ }
135
+ }
136
+ }
137
+
138
+ // Call custom callback if provided
139
+ if (onUserConverted) {
140
+ await onUserConverted(anonymousId, authenticatedId);
141
+ }
142
+ },
143
+ });
144
+
145
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
146
+ console.log('[createAuthInitModule] Auth initialized');
147
+ }
148
+
149
+ return true;
150
+ } catch (error) {
151
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
152
+ console.error('[createAuthInitModule] Error:', error);
153
+ }
154
+ return false;
155
+ }
156
+ },
157
+ };
158
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Auth Init Module
3
+ * Provides factory for creating app initialization modules
4
+ */
5
+
6
+ export {
7
+ createAuthInitModule,
8
+ type AuthInitModuleConfig,
9
+ type InitModule,
10
+ } from './createAuthInitModule';