mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-10 17:04:36 +00:00
fix: while checking session extract username also
This commit is contained in:
582
package-lock.json
generated
582
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -110,7 +110,7 @@ export class AuthManager {
|
||||
//For SAS9 we will send request on SASStoredProcess
|
||||
const url =
|
||||
this.serverType === 'SASVIYA'
|
||||
? `${this.serverUrl}/identities`
|
||||
? `${this.serverUrl}/identities/users/@currentUser`
|
||||
: `${this.serverUrl}/SASStoredProcess`
|
||||
|
||||
const { result: loginResponse } = await this.requestClient
|
||||
@@ -120,6 +120,10 @@ export class AuthManager {
|
||||
})
|
||||
|
||||
const isLoggedIn = loginResponse !== 'authErr'
|
||||
const userName = isLoggedIn
|
||||
? this.extractUserName(loginResponse)
|
||||
: this.userName
|
||||
|
||||
let loginForm = null
|
||||
|
||||
if (!isLoggedIn) {
|
||||
@@ -137,11 +141,16 @@ export class AuthManager {
|
||||
|
||||
return Promise.resolve({
|
||||
isLoggedIn,
|
||||
userName: this.userName,
|
||||
userName: userName ?? this.userName,
|
||||
loginForm
|
||||
})
|
||||
}
|
||||
|
||||
private extractUserName = (response: string) =>
|
||||
this.serverType === 'SASVIYA'
|
||||
? response?.match(/<id>[0-1a-zA-Z]*<\/id>/)?.[0].slice(4, -5)
|
||||
: response?.match(/"title":"Log Off [0-1a-zA-Z]*"/)?.[0].slice(17, -1)
|
||||
|
||||
private getLoginForm(response: any) {
|
||||
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
|
||||
const matches = pattern.exec(response)
|
||||
|
||||
@@ -175,7 +175,7 @@ describe('AuthManager', () => {
|
||||
expect(response.isLoggedIn).toBeTruthy()
|
||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
`http://test-server.com/identities`,
|
||||
`http://test-server.com/identities/users/@currentUser`,
|
||||
{
|
||||
withCredentials: true,
|
||||
responseType: 'text',
|
||||
|
||||
Reference in New Issue
Block a user