diff --git a/src/features/auth/model/cleanupData.ts b/src/features/auth/model/cleanupData.ts index 87afb2b13..6f24d2f24 100644 --- a/src/features/auth/model/cleanupData.ts +++ b/src/features/auth/model/cleanupData.ts @@ -2,6 +2,13 @@ import { clearEntityRecordStorages } from '@features/auth/lib/clearEntityRecordS import { clearUploadQueueStorage } from '@features/auth/lib/clearUploadQueueStorage'; import { getDefaultLogger } from '@shared/lib/services/loggerInstance'; +// Clear entity record and progression data. +// This function should only be called upon successful login, and that the +// just logged-in user's ID is not the same as the previously logged-in user's +// ID. +// This function should not be called upon log out. This way, previously stored +// entity record and progression data can be preserved for the same user over +// multiple sessions. This is an intended behaviour. export async function cleanupData() { getDefaultLogger().info( '[cleanupData] Processing cleanup upon another user login', diff --git a/src/features/login/ui/LoginForm.tsx b/src/features/login/ui/LoginForm.tsx index 0e5fa4f84..289a18bdd 100644 --- a/src/features/login/ui/LoginForm.tsx +++ b/src/features/login/ui/LoginForm.tsx @@ -59,6 +59,11 @@ export const LoginForm: FC = props => { password: variables.password, }; + // If the previously logged-in user's ID is not the same as the just + // logged-in user's ID, then clear previously stored data. + // We are able to make this determination because previously stored data + // is not cleared on log out (only session info is cleared on log out), + // and this is an intended behaviour. if (userParams.userId !== userId) { await cleanupData(); dispatch(cleanUpAction()); diff --git a/src/features/logout/model/hooks.ts b/src/features/logout/model/hooks.ts index 1539fc956..71dab8426 100644 --- a/src/features/logout/model/hooks.ts +++ b/src/features/logout/model/hooks.ts @@ -16,7 +16,6 @@ import { getDefaultLogger } from '@app/shared/lib/services/loggerInstance'; import { useTCPSocket } from '@app/shared/lib/tcp/useTCPSocket'; import { isAppOnline } from '@app/shared/lib/utils/networkHelpers'; import { hasPendingMutations } from '@app/shared/lib/utils/reactQueryHelpers'; -import { cleanupData } from '@features/auth/model/cleanupData'; export function useLogout() { const queryClient = useQueryClient(); @@ -58,8 +57,6 @@ export function useLogout() { queryClient.clear(); - await cleanupData(); - getDefaultSessionService().clearSession(); closeActiveTCPConnection();