Skip to content

Commit e7e1065

Browse files
fix: prevent duplicate login profiles in dropdown
When users log out and log back in with the same profile, the profile was being added to the profiles array again, causing duplicates in the dropdown menu. This change modifies the login action to check if a profile with the same ID already exists before adding it. If it exists, the profile is updated instead of creating a duplicate entry. Fixes duplicate profile issue reported in PR comments. Co-authored-by: Anguel <modelorona@users.noreply.github.com>
1 parent 7973bf5 commit e7e1065

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

frontend/src/store/auth.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ export const authSlice = createSlice({
4141
...(action.payload as LoginCredentials),
4242
}
4343
state.current = profile as LocalLoginProfile;
44-
state.profiles.push(profile as LocalLoginProfile);
44+
45+
// Check if profile already exists to prevent duplicates
46+
const existingProfileIndex = state.profiles.findIndex(p => p.Id === profile.Id);
47+
if (existingProfileIndex >= 0) {
48+
// Update existing profile instead of adding duplicate
49+
state.profiles[existingProfileIndex] = profile as LocalLoginProfile;
50+
} else {
51+
// Add new profile
52+
state.profiles.push(profile as LocalLoginProfile);
53+
}
54+
4555
state.status = "logged-in";
4656
},
4757
switch: (state, action: PayloadAction<{id: string}>) => {

0 commit comments

Comments
 (0)