-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathuserIdentityHelper.tsx
41 lines (35 loc) · 1.02 KB
/
userIdentityHelper.tsx
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
import React from 'react';
import { IdentityRef } from 'azure-devops-extension-api/WebApi';
import { SDKContext } from '../dal/azureDevOpsContextProvider';
let userIdentity: IdentityRef;
/**
* Get the identity of current user
*/
export const getUserIdentity = (): IdentityRef => {
if (!userIdentity){
const { SDK } = React.useContext(SDKContext);
const currentUser = SDK.getUser();
userIdentity = {
id: currentUser.id,
displayName: currentUser.displayName,
uniqueName: currentUser.name,
imageUrl: currentUser.imageUrl,
_links: {
avatar: {
href: currentUser.imageUrl,
},
},
} as IdentityRef;
}
return userIdentity;
}
export const encrypt = (id: string): string => {
return id.split('').reverse().map(char => {
return String.fromCharCode(char.charCodeAt(0) + 4);
}).join('');
}
export const decrypt = (id: string): string => {
return id.split('').reverse().map(char => {
return String.fromCharCode(char.charCodeAt(0) - 4);
}).join('');
}