Skip to content

Commit

Permalink
fix: Run QueryClient.clear() on logout (#32587)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Jun 12, 2024
1 parent 7deda6e commit 404a303
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-readers-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes issues with loading license modules when loading the page while logged out
7 changes: 5 additions & 2 deletions apps/meteor/client/providers/UserProvider/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
import { UserContext, useEndpoint } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import type { ContextType, ReactElement, ReactNode } from 'react';
import React, { useEffect, useMemo } from 'react';
import React, { useEffect, useMemo, useRef } from 'react';

import { Subscriptions, ChatRoom } from '../../../app/models/client';
import { getUserPreference } from '../../../app/utils/client';
Expand Down Expand Up @@ -43,6 +43,7 @@ type UserProviderProps = {

const UserProvider = ({ children }: UserProviderProps): ReactElement => {
const userId = useReactiveValue(getUserId);
const previousUserId = useRef(userId);
const user = useReactiveValue(getUser);
const [userLanguage, setUserLanguage] = useLocalStorage('userLanguage', '');
const [preferedLanguage, setPreferedLanguage] = useLocalStorage('preferedLanguage', '');
Expand Down Expand Up @@ -94,9 +95,11 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => {
}, [preferedLanguage, setPreferedLanguage, setUserLanguage, user?.language, userLanguage, userId, setUserPreferences]);

useEffect(() => {
if (!userId) {
if (previousUserId.current && previousUserId.current !== userId) {
queryClient.clear();
}

previousUserId.current = userId;
}, [userId]);

return <UserContext.Provider children={children} value={contextValue} />;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Page } from '@playwright/test';

import { ADMIN_CREDENTIALS, IS_EE } from '../config/constants';
import injectInitialData from '../fixtures/inject-initial-data';
import { test, expect } from '../utils/test';

test.describe('OC - Enterprise Menu Items After Relogin', () => {
// Create page object and redirect to home
test.beforeEach(async ({ page }: { page: Page }) => {
await page.goto('/omnichannel/current');

await page.locator('role=textbox[name=/username/i]').waitFor({ state: 'visible' });
await page.locator('role=textbox[name=/username/i]').fill(ADMIN_CREDENTIALS.email);
await page.locator('[name=password]').fill(ADMIN_CREDENTIALS.password);
await page.locator('role=button[name="Login"]').click();

await page.locator('.main-content').waitFor();
});

// Delete all data
test.afterAll(async () => {
await injectInitialData();
});

test('OC - Enterprise Menu Items - Logout & Login', async ({ page }) => {
test.skip(!IS_EE);
await test.step('expect EE menu items to be visible', async () => {
await expect(page.locator('a[href="/omnichannel/tags"]')).toBeVisible();
});
});
});

0 comments on commit 404a303

Please sign in to comment.