diff --git a/ee/packages/ddp-client/src/DDPSDK.ts b/ee/packages/ddp-client/src/DDPSDK.ts index 61e0dc6fe28f7..445ce90d7c780 100644 --- a/ee/packages/ddp-client/src/DDPSDK.ts +++ b/ee/packages/ddp-client/src/DDPSDK.ts @@ -113,6 +113,9 @@ export class DDPSDK implements SDK { const sdk = new DDPSDK(connection, stream, account, timeoutControl, rest); connection.on('connected', () => { + if (account.user?.token) { + account.loginWithToken(account.user.token); + } [...stream.subscriptions.entries()].forEach(([, sub]) => { ddp.subscribeWithId(sub.id, sub.name, sub.params); }); diff --git a/ee/packages/ddp-client/src/types/Account.ts b/ee/packages/ddp-client/src/types/Account.ts index 654ae2c2fb4d4..c8a51e4027864 100644 --- a/ee/packages/ddp-client/src/types/Account.ts +++ b/ee/packages/ddp-client/src/types/Account.ts @@ -2,13 +2,20 @@ import { Emitter } from '@rocket.chat/emitter'; import type { ClientStream } from './ClientStream'; +type User = { + id: string; + username?: string; + token?: string; + tokenExpires?: Date; +} & Record; + export interface Account extends Emitter<{ uid: string | undefined; - user: Record | undefined; + user?: User; }> { uid?: string; - user?: Record; + user?: User; loginWithPassword(username: string, password: string): Promise; loginWithToken(token: string): Promise<{ id: string; @@ -21,12 +28,7 @@ export interface Account export class AccountImpl extends Emitter<{ uid: string | undefined; - user: { - id: string; - username?: string; - token?: string; - tokenExpires?: Date; - }; + user: User; }> implements Account { @@ -36,11 +38,6 @@ export class AccountImpl constructor(private readonly client: ClientStream) { super(); - this.client.on('connected', () => { - if (this.user?.token) { - this.loginWithToken(this.user.token); - } - }); client.onCollection('users', (data) => { if (data.collection !== 'users') { @@ -117,6 +114,7 @@ export class AccountImpl wait: true, }); this.uid = undefined; + this.user = undefined; this.emit('uid', this.uid); } }