diff --git a/apps/meteor/app/models/client/models/Users.ts b/apps/meteor/app/models/client/models/Users.ts index 089486f3a20ca1d407c7e33ad0bc9adfbbd74c3e..26d333cc8bb1bf29ac9fc010d341a214b80ef1cf 100644 --- a/apps/meteor/app/models/client/models/Users.ts +++ b/apps/meteor/app/models/client/models/Users.ts @@ -30,5 +30,13 @@ class UsersCollection extends Mongo.Collection<IUser> { } } +Object.assign(Meteor.users, { + _connection: undefined, + findOneById: UsersCollection.prototype.findOneById, + isUserInRole: UsersCollection.prototype.isUserInRole, + findUsersInRoles: UsersCollection.prototype.findUsersInRoles, + remove: UsersCollection.prototype.remove, +}); + /** @deprecated */ -export const Users = new UsersCollection(); +export const Users = Meteor.users as UsersCollection; diff --git a/apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts b/apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts index 845731e2450adc1eef3d5c7ab2bc6f41bcc7bcb5..52d6661d706198eac5819ed3e09e75e9892f959a 100644 --- a/apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts +++ b/apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts @@ -11,15 +11,12 @@ class CachedCollectionManager extends Emitter<{ reconnect: void; login: string | private _syncEnabled: boolean; - private logged: boolean; - private step: number; constructor() { super(); this.items = []; this._syncEnabled = false; - this.logged = false; const { _unstoreLoginToken } = Accounts; Accounts._unstoreLoginToken = (...args) => { @@ -40,14 +37,6 @@ class CachedCollectionManager extends Emitter<{ reconnect: void; login: string | return connected && this.emit('reconnect'); } }); - - Tracker.autorun(() => { - const uid = Meteor.userId(); - this.logged = uid !== null; - if (this.logged) { - this.emit('login', uid); - } - }); } register(cachedCollection: CachedCollection<any>) { @@ -80,10 +69,7 @@ class CachedCollectionManager extends Emitter<{ reconnect: void; login: string | } onLogin(cb: () => void) { - this.on('login', cb); - if (this.logged) { - cb(); - } + Accounts.onLogin(cb); } } diff --git a/apps/meteor/client/startup/startup.ts b/apps/meteor/client/startup/startup.ts index 2541529a1aef8e41f609622e5422b4fcc128100f..45c102a72bf49e5ca012ffeb5759d49bbbc943fc 100644 --- a/apps/meteor/client/startup/startup.ts +++ b/apps/meteor/client/startup/startup.ts @@ -28,10 +28,15 @@ Meteor.startup(() => { removeLocalUserData(); return; } + if (!Meteor.status().connected) { return; } + if (Meteor.loggingIn()) { + return; + } + const user = await synchronizeUserData(uid); if (!user) { return; diff --git a/apps/meteor/client/views/root/SAMLLoginRoute.tsx b/apps/meteor/client/views/root/SAMLLoginRoute.tsx index 61ceb82a5ee7c7109167f30879bc4a99a7fa9137..2e12b036a4b9546701360fa73d4a6489b07a7478 100644 --- a/apps/meteor/client/views/root/SAMLLoginRoute.tsx +++ b/apps/meteor/client/views/root/SAMLLoginRoute.tsx @@ -1,5 +1,5 @@ import type { LocationPathname } from '@rocket.chat/ui-contexts'; -import { useRouter, useToastMessageDispatch, useUserId, useAbsoluteUrl } from '@rocket.chat/ui-contexts'; +import { useRouter, useToastMessageDispatch, useAbsoluteUrl } from '@rocket.chat/ui-contexts'; import { Meteor } from 'meteor/meteor'; import { useEffect } from 'react'; @@ -38,20 +38,6 @@ const SAMLLoginRoute = () => { }); }, [dispatchToastMessage, rootUrl, router]); - const userId = useUserId(); - useEffect(() => { - if (!userId) { - return; - } - - router.navigate( - { - pathname: '/home', - }, - { replace: true }, - ); - }, [userId, router]); - return null; }; diff --git a/apps/meteor/tests/unit/client/views/root/SAMLLoginRoute.spec.tsx b/apps/meteor/tests/unit/client/views/root/SAMLLoginRoute.spec.tsx index bfd0d9ec0a6b9bf8576a91872f4704834897035a..bca7538e46c19f621c1c3116b8d1804555fc48bd 100644 --- a/apps/meteor/tests/unit/client/views/root/SAMLLoginRoute.spec.tsx +++ b/apps/meteor/tests/unit/client/views/root/SAMLLoginRoute.spec.tsx @@ -19,7 +19,7 @@ describe('views/root/SAMLLoginRoute', () => { loginWithSamlTokenStub.callsFake((_token, callback) => callback()); }); - it('should redirect to /home when userId is not null', async () => { + it('should redirect to /home', async () => { render( <MockedServerContext> <MockedUserContext> @@ -30,7 +30,7 @@ describe('views/root/SAMLLoginRoute', () => { </MockedServerContext>, ); - expect(navigateStub.calledTwice).toBe(true); + expect(navigateStub.calledOnce).toBe(true); expect( navigateStub.calledWith( sinon.match({ @@ -40,7 +40,7 @@ describe('views/root/SAMLLoginRoute', () => { ).toBe(true); }); - it('should redirect to /home when userId is null and redirectUrl is not within the workspace domain', async () => { + it('should redirect to /home when redirectUrl is not within the workspace domain', async () => { render( <MockedServerContext> <RouterContextMock searchParameters={{ redirectUrl: 'http://rocket.chat' }} navigate={navigateStub}> @@ -58,7 +58,7 @@ describe('views/root/SAMLLoginRoute', () => { ).toBe(true); }); - it('should redirect to the provided redirectUrl when userId is null and redirectUrl is within the workspace domain', async () => { + it('should redirect to the provided redirectUrl when redirectUrl is within the workspace domain', async () => { render( <MockedServerContext> <RouterContextMock searchParameters={{ redirectUrl: 'http://localhost:3000/invite/test' }} navigate={navigateStub}>