Skip to content
Merged
Changes from all commits
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
46 changes: 38 additions & 8 deletions apps/proxy-auth/src/app/element.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,54 @@ window['initVerification'] = (config: any) => {
if (document.getElementById('proxyContainer') && config?.type !== 'user-management') {
document.getElementById('proxyContainer').append(sendOtpElement);
} else if (config?.type === 'user-management') {
// For user-management, element always stays in body
// This ensures it can always receive window events (showUserManagement, hideUserManagement)
// Master element always stays in body (hidden) for window events
sendOtpElement.style.display = 'none';
sendOtpElement.setAttribute('data-master', 'true');
document.body.append(sendOtpElement);

// Watch for container to control visibility
// Helper to create a fresh configured element for the container
const createContainerElement = () => {
const el = document.createElement('proxy-auth') as NgElement & WithProperties<SendOtpComponent>;
el.referenceId = config?.referenceId;
el.type = config?.type;
el.authToken = config?.authToken;
el.showCompanyDetails = config?.showCompanyDetails;
el.userToken = config?.userToken;
el.isRolePermission = config?.isRolePermission;
el.isPreview = config?.isPreview;
el.isLogin = config?.isLogin;
el.loginRedirectUrl = config?.loginRedirectUrl;
el.theme = config?.theme;
el.version = config?.version;
el.input_fields = config?.input_fields;
el.show_social_login_icons = config?.show_social_login_icons;
el.exclude_role_ids = config?.exclude_role_ids;
el.include_role_ids = config?.include_role_ids;
el.isHidden = config?.isHidden;
el.target = config?.target ?? '_self';
el.css = config.style;
el.successReturn = config.success;
el.failureReturn = config.failure;
el.otherData = omit(config, RESERVED_KEYS);
return el;
};

// Watch for container to appear/disappear
const containerCheck$ = interval(100).pipe(
map(() => document.getElementById('userProxyContainer')),
distinctUntilChanged()
);

containerCheck$.subscribe((targetContainer) => {
// Remove any existing container element (not the master)
const existingContainerElement = document.querySelector('proxy-auth:not([data-master])');
if (existingContainerElement) {
existingContainerElement.remove();
}

if (targetContainer) {
// Container exists - show the element
sendOtpElement.style.display = '';
} else {
// Container doesn't exist - hide the element
sendOtpElement.style.display = 'none';
// Container exists - create fresh element and append
targetContainer.append(createContainerElement());
}
});
} else if (document.getElementById('userProxyContainer')) {
Expand Down
Loading