Skip to content

Commit 7a26922

Browse files
committed
Refactor AuthContext to improve user identification handling for Umami tracking. Simplify logic by removing unnecessary checks and ensuring user data is set correctly upon authentication. This enhances clarity and maintainability of the authentication context.
1 parent b878aea commit 7a26922

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

frontend/src/contexts/AuthContext.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,19 @@ export const useAuth = () => {
5151

5252
// Handle Umami user identification
5353
useEffect(() => {
54-
if (isAuthenticated && transformedUser) {
55-
// Set user for Umami identification
56-
setUmamiUser({
57-
email: transformedUser.email,
58-
id: transformedUser.id,
59-
name: transformedUser.name,
60-
// Add additional properties if available
61-
sub: user?.sub,
62-
});
63-
} else if (!isAuthenticated) {
54+
if (!isAuthenticated) {
6455
// Clear user identification when logged out
6556
clearUmamiUser();
57+
return;
58+
}
59+
if (user) {
60+
setUmamiUser({
61+
email: user.email,
62+
id: user.sub,
63+
name: user.name,
64+
});
6665
}
67-
}, [isAuthenticated, transformedUser, user]);
66+
}, [isAuthenticated, user]);
6867

6968
// Wrap the Auth0 logout to match our previous API
7069
const logout = () => {

0 commit comments

Comments
 (0)