Skip to content

Commit 3b776b4

Browse files
committed
Fix bug where context is not updated correctly after logging in
1 parent 36c58fc commit 3b776b4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

frontend/src/app/components/auth/LoginComponent.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,13 @@ export default function LoginForm() {
5151
// Store token
5252
addToken(token);
5353

54-
// Parse token to get user data and set in context
55-
try {
56-
const payload = JSON.parse(atob(token.split('.')[1]));
57-
if (payload.username && payload.email) {
58-
setUser({
59-
username: payload.username,
60-
email: payload.email,
61-
});
62-
}
63-
} catch (error) {
64-
console.error("Error parsing token:", error);
54+
// Set user data from the API response
55+
const userData = response?.data?.data;
56+
if (userData?.username && userData?.email) {
57+
setUser({
58+
username: userData.username,
59+
email: userData.email,
60+
});
6561
}
6662

6763
// Show success message

0 commit comments

Comments
 (0)