Skip to content
Snippets Groups Projects
Unverified Commit 3d019906 authored by dionisio-bot[bot]'s avatar dionisio-bot[bot] Committed by GitHub
Browse files

fix: Forget session on window close (#33129)

parent 9e1b9ad6
No related branches found
No related tags found
No related merge requests found
---
'@rocket.chat/meteor': patch
---
Fixed an issue related to setting Accounts_ForgetUserSessionOnWindowClose, this setting was not working as expected.
The new meteor 2.16 release introduced a new option to configure the Accounts package and choose between the local storage or session storage. They also changed how Meteor.\_localstorage works internally. Due to these changes in Meteor, our setting to use session storage wasn't working as expected. This PR fixes this issue and configures the Accounts package according to the workspace settings.
...@@ -2,6 +2,7 @@ import { Accounts } from 'meteor/accounts-base'; ...@@ -2,6 +2,7 @@ import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker'; import { Tracker } from 'meteor/tracker';
import { settings } from '../../app/settings/client';
import { mainReady } from '../../app/ui-utils/client'; import { mainReady } from '../../app/ui-utils/client';
import { sdk } from '../../app/utils/client/lib/SDKClient'; import { sdk } from '../../app/utils/client/lib/SDKClient';
import { t } from '../../app/utils/lib/i18n'; import { t } from '../../app/utils/lib/i18n';
...@@ -24,3 +25,15 @@ Accounts.onEmailVerificationLink((token: string) => { ...@@ -24,3 +25,15 @@ Accounts.onEmailVerificationLink((token: string) => {
}); });
}); });
}); });
Meteor.startup(() => {
Tracker.autorun(() => {
const forgetUserSessionOnWindowClose = settings.get('Accounts_ForgetUserSessionOnWindowClose');
if (forgetUserSessionOnWindowClose === undefined) {
return;
}
Accounts.config({ clientStorage: forgetUserSessionOnWindowClose ? 'session' : 'local' });
});
});
...@@ -42,6 +42,8 @@ declare module 'meteor/accounts-base' { ...@@ -42,6 +42,8 @@ declare module 'meteor/accounts-base' {
function _clearAllLoginTokens(userId: string | null): void; function _clearAllLoginTokens(userId: string | null): void;
function config(options: { clientStorage: 'session' | 'local' }): void;
class ConfigError extends Error {} class ConfigError extends Error {}
class LoginCancelledError extends Error { class LoginCancelledError extends Error {
......
import { DEFAULT_USER_CREDENTIALS } from './config/constants';
import { Registration } from './page-objects';
import { test, expect } from './utils/test';
test.describe.serial('Forget session on window close setting', () => {
let poRegistration: Registration;
test.beforeEach(async ({ page }) => {
poRegistration = new Registration(page);
await page.goto('/home');
});
test.describe('Setting off', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
});
test('Login using credentials and reload to stay logged in', async ({ page, context }) => {
await poRegistration.username.type('user1');
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password);
await poRegistration.btnLogin.click();
await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible();
const newPage = await context.newPage();
await newPage.goto('/home');
await expect(newPage.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible();
});
});
test.describe('Setting on', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true });
});
test.afterAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
});
test('Login using credentials and reload to get logged out', async ({ page, context }) => {
await poRegistration.username.type('user1');
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password);
await poRegistration.btnLogin.click();
await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible();
const newPage = await context.newPage();
await newPage.goto('/home');
await expect(newPage.locator('role=button[name="Login"]')).toBeVisible();
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment