diff --git a/sasjs-tests/src/testSuites/Basic.ts b/sasjs-tests/src/testSuites/Basic.ts
index 3e1e256..b045874 100644
--- a/sasjs-tests/src/testSuites/Basic.ts
+++ b/sasjs-tests/src/testSuites/Basic.ts
@@ -37,6 +37,17 @@ export const basicTests = (
assertion: (response: any) =>
response && response.isLoggedIn && response.userName === userName
},
+ {
+ title: "Multiple Log in attempts",
+ description: "Should fail on first attempt and should log the user in on second attempt",
+ test: async () => {
+ await adapter.logOut()
+ await adapter.logIn('invalid', 'invalid')
+ return adapter.logIn(userName, password)
+ },
+ assertion: (response: any) =>
+ response && response.isLoggedIn && response.userName === userName
+ },
{
title: "Default config",
description:
diff --git a/src/SASjs.ts b/src/SASjs.ts
index edb0232..27e0489 100644
--- a/src/SASjs.ts
+++ b/src/SASjs.ts
@@ -411,6 +411,29 @@ export default class SASjs {
}
}
+ private async getLoginForm(response: any) {
+ const pattern: RegExp = /
/
+ const matches = pattern.exec(response)
+ const formInputs: any = {}
+
+ if (matches && matches.length) {
+ this.setLoginUrl(matches)
+ const inputs = response.match(/]*>/g)
+
+ if (inputs) {
+ inputs.forEach((inputStr: string) => {
+ const valueMatch = inputStr.match(/name="([^"]*)"\svalue="([^"]*)/)
+
+ if (valueMatch && valueMatch.length) {
+ formInputs[valueMatch[1]] = valueMatch[2]
+ }
+ })
+ }
+ }
+
+ return Object.keys(formInputs).length ? formInputs : null
+ }
+
/**
* Checks whether a session is active, or login is required.
* @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
@@ -419,10 +442,16 @@ export default class SASjs {
const loginResponse = await fetch(this.loginUrl.replace('.do', ''))
const responseText = await loginResponse.text()
const isLoggedIn = //
- const response = await fetch(this.loginUrl).then((r) => r.text())
- const matches = pattern.exec(response)
- const formInputs: any = {}
- if (matches && matches.length) {
- this.setLoginUrl(matches)
- const inputs = response.match(/]*>/g)
- if (inputs) {
- inputs.forEach((inputStr: string) => {
- const valueMatch = inputStr.match(/name="([^"]*)"\svalue="([^"]*)/)
- if (valueMatch && valueMatch.length) {
- formInputs[valueMatch[1]] = valueMatch[2]
- }
- })
- }
- }
- return Object.keys(formInputs).length ? formInputs : null
- }
-
private async createFoldersAndServices(
parentFolder: string,
membersJson: any[],