Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Run QueryClient.clear() on logout #32587

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
});
Loading