frontend: add sanitizer to internal user & clean up logs
This sanitizer is kind of dumb, but, it'll do for now
Parents:
ba963711 file(s) changed
- frontend/context/AuthContext.tsx +18 -6
frontend/context/AuthContext.tsx
@@ -14,6 +14,8 @@ firstName: string;
14 14 lastName?: string;
15 15 email: string;
16 16 updatedAt: date;
17 + avatarURL?: string;
18 + avatarKey?: string;
17 19 }) => void;
18 20 login: (email: string, password: string) => Promise<void>;
19 21 signup: (userData: {
@@ -27,6 +29,19 @@ forgotPassword: (email: string) => Promise<{ message: string; token?: string }>;
27 29 resetPassword: (token: string, password: string) => Promise<void>;
28 30 }
29 31
32 +
33 + export function sanitizeUser(data: any): User {
34 + return {
35 + id: data.id,
36 + email: data.email,
37 + firstName: data.firstName,
38 + lastName: data.lastName,
39 + updatedAt: data.updatedAt,
40 + avatarKey: data.avatarKey,
41 + avatarURL: data.avatarURL,
42 + };
43 + }
44 +
30 45 const AuthContext = createContext<AuthContextType | null>(null);
31 46
32 47 export function useAuth() {
@@ -41,10 +56,7 @@
41 56 export const AuthProvider = ({ children }: AuthProviderProps) => {
42 57 const [user, setUser] = useState<User | null>(null);
43 58 const [isLoading, setIsLoading] = useState(true);
44 -
45 - console.log("user & auth", isAuthenticated, user)
46 59 const isAuthenticated = !!user;
47 - console.log("after user & auth", isAuthenticated, user)
48 60
49 61 // Check for existing authentication on app start
50 62 useEffect(() => {
@@ -54,11 +66,9 @@
54 66 const checkAuthState = async () => {
55 67 try {
56 68 const { token } = await apiClient.getStoredAuthData();
57 - console.log("We have a token?", token);
58 69
59 70 if (token) {
60 71 const verifyResponse = await apiClient.verifyToken();
61 - console.log("Checking response: ", verifyResponse)
62 72 if (verifyResponse.valid && verifyResponse.userId && verifyResponse.email) {
63 73 // TODO: Fetch the full user profile
64 74 // For now, we'll create a basic user object
@@ -67,6 +77,8 @@ id: verifyResponse.userId,
67 77 email: verifyResponse.email,
68 78 firstName: verifyResponse.user.firstName,
69 79 lastName: verifyResponse.user.lastName,
80 + avatarURL: verifyResponse.user.avatarURL,
81 + avatarKey: verifyResponse.user.avatarKey
70 82 });
71 83 }
72 84 }
@@ -124,7 +136,7 @@ await apiClient.resetPassword(token, password);
124 136 };
125 137
126 138 const updateAuthUser = (user) => {
127 - setUser(user);
139 + setUser(sanitizeUser(user));
128 140 }
129 141
130 142 const value: AuthContextType = {