mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-15 08:00:05 +00:00
chore: redirect login with onLoggedOut callback
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
|||||||
Sas9JobExecutor
|
Sas9JobExecutor
|
||||||
} from './job-execution'
|
} from './job-execution'
|
||||||
import { ErrorResponse } from './types/errors'
|
import { ErrorResponse } from './types/errors'
|
||||||
|
import { LoginOptions } from './types/LoginOptions'
|
||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: '',
|
serverUrl: '',
|
||||||
@@ -533,7 +534,11 @@ export default class SASjs {
|
|||||||
* @param username - a string representing the username.
|
* @param username - a string representing the username.
|
||||||
* @param password - a string representing the password.
|
* @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 (this.sasjsConfig.loginMechanism === LoginMechanism.Default) {
|
||||||
if (!username || !password) {
|
if (!username || !password) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -549,7 +554,7 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.authManager!.redirectedLogIn()
|
return this.authManager!.redirectedLogIn(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import { RequestClient } from '../request/RequestClient'
|
import { RequestClient } from '../request/RequestClient'
|
||||||
|
import { LoginOptions } from '../types/LoginOptions'
|
||||||
import { serialize } from '../utils'
|
import { serialize } from '../utils'
|
||||||
import { openWebPage } from './openWebPage'
|
import { openWebPage } from './openWebPage'
|
||||||
import { verifyingPopUpLoginSAS9 } from './verifyingPopUpLoginSAS9'
|
import { verifyingPopUpLoginSAS9 } from './verifyingPopUpLoginSAS9'
|
||||||
@@ -27,11 +28,15 @@ export class AuthManager {
|
|||||||
* Opens Pop up window to SAS Login screen.
|
* Opens Pop up window to SAS Login screen.
|
||||||
* And checks if user has finished login process.
|
* And checks if user has finished login process.
|
||||||
*/
|
*/
|
||||||
public async redirectedLogIn() {
|
public async redirectedLogIn({ onLoggedOut }: LoginOptions) {
|
||||||
const loginPopup = await openWebPage(
|
const loginPopup = await openWebPage(
|
||||||
this.loginPreventRedirectUrl,
|
this.loginPreventRedirectUrl,
|
||||||
'SASLogon',
|
'SASLogon',
|
||||||
{ width: 500, height: 600 }
|
{
|
||||||
|
width: 500,
|
||||||
|
height: 600
|
||||||
|
},
|
||||||
|
onLoggedOut
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!loginPopup) {
|
if (!loginPopup) {
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ interface windowFeatures {
|
|||||||
export async function openWebPage(
|
export async function openWebPage(
|
||||||
url: string,
|
url: string,
|
||||||
windowName: string = '',
|
windowName: string = '',
|
||||||
{ width, height }: windowFeatures
|
{ width, height }: windowFeatures,
|
||||||
|
onLoggedOut?: Function
|
||||||
): Promise<Window | null> {
|
): Promise<Window | null> {
|
||||||
const left = screen.width / 2 - width / 2
|
const left = screen.width / 2 - width / 2
|
||||||
const top = screen.height / 2 - height / 2
|
const top = screen.height / 2 - height / 2
|
||||||
@@ -20,6 +21,11 @@ export async function openWebPage(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!loginPopup) {
|
if (!loginPopup) {
|
||||||
|
if (onLoggedOut) {
|
||||||
|
onLoggedOut()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const doLogin = await openLoginPrompt()
|
const doLogin = await openLoginPrompt()
|
||||||
return doLogin
|
return doLogin
|
||||||
? window.open(
|
? window.open(
|
||||||
|
|||||||
3
src/types/LoginOptions.ts
Normal file
3
src/types/LoginOptions.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export interface LoginOptions {
|
||||||
|
onLoggedOut?: Function
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user