diff --git a/src/SASjs.ts b/src/SASjs.ts index 2c08f70..1458a69 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -25,6 +25,7 @@ import { Sas9JobExecutor } from './job-execution' import { ErrorResponse } from './types/errors' +import { LoginOptions } from './types/LoginOptions' const defaultConfig: SASjsConfig = { serverUrl: '', @@ -533,7 +534,11 @@ export default class SASjs { * @param username - a string representing the username. * @param password - a string representing the password. */ - public async logIn(username?: string, password?: string) { + public async logIn( + username?: string, + password?: string, + options: LoginOptions = {} + ) { if (this.sasjsConfig.loginMechanism === LoginMechanism.Default) { if (!username || !password) { throw new Error( @@ -549,7 +554,7 @@ export default class SASjs { ) } - return this.authManager!.redirectedLogIn() + return this.authManager!.redirectedLogIn(options) } /** diff --git a/src/auth/AuthManager.ts b/src/auth/AuthManager.ts index c97f5ea..ed2728c 100644 --- a/src/auth/AuthManager.ts +++ b/src/auth/AuthManager.ts @@ -1,5 +1,6 @@ import { ServerType } from '@sasjs/utils/types' import { RequestClient } from '../request/RequestClient' +import { LoginOptions } from '../types/LoginOptions' import { serialize } from '../utils' import { openWebPage } from './openWebPage' import { verifyingPopUpLoginSAS9 } from './verifyingPopUpLoginSAS9' @@ -27,11 +28,15 @@ export class AuthManager { * Opens Pop up window to SAS Login screen. * And checks if user has finished login process. */ - public async redirectedLogIn() { + public async redirectedLogIn({ onLoggedOut }: LoginOptions) { const loginPopup = await openWebPage( this.loginPreventRedirectUrl, 'SASLogon', - { width: 500, height: 600 } + { + width: 500, + height: 600 + }, + onLoggedOut ) if (!loginPopup) { diff --git a/src/auth/openWebPage.ts b/src/auth/openWebPage.ts index 79f3a4f..f50167d 100644 --- a/src/auth/openWebPage.ts +++ b/src/auth/openWebPage.ts @@ -8,7 +8,8 @@ interface windowFeatures { export async function openWebPage( url: string, windowName: string = '', - { width, height }: windowFeatures + { width, height }: windowFeatures, + onLoggedOut?: Function ): Promise { const left = screen.width / 2 - width / 2 const top = screen.height / 2 - height / 2 @@ -20,6 +21,11 @@ export async function openWebPage( ) if (!loginPopup) { + if (onLoggedOut) { + onLoggedOut() + return null + } + const doLogin = await openLoginPrompt() return doLogin ? window.open( diff --git a/src/types/LoginOptions.ts b/src/types/LoginOptions.ts new file mode 100644 index 0000000..e4d1809 --- /dev/null +++ b/src/types/LoginOptions.ts @@ -0,0 +1,3 @@ +export interface LoginOptions { + onLoggedOut?: Function +}