mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-11 06:10:05 +00:00
fix(auth): login and check session returns username + user full name
This commit is contained in:
31
src/utils/sas9/extractUserLongNameSas9.ts
Normal file
31
src/utils/sas9/extractUserLongNameSas9.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Dictionary should contain only languages in SAS where `logout` text
|
||||
* is represented with more then one word
|
||||
*/
|
||||
const dictionary = ['Log Off']
|
||||
|
||||
/**
|
||||
* Extracts user full name assuming the first word after "title" means log off if not found otherwise in the dictionary
|
||||
* @param response SAS response content
|
||||
* @returns user full name
|
||||
*/
|
||||
export const extractUserLongNameSas9 = (response: string) => {
|
||||
const regex = /"title":\s?".*?"/
|
||||
|
||||
const matched = response?.match(regex)
|
||||
let fullName = matched?.[0].split(':')[1].trim()
|
||||
let breakIndex = fullName?.indexOf(' ')
|
||||
|
||||
if (!fullName) return 'unknown'
|
||||
|
||||
dictionary.map((logoutWord) => {
|
||||
const index = fullName?.indexOf(logoutWord) || -1
|
||||
|
||||
if (index > -1) {
|
||||
breakIndex = index + logoutWord.length
|
||||
}
|
||||
})
|
||||
|
||||
//Cut only name
|
||||
return fullName.slice(breakIndex, -1).trim()
|
||||
}
|
||||
Reference in New Issue
Block a user