Skip to content

Commit

Permalink
chore(client): stop replacing Meteor.user (#32910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Jul 26, 2024
1 parent 7c5eac8 commit 776fc1e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 35 deletions.
10 changes: 9 additions & 1 deletion apps/meteor/app/models/client/models/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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>) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 5 additions & 0 deletions apps/meteor/client/startup/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 1 addition & 15 deletions apps/meteor/client/views/root/SAMLLoginRoute.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -30,7 +30,7 @@ describe('views/root/SAMLLoginRoute', () => {
</MockedServerContext>,
);

expect(navigateStub.calledTwice).toBe(true);
expect(navigateStub.calledOnce).toBe(true);
expect(
navigateStub.calledWith(
sinon.match({
Expand All @@ -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}>
Expand All @@ -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}>
Expand Down

0 comments on commit 776fc1e

Please sign in to comment.