@umituz/react-native-auth 1.5.2 → 1.6.0
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/domain/value-objects/AuthConfig.ts +1 -15
- package/src/index.ts +9 -0
- package/src/infrastructure/services/AuthService.ts +17 -41
- package/src/presentation/components/AuthLegalLinks.tsx +1 -1
- package/src/presentation/components/AuthLink.tsx +1 -1
- package/src/presentation/components/LoginForm.tsx +1 -1
- package/src/presentation/components/RegisterForm.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Authentication service for React Native apps - Secure, type-safe, and production-ready. Provider-agnostic design supports Firebase Auth and can be adapted for Supabase or other providers.",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -14,23 +14,9 @@ export interface AuthConfig {
|
|
|
14
14
|
requireNumbers?: boolean;
|
|
15
15
|
/** Require special characters in password */
|
|
16
16
|
requireSpecialChars?: boolean;
|
|
17
|
-
/** Callback for user profile creation after signup */
|
|
18
|
-
onUserCreated?: (user: any) => Promise<void> | void;
|
|
19
|
-
/** Callback for user profile update */
|
|
20
|
-
onUserUpdated?: (user: any) => Promise<void> | void;
|
|
21
|
-
/** Callback for sign out cleanup */
|
|
22
|
-
onSignOut?: () => Promise<void> | void;
|
|
23
|
-
/** Callback for analytics logging on sign in */
|
|
24
|
-
onSignIn?: (method: string) => Promise<void> | void;
|
|
25
|
-
/** Callback for analytics logging on guest mode */
|
|
26
|
-
onGuestModeEnabled?: () => Promise<void> | void;
|
|
27
|
-
/** Callback for analytics initialization when user authenticates */
|
|
28
|
-
onAnalyticsInit?: (userId: string) => Promise<void> | void;
|
|
29
|
-
/** Callback for analytics initialization when guest mode enabled */
|
|
30
|
-
onAnalyticsInitGuest?: () => Promise<void> | void;
|
|
31
17
|
}
|
|
32
18
|
|
|
33
|
-
export const DEFAULT_AUTH_CONFIG: Required<
|
|
19
|
+
export const DEFAULT_AUTH_CONFIG: Required<AuthConfig> = {
|
|
34
20
|
minPasswordLength: 6,
|
|
35
21
|
requireUppercase: false,
|
|
36
22
|
requireLowercase: false,
|
package/src/index.ts
CHANGED
|
@@ -71,6 +71,15 @@ export type {
|
|
|
71
71
|
AuthStackParamList,
|
|
72
72
|
AuthNavigatorProps,
|
|
73
73
|
} from './presentation/navigation/AuthNavigator';
|
|
74
|
+
|
|
75
|
+
// PRESENTATION LAYER - Components
|
|
76
|
+
// =============================================================================
|
|
77
|
+
|
|
78
|
+
export { AuthContainer } from './presentation/components/AuthContainer';
|
|
79
|
+
export { AuthHeader } from './presentation/components/AuthHeader';
|
|
80
|
+
export { AuthFormCard } from './presentation/components/AuthFormCard';
|
|
81
|
+
export { LoginForm } from './presentation/components/LoginForm';
|
|
82
|
+
export { RegisterForm } from './presentation/components/RegisterForm';
|
|
74
83
|
export { AuthLegalLinks } from './presentation/components/AuthLegalLinks';
|
|
75
84
|
export type { AuthLegalLinksProps } from './presentation/components/AuthLegalLinks';
|
|
76
85
|
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from "../../domain/errors/AuthError";
|
|
28
28
|
import type { AuthConfig } from "../../domain/value-objects/AuthConfig";
|
|
29
29
|
import { DEFAULT_AUTH_CONFIG } from "../../domain/value-objects/AuthConfig";
|
|
30
|
+
import { DeviceEventEmitter } from "react-native";
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Validate email format
|
|
@@ -203,18 +204,8 @@ export class AuthService implements IAuthService {
|
|
|
203
204
|
}
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
// Call user created callback if provided
|
|
207
|
-
// User state is managed by Firebase Auth's onAuthStateChanged
|
|
208
|
-
if (this.config.onUserCreated) {
|
|
209
|
-
try {
|
|
210
|
-
await this.config.onUserCreated(userCredential.user);
|
|
211
|
-
} catch (callbackError) {
|
|
212
|
-
// Don't fail signup if callback fails
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
207
|
// Emit event for AppNavigator to handle navigation
|
|
217
|
-
|
|
208
|
+
DeviceEventEmitter.emit("user-authenticated", { userId: userCredential.user.uid });
|
|
218
209
|
|
|
219
210
|
return userCredential.user;
|
|
220
211
|
} catch (error: any) {
|
|
@@ -250,18 +241,8 @@ export class AuthService implements IAuthService {
|
|
|
250
241
|
|
|
251
242
|
this.isGuestMode = false;
|
|
252
243
|
|
|
253
|
-
// Call analytics callback if provided
|
|
254
|
-
// User state is managed by Firebase Auth's onAuthStateChanged
|
|
255
|
-
if (this.config.onSignIn) {
|
|
256
|
-
try {
|
|
257
|
-
await this.config.onSignIn("email");
|
|
258
|
-
} catch (callbackError) {
|
|
259
|
-
// Don't fail signin if analytics callback fails
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
244
|
// Emit event for AppNavigator to handle navigation
|
|
264
|
-
|
|
245
|
+
DeviceEventEmitter.emit("user-authenticated", { userId: userCredential.user.uid });
|
|
265
246
|
|
|
266
247
|
return userCredential.user;
|
|
267
248
|
} catch (error: any) {
|
|
@@ -284,15 +265,6 @@ export class AuthService implements IAuthService {
|
|
|
284
265
|
await firebaseSignOut(auth);
|
|
285
266
|
this.isGuestMode = false;
|
|
286
267
|
|
|
287
|
-
// Call sign out callback if provided
|
|
288
|
-
// User state is managed by Firebase Auth's onAuthStateChanged
|
|
289
|
-
if (this.config.onSignOut) {
|
|
290
|
-
try {
|
|
291
|
-
await this.config.onSignOut();
|
|
292
|
-
} catch (callbackError) {
|
|
293
|
-
// Don't fail signout if callback fails
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
268
|
} catch (error: any) {
|
|
297
269
|
throw mapFirebaseAuthError(error);
|
|
298
270
|
}
|
|
@@ -315,15 +287,6 @@ export class AuthService implements IAuthService {
|
|
|
315
287
|
|
|
316
288
|
this.isGuestMode = true;
|
|
317
289
|
|
|
318
|
-
// Call analytics callback if provided
|
|
319
|
-
// Guest mode state is managed by useAuth hook
|
|
320
|
-
if (this.config.onGuestModeEnabled) {
|
|
321
|
-
try {
|
|
322
|
-
await this.config.onGuestModeEnabled();
|
|
323
|
-
} catch (callbackError) {
|
|
324
|
-
// Don't fail guest mode if analytics callback fails
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
290
|
}
|
|
328
291
|
|
|
329
292
|
/**
|
|
@@ -374,13 +337,26 @@ let authServiceInstance: AuthService | null = null;
|
|
|
374
337
|
/**
|
|
375
338
|
* Initialize auth service with Firebase Auth instance
|
|
376
339
|
* Must be called before using any auth methods
|
|
340
|
+
*
|
|
341
|
+
* Uses DEFAULT_AUTH_CONFIG if no config is provided:
|
|
342
|
+
* - minPasswordLength: 6
|
|
343
|
+
* - requireUppercase: false
|
|
344
|
+
* - requireLowercase: false
|
|
345
|
+
* - requireNumbers: false
|
|
346
|
+
* - requireSpecialChars: false
|
|
347
|
+
*
|
|
348
|
+
* @param auth - Firebase Auth instance
|
|
349
|
+
* @param config - Optional auth configuration (defaults to permissive settings)
|
|
377
350
|
*/
|
|
378
351
|
export function initializeAuthService(
|
|
379
352
|
auth: Auth,
|
|
380
353
|
config?: AuthConfig
|
|
381
354
|
): AuthService {
|
|
355
|
+
// Use default config if not provided (permissive settings for better UX)
|
|
356
|
+
const finalConfig = config || DEFAULT_AUTH_CONFIG;
|
|
357
|
+
|
|
382
358
|
if (!authServiceInstance) {
|
|
383
|
-
authServiceInstance = new AuthService(
|
|
359
|
+
authServiceInstance = new AuthService(finalConfig);
|
|
384
360
|
}
|
|
385
361
|
authServiceInstance.initialize(auth);
|
|
386
362
|
return authServiceInstance;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React from "react";
|
|
7
7
|
import { View, StyleSheet, Linking } from "react-native";
|
|
8
|
-
import { AtomicButton, AtomicText } from "@umituz/react-native-design-system";
|
|
8
|
+
import { AtomicButton, AtomicText } from "@umituz/react-native-design-system-atoms";
|
|
9
9
|
import { useAppDesignTokens } from "@umituz/react-native-design-system-theme";
|
|
10
10
|
import { useLocalization } from "@umituz/react-native-localization";
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React from "react";
|
|
7
7
|
import { View, Text, StyleSheet } from "react-native";
|
|
8
|
-
import { AtomicButton } from "@umituz/react-native-design-system";
|
|
8
|
+
import { AtomicButton } from "@umituz/react-native-design-system-atoms";
|
|
9
9
|
import { useAppDesignTokens } from "@umituz/react-native-design-system-theme";
|
|
10
10
|
|
|
11
11
|
interface AuthLinkProps {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useState } from "react";
|
|
7
7
|
import { View, StyleSheet } from "react-native";
|
|
8
|
-
import { AtomicInput, AtomicButton } from "@umituz/react-native-design-system";
|
|
8
|
+
import { AtomicInput, AtomicButton } from "@umituz/react-native-design-system-atoms";
|
|
9
9
|
import { useLocalization } from "@umituz/react-native-localization";
|
|
10
10
|
import { useAuth } from "../hooks/useAuth";
|
|
11
11
|
import { AuthErrorDisplay } from "./AuthErrorDisplay";
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useState } from "react";
|
|
7
7
|
import { View, StyleSheet } from "react-native";
|
|
8
|
-
import { AtomicInput, AtomicButton } from "@umituz/react-native-design-system";
|
|
8
|
+
import { AtomicInput, AtomicButton } from "@umituz/react-native-design-system-atoms";
|
|
9
9
|
import { useLocalization } from "@umituz/react-native-localization";
|
|
10
10
|
import {
|
|
11
11
|
validateEmail,
|