From d92818edea82df00844a2b9bc63447d166bfe689 Mon Sep 17 00:00:00 2001 From: Natsumi Date: Wed, 27 Aug 2025 11:45:37 +1200 Subject: [PATCH] Fix bugs with switching accounts --- src/api/friend.js | 7 ++++--- src/stores/auth.js | 4 ++-- src/stores/friend.js | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/api/friend.js b/src/api/friend.js index 397cee72..56bed238 100644 --- a/src/api/friend.js +++ b/src/api/friend.js @@ -76,18 +76,19 @@ const friendReq = { }, /** - * @param {{ userId: string }} params - * @returns {Promise<{json: any, params: { userId: string }}>} + * currentUserId for own reference + * @param {{ userId: string, currentUserId: string }} params + * @returns {Promise<{json: any, params: { userId: string, currentUserId: string }}>} */ getFriendStatus(params) { return request(`user/${params.userId}/friendStatus`, { method: 'GET' }).then((json) => { - console.log('getFriendStatus', json); const args = { json, params }; + console.log('getFriendStatus', args); return args; }); }, diff --git a/src/stores/auth.js b/src/stores/auth.js index f8233970..e6d2e3b1 100644 --- a/src/stores/auth.js +++ b/src/stores/auth.js @@ -823,7 +823,7 @@ export const useAuthStore = defineStore('Auth', () => { 'Primary password is enabled, this disables auto login.' ); state.attemptingAutoLogin = false; - logout(); + handleLogoutEvent(); return; } const attemptsInLastHour = Array.from(state.autoLoginAttempts).filter( @@ -834,7 +834,7 @@ export const useAuthStore = defineStore('Auth', () => { 'More than 3 auto login attempts within the past hour, logging out instead of attempting auto login.' ); state.attemptingAutoLogin = false; - logout(); + handleLogoutEvent(); return; } state.autoLoginAttempts.add(new Date().getTime()); diff --git a/src/stores/friend.js b/src/stores/friend.js index 48df3b27..de1a5086 100644 --- a/src/stores/friend.js +++ b/src/stores/friend.js @@ -270,6 +270,8 @@ export const useFriendStore = defineStore('Friend', () => { (isLoggedIn) => { state.friends.clear(); state.friendNumber = 0; + state.friendLog.clear(); + state.friendLogTable.data = []; groupStore.groupInstances = []; state.vipFriends_ = []; state.onlineFriends_ = []; @@ -1128,9 +1130,14 @@ export const useFriendStore = defineStore('Friend', () => { } friendRequest .getFriendStatus({ - userId: id + userId: id, + currentUserId: userStore.currentUser.id }) .then((args) => { + if (args.params.currentUserId !== userStore.currentUser.id) { + // safety check for delayed response + return; + } handleFriendStatus(args); if (args.json.isFriend && !state.friendLog.has(id)) { if (state.friendNumber === 0) { @@ -1207,9 +1214,14 @@ export const useFriendStore = defineStore('Friend', () => { } friendRequest .getFriendStatus({ - userId: id + userId: id, + currentUserId: userStore.currentUser.id }) .then((args) => { + if (args.params.currentUserId !== userStore.currentUser.id) { + // safety check for delayed response + return; + } handleFriendStatus(args); if (!args.json.isFriend && state.friendLog.has(id)) { const friendLogHistory = {