@umituz/react-native-auth 2.5.9 → 2.5.10
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": "2.5.
|
|
3
|
+
"version": "2.5.10",
|
|
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",
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anonymous User Name Generator
|
|
3
|
+
* Generates friendly, random names for anonymous users
|
|
4
|
+
* Fully generic - no app-specific content
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const DEFAULT_NAMES = [
|
|
8
|
+
'Alex',
|
|
9
|
+
'Sam',
|
|
10
|
+
'Jordan',
|
|
11
|
+
'Taylor',
|
|
12
|
+
'Morgan',
|
|
13
|
+
'Casey',
|
|
14
|
+
'Riley',
|
|
15
|
+
'Avery',
|
|
16
|
+
'Quinn',
|
|
17
|
+
'Blake',
|
|
18
|
+
'Charlie',
|
|
19
|
+
'Dakota',
|
|
20
|
+
'Eden',
|
|
21
|
+
'Finley',
|
|
22
|
+
'Harper',
|
|
23
|
+
'Sage',
|
|
24
|
+
'River',
|
|
25
|
+
'Skylar',
|
|
26
|
+
'Rowan',
|
|
27
|
+
'Phoenix',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export interface GuestNameConfig {
|
|
31
|
+
names?: string[];
|
|
32
|
+
prefixes?: string[];
|
|
33
|
+
usePrefixes?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Generate a random guest name
|
|
38
|
+
* Uses userId to ensure consistency per user
|
|
39
|
+
*/
|
|
40
|
+
export function generateGuestName(
|
|
41
|
+
userId?: string,
|
|
42
|
+
config?: GuestNameConfig,
|
|
43
|
+
): string {
|
|
44
|
+
const names = config?.names || DEFAULT_NAMES;
|
|
45
|
+
const prefixes = config?.prefixes || [];
|
|
46
|
+
const usePrefixes = config?.usePrefixes ?? false;
|
|
47
|
+
|
|
48
|
+
if (!userId) {
|
|
49
|
+
const randomIndex = Math.floor(Math.random() * names.length);
|
|
50
|
+
return names[randomIndex];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Use userId hash for consistent name per user
|
|
54
|
+
const hash = userId.split('').reduce((acc, char) => {
|
|
55
|
+
return ((acc << 5) - acc + char.charCodeAt(0)) | 0;
|
|
56
|
+
}, 0);
|
|
57
|
+
|
|
58
|
+
const nameIndex = Math.abs(hash) % names.length;
|
|
59
|
+
const name = names[nameIndex];
|
|
60
|
+
|
|
61
|
+
if (usePrefixes && prefixes.length > 0) {
|
|
62
|
+
const prefixIndex = Math.abs(hash >> 8) % prefixes.length;
|
|
63
|
+
return `${prefixes[prefixIndex]} ${name}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return name;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get guest display name with fallback
|
|
71
|
+
*/
|
|
72
|
+
export function getGuestDisplayName(
|
|
73
|
+
userId?: string,
|
|
74
|
+
fallback = 'Guest',
|
|
75
|
+
config?: GuestNameConfig,
|
|
76
|
+
): string {
|
|
77
|
+
if (!userId) return fallback;
|
|
78
|
+
return generateGuestName(userId, config);
|
|
79
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -113,6 +113,10 @@ export type { UseProfileEditReturn, ProfileEditFormState } from './presentation/
|
|
|
113
113
|
|
|
114
114
|
export type { UserProfile, UpdateProfileParams } from './domain/entities/UserProfile';
|
|
115
115
|
|
|
116
|
+
// Domain Utils - Guest Names
|
|
117
|
+
export { generateGuestName, getGuestDisplayName } from './domain/utils/guestNameGenerator';
|
|
118
|
+
export type { GuestNameConfig } from './domain/utils/guestNameGenerator';
|
|
119
|
+
|
|
116
120
|
// =============================================================================
|
|
117
121
|
// PRESENTATION LAYER - Screens & Navigation
|
|
118
122
|
// =============================================================================
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { useMemo } from "react";
|
|
8
8
|
import { useAuth } from "./useAuth";
|
|
9
|
+
import { generateGuestName, type GuestNameConfig } from "../../domain/utils/guestNameGenerator";
|
|
9
10
|
|
|
10
11
|
export interface UserProfileData {
|
|
11
12
|
displayName: string;
|
|
@@ -16,9 +17,9 @@ export interface UserProfileData {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export interface UseUserProfileParams {
|
|
19
|
-
anonymousDisplayName?: string;
|
|
20
20
|
guestDisplayName?: string;
|
|
21
21
|
accountRoute?: string;
|
|
22
|
+
guestNameConfig?: GuestNameConfig;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export const useUserProfile = (
|
|
@@ -26,9 +27,9 @@ export const useUserProfile = (
|
|
|
26
27
|
): UserProfileData | undefined => {
|
|
27
28
|
const { user } = useAuth();
|
|
28
29
|
|
|
29
|
-
const
|
|
30
|
-
const guestName = params?.guestDisplayName || "Guest User";
|
|
30
|
+
const guestName = params?.guestDisplayName || "Guest";
|
|
31
31
|
const accountRoute = params?.accountRoute || "Account";
|
|
32
|
+
const nameConfig = params?.guestNameConfig;
|
|
32
33
|
|
|
33
34
|
return useMemo(() => {
|
|
34
35
|
if (!user) {
|
|
@@ -39,7 +40,7 @@ export const useUserProfile = (
|
|
|
39
40
|
|
|
40
41
|
if (isAnonymous) {
|
|
41
42
|
return {
|
|
42
|
-
displayName:
|
|
43
|
+
displayName: generateGuestName(user.uid, nameConfig),
|
|
43
44
|
userId: user.uid,
|
|
44
45
|
isAnonymous: true,
|
|
45
46
|
};
|
|
@@ -52,5 +53,5 @@ export const useUserProfile = (
|
|
|
52
53
|
isAnonymous: false,
|
|
53
54
|
avatarUrl: user.photoURL || undefined,
|
|
54
55
|
};
|
|
55
|
-
}, [user,
|
|
56
|
+
}, [user, guestName, accountRoute, nameConfig]);
|
|
56
57
|
};
|