forked from DeepNotesApp/DeepNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathself-user-name.ts
More file actions
44 lines (40 loc) · 1.05 KB
/
Copy pathself-user-name.ts
File metadata and controls
44 lines (40 loc) · 1.05 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
41
42
43
44
import { bytesToText, textToBytes } from '@stdlib/misc';
import { createSmartComputed } from '@stdlib/vue';
import { once } from 'lodash';
export const selfUserName = once(() =>
createSmartComputed({
get: async () => {
const userEncryptedName = await internals.realtime.globalCtx.hgetAsync(
'user',
authStore().userId,
'encrypted-name',
);
if (userEncryptedName == null) {
return '';
}
return bytesToText(
internals.symmetricKeyring.decrypt(userEncryptedName, {
padding: true,
associatedData: {
context: 'UserName',
userId: authStore().userId,
},
}),
);
},
set: (value) => {
internals.realtime.hset(
'user',
authStore().userId,
'encrypted-name',
internals.symmetricKeyring.encrypt(textToBytes(value), {
padding: true,
associatedData: {
context: 'UserName',
userId: authStore().userId,
},
}),
);
},
}),
);