Skip to content
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
3 changes: 3 additions & 0 deletions ee/packages/ddp-client/src/DDPSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
24 changes: 11 additions & 13 deletions ee/packages/ddp-client/src/types/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;

export interface Account
extends Emitter<{
uid: string | undefined;
user: Record<string, unknown> | undefined;
user?: User;
}> {
uid?: string;
user?: Record<string, unknown>;
user?: User;
loginWithPassword(username: string, password: string): Promise<void>;
loginWithToken(token: string): Promise<{
id: string;
Expand All @@ -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
{
Expand All @@ -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') {
Expand Down Expand Up @@ -117,6 +114,7 @@ export class AccountImpl
wait: true,
});
this.uid = undefined;
this.user = undefined;
this.emit('uid', this.uid);
}
}