Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUT-1539] - Child Window Pop up option #46

Merged
merged 5 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename consts/functions
  • Loading branch information
hwhmeikle committed Oct 26, 2023
commit ebceca71932a9489d147049fb4a162f6331f0f4e
17 changes: 9 additions & 8 deletions src/authsignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export class Authsignal {
private launchWithPopup(url: string, options: PopupLaunchOptions) {
const {popupOptions} = options;

const Popup = new PopupHandler({width: popupOptions?.width});
const popupHandler = new PopupHandler({width: popupOptions?.width});

const popupUrl = `${url}&mode=popup`;

Popup.show({url: popupUrl});
popupHandler.show({url: popupUrl});

return new Promise<TokenPayload>((resolve) => {
const onMessage = (event: MessageEvent) => {
Expand All @@ -99,11 +99,11 @@ export class Authsignal {
if (data?.event === AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP) {
this._token = data.token;

Popup.close();
popupHandler.close();
}
};

Popup.on("hide", () => {
popupHandler.on("hide", () => {
resolve({token: this._token});
});

Expand All @@ -114,11 +114,11 @@ export class Authsignal {
private launchWithWindow(url: string, options: WindowLaunchOptions) {
const {windowOptions} = options;

const Window = new WindowHandler();
const windowHandler = new WindowHandler();

const popupUrl = `${url}&mode=popup`;
const windowUrl = `${url}&mode=popup`;

Window.show({url: popupUrl, width: windowOptions?.width, height: windowOptions?.height});
windowHandler.show({url: windowUrl, width: windowOptions?.width, height: windowOptions?.height});

return new Promise<TokenPayload>((resolve) => {
const onMessage = (event: MessageEvent) => {
Expand All @@ -133,10 +133,11 @@ export class Authsignal {
if (data?.event === AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP) {
this._token = data.token;

Window.close();
windowHandler.close();
resolve({token: this._token});
}
};

window.addEventListener("message", onMessage, false);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/window-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type PopupShowInput = {
type WindowShowInput = {
url: string;
width?: number;
height?: number;
Expand All @@ -10,7 +10,7 @@ const DEFAULT_HEIGHT = 500;
export class WindowHandler {
private windowRef: Window | null = null;

show({url, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT}: PopupShowInput) {
show({url, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT}: WindowShowInput) {
const windowRef = openWindow({url, width, height, win: window});

if (!windowRef) {
Expand All @@ -31,14 +31,14 @@ export class WindowHandler {
}
}

type WindowPopupCenterOptions = {
type OpenWindowInput = {
url: string;
width: number;
height: number;
win: Window;
};

function openWindow({url, width, height, win}: WindowPopupCenterOptions): Window | null {
function openWindow({url, width, height, win}: OpenWindowInput): Window | null {
if (!win.top) {
return null;
}
Expand Down