-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathAccount.ts
More file actions
40 lines (29 loc) · 1.13 KB
/
Account.ts
File metadata and controls
40 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { ServiceClass, Settings } from '@rocket.chat/core-services';
import type { IAccount, ILoginResult } from '@rocket.chat/core-services';
import { getLoginExpirationInDays } from '@rocket.chat/tools';
import { loginViaResume } from './lib/loginViaResume';
import { removeSession } from './lib/removeSession';
export class Account extends ServiceClass implements IAccount {
protected name = 'accounts';
private loginExpiration = 90;
constructor() {
super();
this.onSettingChanged('Accounts_LoginExpiration', async ({ setting }): Promise<void> => {
const { value } = setting;
this.loginExpiration = getLoginExpirationInDays(value as number);
});
}
async login({ resume }: { resume: string }): Promise<false | ILoginResult> {
if (resume) {
return loginViaResume(resume, this.loginExpiration);
}
return false;
}
async logout({ userId, token }: { userId: string; token: string }): Promise<void> {
return removeSession(userId, token);
}
override async started(): Promise<void> {
const expiry = await Settings.get<number>('Accounts_LoginExpiration');
this.loginExpiration = getLoginExpirationInDays(expiry);
}
}