Skip to content

Commit 4cd91da

Browse files
committed
πŸ”§ Fix LogRocket Username Identification
βœ… LOGROCKET USER IDENTIFICATION FIX: - ADDED: LogRocket user identification to AuthProvider - ADDED: identifyUser call when user logs in with complete user data - ADDED: Comprehensive debugging logs for troubleshooting - FIXED: LogRocket showing 'Anonymous' instead of actual usernames πŸ” Enhanced Debugging: - ADDED: Detailed logging in AuthProvider setUser function - ADDED: User data validation and logging in LogRocket service - ADDED: Clear identification of when LogRocket is/isn't initialized - ADDED: Sanitized user data logging for security 🎯 User Identification Flow: - AuthProvider now calls identifyUser when user state is set - LogRocket receives user ID, username, email, and account type - Proper sanitization of sensitive data (email masking) - Fallback handling for missing user data πŸ“Š LogRocket Integration: - User sessions now properly identified with username - Account type and signup date included in metadata - Session start tracking for user activity - Production-ready user identification πŸ”§ Technical Implementation: - Import identifyUser from LogRocket utils in AuthProvider - Call identifyUser in setUser callback with complete user object - Enhanced error handling and logging for debugging - Proper user data structure for LogRocket API Ready for production testing! πŸš€
1 parent b0cbd67 commit 4cd91da

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

β€Žapp/providers/AuthProvider.tsxβ€Ž

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, { createContext, useContext, useState, useEffect, useCallback, ReactNode } from 'react';
44
import { User, AuthContextValue, AuthState, AuthError, AuthErrorCode } from '../types/auth';
55
import { getEnvironmentType } from '../utils/environmentConfig';
6+
import { identifyUser } from '../utils/logrocket';
67

78
// Create context
89
const AuthContext = createContext<AuthContextValue | null>(null);
@@ -64,6 +65,32 @@ export function AuthProvider({ children }: AuthProviderProps) {
6465
isLoading: false,
6566
error: null
6667
}));
68+
69+
// Identify user in LogRocket when user logs in
70+
if (user) {
71+
try {
72+
console.log('πŸ” AuthProvider: Attempting to identify user in LogRocket:', {
73+
uid: user.uid,
74+
username: user.username,
75+
email: user.email,
76+
hasUsername: !!user.username,
77+
hasEmail: !!user.email
78+
});
79+
80+
identifyUser({
81+
id: user.uid,
82+
username: user.username,
83+
email: user.email,
84+
accountType: 'user',
85+
createdAt: user.createdAt
86+
});
87+
console.log('βœ… LogRocket user identified successfully:', user.username || user.email);
88+
} catch (error) {
89+
console.error('❌ Failed to identify user in LogRocket:', error);
90+
}
91+
} else {
92+
console.log('πŸ” AuthProvider: User is null, skipping LogRocket identification');
93+
}
6794
}, []);
6895

6996
// Check current session

β€Žapp/utils/logrocket.tsβ€Ž

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,18 @@ class LogRocketService {
218218
createdAt?: string;
219219
// Don't include: tokens, balances, payment info, etc.
220220
}): void {
221-
if (!this.isInitialized) return;
221+
console.log('πŸ” LogRocket.identify called with:', {
222+
userId: user.id,
223+
username: user.username,
224+
email: user.email ? `${user.email.substring(0, 3)}***` : undefined,
225+
isInitialized: this.isInitialized,
226+
isProduction: this.isProduction
227+
});
228+
229+
if (!this.isInitialized) {
230+
console.log('⏭️ LogRocket not initialized, skipping user identification');
231+
return;
232+
}
222233

223234
try {
224235
// Sanitize user data - only include safe, non-sensitive information
@@ -228,6 +239,12 @@ class LogRocketService {
228239
email: user.email ? this.sanitizeEmail(user.email) : undefined,
229240
};
230241

242+
console.log('πŸ” LogRocket sanitized user data:', {
243+
id: sanitizedUser.id,
244+
name: sanitizedUser.name,
245+
email: sanitizedUser.email ? `${sanitizedUser.email.substring(0, 3)}***` : undefined
246+
});
247+
231248
// Additional safe metadata
232249
const metadata = {
233250
accountType: user.accountType,
@@ -241,15 +258,18 @@ class LogRocketService {
241258
};
242259

243260
LogRocket.identify(user.id, sanitizedUser);
244-
261+
245262
// Track user session start
246263
this.track('user_session_start', {
247264
userId: user.id,
248265
accountType: user.accountType,
249266
timestamp: new Date().toISOString(),
250267
});
251268

252-
console.log('πŸ‘€ User identified in LogRocket:', user.id);
269+
console.log('πŸ‘€ User identified in LogRocket successfully:', {
270+
userId: user.id,
271+
username: user.username
272+
});
253273
} catch (error) {
254274
console.error('❌ Failed to identify user in LogRocket:', error);
255275
}

0 commit comments

Comments
Β (0)