-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathinsertOrUpdateUser.ts
More file actions
32 lines (26 loc) · 1.03 KB
/
insertOrUpdateUser.ts
File metadata and controls
32 lines (26 loc) · 1.03 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
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import { twoFactorRequired } from '../../../2fa/server/twoFactorRequired';
import type { ISaveUserDataParams } from '../functions/saveUser';
import { saveUser } from '../functions/saveUser';
import { methodDeprecationLogger } from '../lib/deprecationWarningLogger';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
insertOrUpdateUser(userData: Record<string, unknown>): Promise<string | boolean>;
}
}
Meteor.methods<ServerMethods>({
insertOrUpdateUser: twoFactorRequired(async (userData) => {
methodDeprecationLogger.method('insertOrUpdateUser', '8.0.0');
check(userData, Object);
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'insertOrUpdateUser',
});
}
return saveUser(userId, userData as ISaveUserDataParams);
}),
});