@civic/auth 0.11.5-beta.2 → 0.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/dist/lib/oauth.js.map +1 -1
- package/dist/nextjs/routeHandler.js +2 -0
- package/dist/nextjs/routeHandler.js.map +1 -1
- package/dist/shared/version.d.ts +1 -1
- package/dist/shared/version.d.ts.map +1 -1
- package/dist/shared/version.js +1 -1
- package/dist/shared/version.js.map +1 -1
- package/dist/vanillajs/iframe/IframeManager.d.ts +1 -1
- package/dist/vanillajs/iframe/IframeManager.d.ts.map +1 -1
- package/dist/vanillajs/iframe/IframeManager.js +16 -2
- package/dist/vanillajs/iframe/IframeManager.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# 0.11.6 - Add iframe local-network-access permissions for localhost testing
|
|
2
|
+
- Added `local-network-access: *` to iframe permissions to allow local testing against remote oauth server
|
|
3
|
+
|
|
1
4
|
# 0.11.5
|
|
2
5
|
- Remote deprecated Oslo dependency
|
|
3
6
|
- Fix NextJS logout then login bug where existing state wasn't being correctly cleared on logout
|
package/dist/lib/oauth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../src/lib/oauth.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,mBAAmB,GAAG,CAAC,MAAc,EAAY,EAAE;IACvD,MAAM,kBAAkB,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC7C,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACpC,CAAC,CAAC,MAAM,CAAC;IAEX,MAAM,eAAe,GAAG,GAAG,kBAAkB,GAAG,CAAC;IAEjD,OAA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AM,0BAA0B,GAAG,CACjC,KAAa,EACqB,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC;AAE7E,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,EAC1B,aAAa,EACb,gBAAgB,GACjB,CAAC","sourcesContent":["import type {\n DisplayMode,\n Endpoints,\n OpenIdConfiguration,\n FrameworkType,\n} from \"@/types.js\";\nimport { v4 as uuid } from \"uuid\";\n\nconst getIssuerVariations = (issuer: string): string[] => {\n const issuerWithoutSlash = issuer.endsWith(\"/\")\n ? issuer.slice(0, issuer.length - 1)\n : issuer;\n\n const issuerWithSlash = `${issuerWithoutSlash}/`;\n\n return [issuerWithoutSlash, issuerWithSlash];\n};\n\nconst addSlashIfNeeded = (url: string): string =>\n url.endsWith(\"/\") ? url : `${url}/`;\n\nconst cache: { [key: string]: Endpoints } = {};\nconst getOauthEndpoints = async (oauthServer: string): Promise<Endpoints> => {\n if (cache[oauthServer]) {\n return cache[oauthServer];\n }\n const openIdConfigResponse = await fetch(\n `${addSlashIfNeeded(oauthServer)}.well-known/openid-configuration`,\n );\n const openIdConfig =\n (await openIdConfigResponse.json()) as OpenIdConfiguration;\n const endpoints: Endpoints = {\n jwks: openIdConfig.jwks_uri,\n auth: openIdConfig.authorization_endpoint,\n token: openIdConfig.token_endpoint,\n userinfo: openIdConfig.userinfo_endpoint,\n endsession: openIdConfig.end_session_endpoint,\n };\n\n cache[oauthServer] = endpoints;\n return endpoints;\n};\n\n/**\n * creates a state string for the OAuth2 flow, encoding the display mode too for future use\n * @param {DisplayMode} displayMode\n * @returns {string}\n */\ntype GenerateStateInput = {\n displayMode?: DisplayMode;\n iframeDisplayMode?: \"modal\" | \"embedded\";\n serverTokenExchange?: boolean;\n loginSuccessUrl?: string;\n framework?: FrameworkType;\n sdkVersion?: string;\n previousSessionStale?: boolean;\n};\nconst generateState = ({\n displayMode,\n iframeDisplayMode,\n serverTokenExchange,\n loginSuccessUrl,\n framework,\n sdkVersion,\n previousSessionStale,\n}: GenerateStateInput): string => {\n const jsonString = JSON.stringify({\n uuid: uuid(),\n ...(displayMode ? { displayMode } : {}),\n ...(iframeDisplayMode ? { iframeDisplayMode } : {}),\n ...(serverTokenExchange ? { serverTokenExchange } : {}),\n ...(loginSuccessUrl ? { loginSuccessUrl } : {}),\n ...(framework ? { framework } : {}),\n ...(sdkVersion ? { sdkVersion } : {}),\n ...(previousSessionStale ? { previousSessionStale } : {}),\n });\n return btoa(jsonString);\n};\n\n/**\n * parses the state string from the OAuth2 flow, decoding the display mode too\n * @param state\n * @param sessionDisplayMode\n * @returns { uuid: string, displayMode: DisplayMode }\n */\nconst displayModeFromState = (\n state: string,\n sessionDisplayMode: DisplayMode | undefined,\n): DisplayMode | undefined => {\n try {\n const jsonString = atob(state);\n return JSON.parse(jsonString).displayMode;\n } catch (e) {\n console.error(\"Failed to parse displayMode from state:\", state, e);\n return sessionDisplayMode;\n }\n};\n\nconst decodeState = (\n state: string,\n):\n | {\n serverTokenExchange?: boolean;\n loginSuccessUrl?: string;\n framework?: FrameworkType;\n sdkVersion?: string;\n iframeDisplayMode?: \"modal\" | \"embedded\";\n }\n | undefined => {\n try {\n const jsonString = atob(state);\n return JSON.parse(jsonString);\n } catch {\n console.error(\"Failed to parse state string to json:\", state);\n return undefined;\n }\n};\n\nconst serverTokenExchangeFromState = (state: string): boolean | undefined =>\n decodeState(state)?.serverTokenExchange;\n\nconst loginSuccessUrlFromState = (state: string | null): string | undefined =>\n state ? decodeState(state)?.loginSuccessUrl : undefined;\n\nconst iframeDisplayModeFromState = (\n state: string,\n): \"modal\" | \"embedded\" | undefined => decodeState(state)?.iframeDisplayMode;\n\nexport {\n serverTokenExchangeFromState,\n loginSuccessUrlFromState,\n getIssuerVariations,\n getOauthEndpoints,\n displayModeFromState,\n iframeDisplayModeFromState,\n generateState,\n addSlashIfNeeded,\n};\n"]}
|
|
@@ -221,6 +221,8 @@ export async function handleLogout(request, config) {
|
|
|
221
221
|
});
|
|
222
222
|
try {
|
|
223
223
|
await clearAuthCookies(resolvedConfigs);
|
|
224
|
+
// Revalidate current path to update authentication state in server components
|
|
225
|
+
await revalidateUrlPath(request.url);
|
|
224
226
|
}
|
|
225
227
|
catch (error) {
|
|
226
228
|
logger.error("[LOGOUT_HANDLER] Error clearing tokens:", error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routeHandler.js","sourceRoot":"","sources":["../../src/nextjs/routeHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA4B,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;AAE5C,MAAM,SAAU,SAAQ,KAAK;IAGT;IAFlB,YACE,OAAe,EACC,SAAiB,GAAG;QAEpC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,WAAM,GAAN,MAAM,CAAc;QAGpC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,qBAAqB,GAAG,CA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,KAAK,CACV,mDAAmD,EACnD,eAAe,CAChB,CAAC;IACF,IAAI,CAAC;QACH,MAAM,EAAE,SAAS,EAAE,GAAG,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAEhE,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,CAAC;QAEhD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CACjD,uBAAuB,CACxB;gBACC,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,GAAG,CAAC;YACR,OAAO,YAAY,CAAC,IAAI,CACtB,EAAE,KAAK,EAAE,mBAAmB,EAAE,EAC9B,EAAE,MAAM,EAAE,UAAU,EAAE,CACvB,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,CAAC;QAEvC,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,YAAY,CAAC,IAAI,CACtB,EAAE,KAAK,EAAE,uBAAuB,EAAE,EAClC,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { CivicAuth, type UrlDetectionRequest } from \"@civic/auth/server\";\nimport { LOGOUT_SUCCESS_TEXT } from \"@/constants.js\";\nimport { loggers } from \"@/lib/logger.js\";\nimport { displayModeFromState } from \"@/lib/oauth.js\";\nimport type { AuthConfig } from \"@/nextjs/config.js\";\nimport { resolveAuthConfig } from \"@/nextjs/config.js\";\nimport { clearAuthCookies, NextjsCookieStorage } from \"@/nextjs/cookies.js\";\nimport { CodeVerifier, UserStorage } from \"@/shared/lib/types.js\";\nimport { revalidatePath } from \"next/cache.js\";\nimport type { NextRequest } from \"next/server.js\";\nimport { NextResponse } from \"next/server.js\";\nimport { prependBasePath, redirectWithBasePath } from \"./utils.js\";\n\nconst logger = loggers.nextjs.handlers.auth;\n\nclass AuthError extends Error {\n constructor(\n message: string,\n public readonly status: number = 401,\n ) {\n super(message);\n this.name = \"AuthError\";\n }\n}\n\n/**\n * Helper to convert NextRequest to UrlDetectionRequest for framework-agnostic URL handling\n */\nconst toUrlDetectionRequest = (request: NextRequest): UrlDetectionRequest => ({\n url: request.url,\n headers: Object.fromEntries(request.headers.entries()),\n searchParams: {\n get: (name: string) => request.nextUrl.searchParams.get(name),\n },\n cookies: {\n get: (name: string) => request.cookies.get(name),\n },\n});\n\n/**\n * Helper to create CivicAuth instance for a request\n * Now handles appUrl detection for proxy environments\n */\nconst createCivicAuth = (request: NextRequest, config: AuthConfig) => {\n const resolvedConfig = resolveAuthConfig(config);\n const cookieStorage = new NextjsCookieStorage({\n ...resolvedConfig.cookies?.tokens,\n [UserStorage.USER]: resolvedConfig.cookies?.user,\n });\n\n // Convert to framework-agnostic request format\n const urlDetectionRequest = toUrlDetectionRequest(request);\n\n // Get appUrl from client (for proxy environments)\n const clientAppUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n\n // Use baseUrl from config, then client appUrl, then request origin\n // This matches the main branch priority: config > client > request\n const appUrl =\n resolvedConfig.baseUrl ||\n clientAppUrl ||\n new URL(urlDetectionRequest.url).origin;\n\n // Build absolute URLs using detected appUrl or request origin\n const absoluteCallbackUrl = resolvedConfig.callbackUrl.startsWith(\"http\")\n ? resolvedConfig.callbackUrl\n : CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n resolvedConfig.callbackUrl,\n appUrl,\n );\n const absoluteLogoutCallbackUrl = resolvedConfig.logoutCallbackUrl.startsWith(\n \"http\",\n )\n ? resolvedConfig.logoutCallbackUrl\n : CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n resolvedConfig.logoutCallbackUrl,\n appUrl,\n );\n\n const civicAuth = new CivicAuth(cookieStorage, {\n disableRefresh: resolvedConfig.disableRefresh,\n clientId: resolvedConfig.clientId,\n redirectUrl: absoluteCallbackUrl,\n oauthServer: resolvedConfig.oauthServer,\n postLogoutRedirectUrl: absoluteLogoutCallbackUrl,\n loginSuccessUrl: request.url,\n });\n\n return {\n civicAuth,\n cookieStorage,\n appUrl, // Return appUrl for use in other functions\n urlDetectionRequest, // Return for use in handlers\n };\n};\n\n/**\n * Login handler - backend OAuth login initiation endpoint\n * Uses CivicAuth.buildLoginUrl()\n */\nasync function handleLogin(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n try {\n const frontendState = request.nextUrl.searchParams.get(\"state\");\n\n // Store appUrl in cookie if provided as query parameter\n const appUrlFromQuery = request.nextUrl.searchParams.get(\"appUrl\");\n if (appUrlFromQuery) {\n const cookieStorage = new NextjsCookieStorage(\n resolvedConfigs.cookies?.tokens ?? {},\n );\n await cookieStorage.set(CodeVerifier.APP_URL, appUrlFromQuery);\n }\n\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n const url = await civicAuth.buildLoginUrl({\n state: frontendState || undefined,\n });\n\n logger.info(\"[LOGIN_HANDLER] Redirecting to OAuth login URL\", {\n loginUrl: url.toString(),\n });\n\n return NextResponse.redirect(url.toString());\n } catch (error) {\n logger.error(\"[LOGIN_HANDLER] Backend login error:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n \"/?error=login_failed\",\n appUrl,\n ),\n );\n }\n}\n\nasync function handleRefresh(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n try {\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n await civicAuth.refreshTokens();\n\n logger.info(\"[REFRESH_HANDLER] Tokens refreshed successfully\");\n\n return NextResponse.json({\n status: \"success\",\n message: \"Tokens refreshed\",\n });\n } catch (error) {\n logger.error(\"[REFRESH_HANDLER] Token refresh error:\", error);\n return NextResponse.json(\n { error: \"Token refresh failed\" },\n { status: 500 },\n );\n }\n}\n\nasync function handleCallback(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n const code = request.nextUrl.searchParams.get(\"code\");\n const state = request.nextUrl.searchParams.get(\"state\");\n const error = request.nextUrl.searchParams.get(\"error\");\n\n if (error) {\n logger.error(\"OAuth error in callback:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n \"/?error=oauth_error\",\n appUrl,\n ),\n );\n }\n\n if (!code || !state) throw new AuthError(\"Bad parameters\", 400);\n\n try {\n const { civicAuth, appUrl, urlDetectionRequest } = createCivicAuth(\n request,\n resolvedConfigs,\n );\n\n // Convert NextRequest to the format expected by handleCallback\n const handleCallbackRequest = {\n headers: Object.fromEntries(request.headers.entries()),\n url: request.url.toString(),\n };\n\n // Get loginSuccessUrl with proper baseUrl handling\n const loginSuccessUrl = CivicAuth.getLoginSuccessUrl(\n urlDetectionRequest,\n appUrl,\n );\n const frontendUrl =\n loginSuccessUrl || resolvedConfigs.loginSuccessUrl || \"/\";\n\n // Use CivicAuth's smart callback handler\n const result = await civicAuth.handleCallback(\n {\n code,\n state,\n req: handleCallbackRequest,\n },\n {\n // Pass the properly resolved frontendUrl\n frontendUrl: prependBasePath(frontendUrl, config.basePath || \"\"),\n },\n );\n if (result.redirectTo) {\n return redirectWithBasePath(\n config,\n CivicAuth.toAbsoluteUrl(urlDetectionRequest, result.redirectTo, appUrl),\n );\n }\n\n if (result.content) {\n // Handle both string content and object content\n if (typeof result.content === \"string\") {\n return new NextResponse(result.content, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/html\",\n },\n });\n } else {\n // Object content (JSON response)\n return NextResponse.json(result.content);\n }\n }\n\n // Fallback redirect\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(urlDetectionRequest, \"/\", appUrl),\n );\n } catch (error) {\n logger.error(\"[CALLBACK_HANDLER] OAuth callback error:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n \"/?error=callback_failed\",\n appUrl,\n ),\n );\n }\n}\n\nconst revalidateUrlPath = async (url: string) => {\n try {\n const path = new URL(url).pathname;\n revalidatePath(path);\n } catch (error) {\n logger.warn(\"Failed to revalidate path after logout:\", error);\n }\n};\n\nexport async function handleLogout(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n // Get framework-agnostic request for URL utilities\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n\n // Read the state from the query parameters\n const state = request.nextUrl.searchParams.get(\"state\");\n const clientLogoutRedirectUrl =\n request.nextUrl.searchParams.get(\"logoutRedirectUrl\");\n\n try {\n logger.info(\"[LOGOUT_HANDLER] Backend logout endpoint called\");\n\n // If client provided a logoutRedirectUrl, override the config\n let configToUse = resolvedConfigs;\n if (clientLogoutRedirectUrl) {\n configToUse = {\n ...resolvedConfigs,\n logoutCallbackUrl: clientLogoutRedirectUrl,\n };\n logger.info(\"[LOGOUT_HANDLER] Overriding logout callback URL\", {\n original: resolvedConfigs.logoutCallbackUrl,\n override: clientLogoutRedirectUrl,\n });\n }\n\n const { civicAuth } = createCivicAuth(request, configToUse);\n\n // Always redirect to OAuth logout (like main branch)\n // Don't validate session - even invalid local sessions should hit OAuth logout\n logger.info(\"[LOGOUT_HANDLER] Processing logout request\", {\n state: !!state,\n });\n\n // Always redirect to OAuth logout endpoint (like main branch)\n // Client-side iframe logic will handle completion and redirect appropriately\n const logoutUrl = await civicAuth.buildLogoutRedirectUrl({\n state: state || undefined,\n });\n\n try {\n await clearAuthCookies(resolvedConfigs);\n } catch (error) {\n logger.error(\"[LOGOUT_HANDLER] Error clearing tokens:\", error);\n }\n\n // Remove state parameter from logout URL to prevent it from appearing in frontend URL\n const cleanLogoutUrl = new URL(logoutUrl);\n cleanLogoutUrl.searchParams.delete(\"state\");\n\n logger.info(\"[LOGOUT_HANDLER] Redirecting to OAuth logout endpoint\", {\n logoutUrl: cleanLogoutUrl.toString(),\n });\n\n return NextResponse.redirect(cleanLogoutUrl.toString());\n } catch (error) {\n logger.error(\"[LOGOUT_HANDLER] Logout error:\", error);\n // If logout URL generation fails, clear tokens and redirect to home\n await clearAuthCookies(resolvedConfigs);\n\n const fallbackUrl =\n clientLogoutRedirectUrl || resolvedConfigs.logoutCallbackUrl;\n const finalFallbackUrl = CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n fallbackUrl,\n appUrl,\n );\n\n return NextResponse.redirect(finalFallbackUrl);\n }\n}\n\nexport async function handleLogoutCallback(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n try {\n logger.info(\n \"[LOGOUT_CALLBACK_HANDLER] Backend logout callback endpoint called\",\n );\n\n // Clear authentication cookies\n await clearAuthCookies(resolvedConfigs);\n\n // Get framework-agnostic request and create CivicAuth instance\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n // Get the state parameter for iframe detection\n const state = request.nextUrl.searchParams.get(\"state\");\n\n // If this is an iframe request, return HTML with logout success signal\n if (state && displayModeFromState(state, \"iframe\") === \"iframe\") {\n // For iframe mode, include the post-logout redirect URL in the HTML\n const postLogoutRedirectUrl =\n civicAuth.getPostLogoutRedirectUrl(urlDetectionRequest);\n const response = new NextResponse(\n `<html lang=\"en\"><span style=\"display:none\">${LOGOUT_SUCCESS_TEXT}<a href=\"${postLogoutRedirectUrl}\" rel=\"civic-auth-post-logout-redirect-url\"></a></span></html>`,\n );\n response.headers.set(\"Content-Type\", \"text/html; charset=utf-8\");\n logger.info(\n \"[LOGOUT_CALLBACK_HANDLER] Returning iframe logout success HTML\",\n { postLogoutRedirectUrl },\n );\n return response;\n }\n\n // For non-iframe requests, redirect to the logout callback URL or post-logout URL\n const redirectUrl = civicAuth.getPostLogoutRedirectUrl(urlDetectionRequest);\n logger.info(\n \"[LOGOUT_CALLBACK_HANDLER] Redirecting to logout callback URL\",\n {\n logoutCallbackUrl: resolvedConfigs.logoutCallbackUrl,\n redirectUrl,\n },\n );\n\n // Revalidate the redirect path to update authentication state in server components\n await revalidateUrlPath(redirectUrl);\n return redirectWithBasePath(config, redirectUrl);\n } catch (error) {\n logger.error(\"[LOGOUT_CALLBACK_HANDLER] Logout callback error:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return redirectWithBasePath(\n config,\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n resolvedConfigs.logoutCallbackUrl,\n appUrl,\n ),\n );\n }\n}\n\n/**\n * Creates an authentication handler for Next.js API routes\n *\n * Usage:\n * ```ts\n * // app/api/auth/[...civicauth]/route.ts\n * import { handler } from '@civic/auth/nextjs'\n * export const GET = handler({\n * // optional config overrides\n * })\n * export const POST = handler({\n * // optional config overrides\n * })\n * ```\n */\nexport const handler =\n (authConfig = {}) =>\n async (request: NextRequest): Promise<NextResponse> => {\n const config = resolveAuthConfig(authConfig);\n logger.debug(\"routeHandler: Auth route handler called\", config);\n try {\n const pathname = request.nextUrl.pathname;\n const pathSegments = pathname.split(\"/\");\n const lastSegment = pathSegments[pathSegments.length - 1];\n\n switch (lastSegment) {\n case \"challenge\":\n case \"login\":\n return await handleLogin(request, config);\n case \"callback\":\n return await handleCallback(request, config);\n case \"refresh\":\n return await handleRefresh(request, config);\n case \"logout\":\n return await handleLogout(request, config);\n case \"logoutcallback\":\n return await handleLogoutCallback(request, config);\n case \"user\":\n return await handleUser(request, config);\n default:\n throw new AuthError(`Invalid auth route: ${pathname}`, 404);\n }\n } catch (error) {\n logger.error(\"Auth handler error:\", error);\n\n const status = error instanceof AuthError ? error.status : 500;\n const message =\n error instanceof Error ? error.message : \"Authentication failed\";\n\n const response = NextResponse.json({ error: message }, { status });\n\n await clearAuthCookies(config);\n return response;\n }\n };\n\n/**\n * User endpoint - returns current user data as JSON\n * Uses CivicAuth.isLoggedIn() and getUser()\n */\nasync function handleUser(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n logger.debug(\n \"routeHandler: [USER_HANDLER] User endpoint called\",\n resolvedConfigs,\n );\n try {\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n const isLoggedIn = await civicAuth.isLoggedIn();\n\n if (!isLoggedIn) {\n const statusCode = request.nextUrl.searchParams.get(\n \"optimisticRehydration\",\n )\n ? 202\n : 401;\n return NextResponse.json(\n { error: \"Not authenticated\" },\n { status: statusCode },\n );\n }\n\n const user = await civicAuth.getUser();\n\n return NextResponse.json({ user });\n } catch (error) {\n logger.error(\"[USER_HANDLER] User endpoint error:\", error);\n return NextResponse.json(\n { error: \"Internal server error\" },\n { status: 500 },\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"routeHandler.js","sourceRoot":"","sources":["../../src/nextjs/routeHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA4B,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,E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IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,YAAY,CAAC,IAAI,CACtB,EAAE,KAAK,EAAE,uBAAuB,EAAE,EAClC,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { CivicAuth, type UrlDetectionRequest } from \"@civic/auth/server\";\nimport { LOGOUT_SUCCESS_TEXT } from \"@/constants.js\";\nimport { loggers } from \"@/lib/logger.js\";\nimport { displayModeFromState } from \"@/lib/oauth.js\";\nimport type { AuthConfig } from \"@/nextjs/config.js\";\nimport { resolveAuthConfig } from \"@/nextjs/config.js\";\nimport { clearAuthCookies, NextjsCookieStorage } from \"@/nextjs/cookies.js\";\nimport { CodeVerifier, UserStorage } from \"@/shared/lib/types.js\";\nimport { revalidatePath } from \"next/cache.js\";\nimport type { NextRequest } from \"next/server.js\";\nimport { NextResponse } from \"next/server.js\";\nimport { prependBasePath, redirectWithBasePath } from \"./utils.js\";\n\nconst logger = loggers.nextjs.handlers.auth;\n\nclass AuthError extends Error {\n constructor(\n message: string,\n public readonly status: number = 401,\n ) {\n super(message);\n this.name = \"AuthError\";\n }\n}\n\n/**\n * Helper to convert NextRequest to UrlDetectionRequest for framework-agnostic URL handling\n */\nconst toUrlDetectionRequest = (request: NextRequest): UrlDetectionRequest => ({\n url: request.url,\n headers: Object.fromEntries(request.headers.entries()),\n searchParams: {\n get: (name: string) => request.nextUrl.searchParams.get(name),\n },\n cookies: {\n get: (name: string) => request.cookies.get(name),\n },\n});\n\n/**\n * Helper to create CivicAuth instance for a request\n * Now handles appUrl detection for proxy environments\n */\nconst createCivicAuth = (request: NextRequest, config: AuthConfig) => {\n const resolvedConfig = resolveAuthConfig(config);\n const cookieStorage = new NextjsCookieStorage({\n ...resolvedConfig.cookies?.tokens,\n [UserStorage.USER]: resolvedConfig.cookies?.user,\n });\n\n // Convert to framework-agnostic request format\n const urlDetectionRequest = toUrlDetectionRequest(request);\n\n // Get appUrl from client (for proxy environments)\n const clientAppUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n\n // Use baseUrl from config, then client appUrl, then request origin\n // This matches the main branch priority: config > client > request\n const appUrl =\n resolvedConfig.baseUrl ||\n clientAppUrl ||\n new URL(urlDetectionRequest.url).origin;\n\n // Build absolute URLs using detected appUrl or request origin\n const absoluteCallbackUrl = resolvedConfig.callbackUrl.startsWith(\"http\")\n ? resolvedConfig.callbackUrl\n : CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n resolvedConfig.callbackUrl,\n appUrl,\n );\n const absoluteLogoutCallbackUrl = resolvedConfig.logoutCallbackUrl.startsWith(\n \"http\",\n )\n ? resolvedConfig.logoutCallbackUrl\n : CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n resolvedConfig.logoutCallbackUrl,\n appUrl,\n );\n\n const civicAuth = new CivicAuth(cookieStorage, {\n disableRefresh: resolvedConfig.disableRefresh,\n clientId: resolvedConfig.clientId,\n redirectUrl: absoluteCallbackUrl,\n oauthServer: resolvedConfig.oauthServer,\n postLogoutRedirectUrl: absoluteLogoutCallbackUrl,\n loginSuccessUrl: request.url,\n });\n\n return {\n civicAuth,\n cookieStorage,\n appUrl, // Return appUrl for use in other functions\n urlDetectionRequest, // Return for use in handlers\n };\n};\n\n/**\n * Login handler - backend OAuth login initiation endpoint\n * Uses CivicAuth.buildLoginUrl()\n */\nasync function handleLogin(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n try {\n const frontendState = request.nextUrl.searchParams.get(\"state\");\n\n // Store appUrl in cookie if provided as query parameter\n const appUrlFromQuery = request.nextUrl.searchParams.get(\"appUrl\");\n if (appUrlFromQuery) {\n const cookieStorage = new NextjsCookieStorage(\n resolvedConfigs.cookies?.tokens ?? {},\n );\n await cookieStorage.set(CodeVerifier.APP_URL, appUrlFromQuery);\n }\n\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n const url = await civicAuth.buildLoginUrl({\n state: frontendState || undefined,\n });\n\n logger.info(\"[LOGIN_HANDLER] Redirecting to OAuth login URL\", {\n loginUrl: url.toString(),\n });\n\n return NextResponse.redirect(url.toString());\n } catch (error) {\n logger.error(\"[LOGIN_HANDLER] Backend login error:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n \"/?error=login_failed\",\n appUrl,\n ),\n );\n }\n}\n\nasync function handleRefresh(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n try {\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n await civicAuth.refreshTokens();\n\n logger.info(\"[REFRESH_HANDLER] Tokens refreshed successfully\");\n\n return NextResponse.json({\n status: \"success\",\n message: \"Tokens refreshed\",\n });\n } catch (error) {\n logger.error(\"[REFRESH_HANDLER] Token refresh error:\", error);\n return NextResponse.json(\n { error: \"Token refresh failed\" },\n { status: 500 },\n );\n }\n}\n\nasync function handleCallback(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n const code = request.nextUrl.searchParams.get(\"code\");\n const state = request.nextUrl.searchParams.get(\"state\");\n const error = request.nextUrl.searchParams.get(\"error\");\n\n if (error) {\n logger.error(\"OAuth error in callback:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n \"/?error=oauth_error\",\n appUrl,\n ),\n );\n }\n\n if (!code || !state) throw new AuthError(\"Bad parameters\", 400);\n\n try {\n const { civicAuth, appUrl, urlDetectionRequest } = createCivicAuth(\n request,\n resolvedConfigs,\n );\n\n // Convert NextRequest to the format expected by handleCallback\n const handleCallbackRequest = {\n headers: Object.fromEntries(request.headers.entries()),\n url: request.url.toString(),\n };\n\n // Get loginSuccessUrl with proper baseUrl handling\n const loginSuccessUrl = CivicAuth.getLoginSuccessUrl(\n urlDetectionRequest,\n appUrl,\n );\n const frontendUrl =\n loginSuccessUrl || resolvedConfigs.loginSuccessUrl || \"/\";\n\n // Use CivicAuth's smart callback handler\n const result = await civicAuth.handleCallback(\n {\n code,\n state,\n req: handleCallbackRequest,\n },\n {\n // Pass the properly resolved frontendUrl\n frontendUrl: prependBasePath(frontendUrl, config.basePath || \"\"),\n },\n );\n if (result.redirectTo) {\n return redirectWithBasePath(\n config,\n CivicAuth.toAbsoluteUrl(urlDetectionRequest, result.redirectTo, appUrl),\n );\n }\n\n if (result.content) {\n // Handle both string content and object content\n if (typeof result.content === \"string\") {\n return new NextResponse(result.content, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/html\",\n },\n });\n } else {\n // Object content (JSON response)\n return NextResponse.json(result.content);\n }\n }\n\n // Fallback redirect\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(urlDetectionRequest, \"/\", appUrl),\n );\n } catch (error) {\n logger.error(\"[CALLBACK_HANDLER] OAuth callback error:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return NextResponse.redirect(\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n \"/?error=callback_failed\",\n appUrl,\n ),\n );\n }\n}\n\nconst revalidateUrlPath = async (url: string) => {\n try {\n const path = new URL(url).pathname;\n revalidatePath(path);\n } catch (error) {\n logger.warn(\"Failed to revalidate path after logout:\", error);\n }\n};\n\nexport async function handleLogout(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n // Get framework-agnostic request for URL utilities\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n\n // Read the state from the query parameters\n const state = request.nextUrl.searchParams.get(\"state\");\n const clientLogoutRedirectUrl =\n request.nextUrl.searchParams.get(\"logoutRedirectUrl\");\n\n try {\n logger.info(\"[LOGOUT_HANDLER] Backend logout endpoint called\");\n\n // If client provided a logoutRedirectUrl, override the config\n let configToUse = resolvedConfigs;\n if (clientLogoutRedirectUrl) {\n configToUse = {\n ...resolvedConfigs,\n logoutCallbackUrl: clientLogoutRedirectUrl,\n };\n logger.info(\"[LOGOUT_HANDLER] Overriding logout callback URL\", {\n original: resolvedConfigs.logoutCallbackUrl,\n override: clientLogoutRedirectUrl,\n });\n }\n\n const { civicAuth } = createCivicAuth(request, configToUse);\n\n // Always redirect to OAuth logout (like main branch)\n // Don't validate session - even invalid local sessions should hit OAuth logout\n logger.info(\"[LOGOUT_HANDLER] Processing logout request\", {\n state: !!state,\n });\n\n // Always redirect to OAuth logout endpoint (like main branch)\n // Client-side iframe logic will handle completion and redirect appropriately\n const logoutUrl = await civicAuth.buildLogoutRedirectUrl({\n state: state || undefined,\n });\n\n try {\n await clearAuthCookies(resolvedConfigs);\n\n // Revalidate current path to update authentication state in server components\n await revalidateUrlPath(request.url);\n } catch (error) {\n logger.error(\"[LOGOUT_HANDLER] Error clearing tokens:\", error);\n }\n\n // Remove state parameter from logout URL to prevent it from appearing in frontend URL\n const cleanLogoutUrl = new URL(logoutUrl);\n cleanLogoutUrl.searchParams.delete(\"state\");\n\n logger.info(\"[LOGOUT_HANDLER] Redirecting to OAuth logout endpoint\", {\n logoutUrl: cleanLogoutUrl.toString(),\n });\n\n return NextResponse.redirect(cleanLogoutUrl.toString());\n } catch (error) {\n logger.error(\"[LOGOUT_HANDLER] Logout error:\", error);\n // If logout URL generation fails, clear tokens and redirect to home\n await clearAuthCookies(resolvedConfigs);\n\n const fallbackUrl =\n clientLogoutRedirectUrl || resolvedConfigs.logoutCallbackUrl;\n const finalFallbackUrl = CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n fallbackUrl,\n appUrl,\n );\n\n return NextResponse.redirect(finalFallbackUrl);\n }\n}\n\nexport async function handleLogoutCallback(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n\n try {\n logger.info(\n \"[LOGOUT_CALLBACK_HANDLER] Backend logout callback endpoint called\",\n );\n\n // Clear authentication cookies\n await clearAuthCookies(resolvedConfigs);\n\n // Get framework-agnostic request and create CivicAuth instance\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n // Get the state parameter for iframe detection\n const state = request.nextUrl.searchParams.get(\"state\");\n\n // If this is an iframe request, return HTML with logout success signal\n if (state && displayModeFromState(state, \"iframe\") === \"iframe\") {\n // For iframe mode, include the post-logout redirect URL in the HTML\n const postLogoutRedirectUrl =\n civicAuth.getPostLogoutRedirectUrl(urlDetectionRequest);\n const response = new NextResponse(\n `<html lang=\"en\"><span style=\"display:none\">${LOGOUT_SUCCESS_TEXT}<a href=\"${postLogoutRedirectUrl}\" rel=\"civic-auth-post-logout-redirect-url\"></a></span></html>`,\n );\n response.headers.set(\"Content-Type\", \"text/html; charset=utf-8\");\n logger.info(\n \"[LOGOUT_CALLBACK_HANDLER] Returning iframe logout success HTML\",\n { postLogoutRedirectUrl },\n );\n return response;\n }\n\n // For non-iframe requests, redirect to the logout callback URL or post-logout URL\n const redirectUrl = civicAuth.getPostLogoutRedirectUrl(urlDetectionRequest);\n logger.info(\n \"[LOGOUT_CALLBACK_HANDLER] Redirecting to logout callback URL\",\n {\n logoutCallbackUrl: resolvedConfigs.logoutCallbackUrl,\n redirectUrl,\n },\n );\n\n // Revalidate the redirect path to update authentication state in server components\n await revalidateUrlPath(redirectUrl);\n return redirectWithBasePath(config, redirectUrl);\n } catch (error) {\n logger.error(\"[LOGOUT_CALLBACK_HANDLER] Logout callback error:\", error);\n const urlDetectionRequest = toUrlDetectionRequest(request);\n const appUrl = CivicAuth.getAppUrl(urlDetectionRequest);\n return redirectWithBasePath(\n config,\n CivicAuth.toAbsoluteUrl(\n urlDetectionRequest,\n resolvedConfigs.logoutCallbackUrl,\n appUrl,\n ),\n );\n }\n}\n\n/**\n * Creates an authentication handler for Next.js API routes\n *\n * Usage:\n * ```ts\n * // app/api/auth/[...civicauth]/route.ts\n * import { handler } from '@civic/auth/nextjs'\n * export const GET = handler({\n * // optional config overrides\n * })\n * export const POST = handler({\n * // optional config overrides\n * })\n * ```\n */\nexport const handler =\n (authConfig = {}) =>\n async (request: NextRequest): Promise<NextResponse> => {\n const config = resolveAuthConfig(authConfig);\n logger.debug(\"routeHandler: Auth route handler called\", config);\n try {\n const pathname = request.nextUrl.pathname;\n const pathSegments = pathname.split(\"/\");\n const lastSegment = pathSegments[pathSegments.length - 1];\n\n switch (lastSegment) {\n case \"challenge\":\n case \"login\":\n return await handleLogin(request, config);\n case \"callback\":\n return await handleCallback(request, config);\n case \"refresh\":\n return await handleRefresh(request, config);\n case \"logout\":\n return await handleLogout(request, config);\n case \"logoutcallback\":\n return await handleLogoutCallback(request, config);\n case \"user\":\n return await handleUser(request, config);\n default:\n throw new AuthError(`Invalid auth route: ${pathname}`, 404);\n }\n } catch (error) {\n logger.error(\"Auth handler error:\", error);\n\n const status = error instanceof AuthError ? error.status : 500;\n const message =\n error instanceof Error ? error.message : \"Authentication failed\";\n\n const response = NextResponse.json({ error: message }, { status });\n\n await clearAuthCookies(config);\n return response;\n }\n };\n\n/**\n * User endpoint - returns current user data as JSON\n * Uses CivicAuth.isLoggedIn() and getUser()\n */\nasync function handleUser(\n request: NextRequest,\n config: AuthConfig,\n): Promise<NextResponse> {\n const resolvedConfigs = resolveAuthConfig(config);\n logger.debug(\n \"routeHandler: [USER_HANDLER] User endpoint called\",\n resolvedConfigs,\n );\n try {\n const { civicAuth } = createCivicAuth(request, resolvedConfigs);\n\n const isLoggedIn = await civicAuth.isLoggedIn();\n\n if (!isLoggedIn) {\n const statusCode = request.nextUrl.searchParams.get(\n \"optimisticRehydration\",\n )\n ? 202\n : 401;\n return NextResponse.json(\n { error: \"Not authenticated\" },\n { status: statusCode },\n );\n }\n\n const user = await civicAuth.getUser();\n\n return NextResponse.json({ user });\n } catch (error) {\n logger.error(\"[USER_HANDLER] User endpoint error:\", error);\n return NextResponse.json(\n { error: \"Internal server error\" },\n { status: 500 },\n );\n }\n}\n"]}
|
package/dist/shared/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "@civic/auth:0.11.
|
|
1
|
+
export declare const VERSION = "@civic/auth:0.11.6";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,uBAAuB,CAAC"}
|
package/dist/shared/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,oBAAoB,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.11.6\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeManager.d.ts","sourceRoot":"","sources":["../../../src/vanillajs/iframe/IframeManager.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,YAAY;IAC3B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AAI,IAAI;CAgDhD"}
|
|
@@ -271,7 +271,7 @@ export class IframeManager {
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
/**
|
|
274
|
-
* Sets iframe attributes to prevent scrollbars
|
|
274
|
+
* Sets iframe attributes to prevent scrollbars and enable local network access
|
|
275
275
|
*/
|
|
276
276
|
setIframeAttributes() {
|
|
277
277
|
if (!this.iframe)
|
|
@@ -279,7 +279,21 @@ export class IframeManager {
|
|
|
279
279
|
this.iframe.setAttribute("scrolling", "no");
|
|
280
280
|
this.iframe.setAttribute("frameborder", "0");
|
|
281
281
|
this.iframe.setAttribute("seamless", "seamless");
|
|
282
|
-
|
|
282
|
+
// Include local-network-access permission to allow OAuth redirects to localhost in Chrome 142+
|
|
283
|
+
// The wildcard (*) allows all origins that load in the iframe (including during SSO redirects)
|
|
284
|
+
// to make local network requests when redirecting back to localhost callback URLs.
|
|
285
|
+
//
|
|
286
|
+
// Security Note: The wildcard is necessary because the iframe navigates through multiple origins
|
|
287
|
+
// during OAuth/SSO flows (auth.civic.com → IdP → auth.civic.com → localhost). Third-party IdPs
|
|
288
|
+
// (Google, Microsoft, Apple, custom OIDC) cannot be enumerated ahead of time. This is explicitly
|
|
289
|
+
// recommended by Chrome for SSO scenarios. Security is maintained through:
|
|
290
|
+
// - OAuth state validation preventing redirect hijacking
|
|
291
|
+
// - Server-side redirect_uri whitelist validation
|
|
292
|
+
// - HTTPS requirement preventing MitM attacks
|
|
293
|
+
// - Limited permission lifetime (only while iframe exists)
|
|
294
|
+
//
|
|
295
|
+
// See: https://developer.chrome.com/blog/private-network-access-preflight
|
|
296
|
+
this.iframe.setAttribute("allow", "camera; screen-wake-lock; publickey-credentials-get *; publickey-credentials-create *; local-network-access *");
|
|
283
297
|
this.iframe.setAttribute("allowFullScreen", "true");
|
|
284
298
|
// Add additional CSS to prevent scrollbars
|
|
285
299
|
this.iframe.style.cssText +=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeManager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C,EAAE,GAAG,8BAA8B,CAAC;YAC5C,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG;;;;;;;;;;;;yBAYL,aAAa,CAAC,aAAa;;;OAG7C,CAAC;YAEF,gCAAgC;YAChC,aAAa,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;YAC1C,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAEnC,yBAAyB;YACzB,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;oBACvB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAC1C,CAAC;gBACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACvD,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,qBAAqB;YAE9B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACzD,CAAC;IACH,CAAC","sourcesContent":["import { CivicIframeResizer } from \"./IframeResizer.js\";\nimport {\n createIframeShimmerLoader,\n createCenteredLoadingSpinner,\n createCloseButton,\n} from \"../ui/LoadingComponents.js\";\nimport { createLogger } from \"../utils/logger.js\";\nimport { WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT } from \"@/constants.js\";\n\nexport interface IframeConfig {\n container: HTMLElement;\n displayMode: \"embedded\" | \"modal\";\n width?: string;\n height?: string;\n iframeId?: string;\n onClose?: () => void;\n}\n\n/**\n * IframeManager - Manages iframe visual presentation and DOM lifecycle\n * Handles styling, positioning, UI components, and iframe element creation/cleanup\n */\nexport class IframeManager {\n // Constants for styling and configuration\n private static readonly MODAL_Z_INDEX = \"1050\";\n private static readonly MODAL_WIDTH = \"22rem\"; // 360px\n private static readonly MODAL_BACKDROP_COLOR = \"rgba(17, 24, 39, 0.5)\";\n private static readonly MODAL_BACKDROP_BLUR = \"blur(4px)\";\n private static readonly BORDER_RADIUS = \"26px\";\n private static readonly TRANSITION_DURATION = \"250ms\";\n private static readonly MODAL_MIN_HEIGHT = \"26px\";\n private static readonly EMBEDDED_MIN_HEIGHT = \"225px\";\n private static readonly IFRAME_READY_DELAY = 100; // ms\n\n private iframe: HTMLIFrameElement | null = null;\n private container: HTMLElement;\n private resizer: CivicIframeResizer | null = null;\n private displayMode: \"embedded\" | \"modal\";\n private keydownHandler?: (event: KeyboardEvent) => void;\n private clickHandler?: (event: MouseEvent) => void;\n private iframeId: string;\n private onClose?: () => void;\n private shimmerLoader: HTMLElement | null = null;\n private closeButton: HTMLButtonElement | null = null;\n private isIframeLoaded = false;\n private iframeReadyMessageListener?: (event: MessageEvent) => void;\n private logger: ReturnType<typeof createLogger>;\n // Store references to wrapper elements for styling control\n private contentWrapper: HTMLElement | null = null;\n private iframeWrapper: HTMLElement | null = null;\n // Preloading support\n private isPreloaded = false;\n private preloadUrl: string | null = null;\n public static browserCorsFailsSilentlyUrl: string | null = null;\n\n public static handleBrowserCorsFailsSilently(url: string): void {\n // Store the URL that caused CORS failure for later reference\n IframeManager.browserCorsFailsSilentlyUrl = url;\n }\n\n constructor(config: IframeConfig) {\n // we aren't going to render the iframe if the browser fails silently as we're redirecting\n\n this.container = config.container;\n this.displayMode = config.displayMode;\n this.iframeId = config.iframeId || \"civic-auth-iframe\";\n this.onClose = config.onClose;\n this.logger = createLogger(\"iframe\");\n this.initializeContainer(config);\n this.setupKeyboardHandlers();\n }\n\n private initializeContainer(config: IframeConfig): void {\n if (this.displayMode === \"modal\") {\n this.applyModalStyles();\n return;\n }\n\n // Embedded mode\n this.container.style.position = \"relative\";\n this.container.style.width = config.width || \"auto\";\n this.container.style.height = config.height || \"auto\";\n this.container.style.backgroundColor = \"transparent\";\n this.container.style.background = \"transparent\";\n this.container.style.borderRadius = IframeManager.BORDER_RADIUS;\n this.container.style.overflow = \"hidden\";\n this.container.style.transition = \"all 0.5s ease-in-out\";\n }\n\n /**\n * Applies modal backdrop styles to create a full-screen overlay\n * Uses !important to override any existing styles\n */\n private applyModalStyles(): void {\n const modalStyles = {\n position: \"fixed\",\n left: \"0\",\n top: \"0\",\n width: \"100vw\",\n height: \"100vh\",\n \"z-index\": IframeManager.MODAL_Z_INDEX,\n display: \"flex\",\n \"align-items\": \"center\",\n \"justify-content\": \"center\",\n \"background-color\": IframeManager.MODAL_BACKDROP_COLOR,\n \"backdrop-filter\": IframeManager.MODAL_BACKDROP_BLUR,\n opacity: \"1\",\n transition: `opacity ${IframeManager.TRANSITION_DURATION} ease`,\n // Reset any conflicting styles that might prevent modal from working\n margin: \"0\",\n padding: \"0\",\n border: \"none\",\n \"border-radius\": \"0\",\n \"min-height\": \"100vh\",\n };\n\n Object.entries(modalStyles).forEach(([property, value]) => {\n this.container.style.setProperty(property, value, \"important\");\n });\n }\n\n private setupKeyboardHandlers(): void {\n if (this.displayMode === \"modal\") {\n this.keydownHandler = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n this.onClose?.();\n }\n };\n window.addEventListener(\"keydown\", this.keydownHandler);\n }\n }\n\n /**\n * Preloads an iframe in the background for instant display later\n * The iframe is created but kept completely hidden and non-interactable\n */\n public preloadIframe(url: string): HTMLIFrameElement {\n this.logger.debug(\"Preloading iframe in background\", { url });\n\n // Clean up any existing iframe content, but preserve container styles for modal mode\n this.cleanupIframeOnly();\n\n // Create new iframe for preloading\n this.iframe = document.createElement(\"iframe\");\n this.iframe.id = this.iframeId;\n this.iframe.src = url;\n this.iframe.setAttribute(\"data-testid\", \"civic-auth-iframe-with-resizer\");\n\n // Apply base iframe styles but keep it completely hidden for preloading\n this.applyIframeStyles();\n\n // Make iframe completely invisible and non-interactable during preload\n this.iframe.style.display = \"none\";\n this.iframe.style.visibility = \"hidden\";\n this.iframe.style.pointerEvents = \"none\";\n this.iframe.style.position = \"absolute\";\n this.iframe.style.left = \"-9999px\";\n this.iframe.style.top = \"-9999px\";\n\n // Add attributes that prevent scrollbars\n this.setIframeAttributes();\n\n // Add CSS to prevent scrollbars\n this.addScrollbarHidingStyles();\n\n // Set up message listener for iframe ready events (more reliable than onload)\n this.setupIframeMessageListener();\n\n // Set up iframe onload handler\n this.setupIframeOnloadHandler();\n\n // For preloading, we need to add the iframe to the DOM but keep it hidden\n // Create a minimal container structure without showing it\n if (this.displayMode === \"modal\") {\n this.setupModalIframeForPreload();\n } else {\n this.setupEmbeddedIframeForPreload();\n }\n\n // Initialize resizer - this will handle all the message-based resizing\n this.resizer = new CivicIframeResizer(this.iframe, this.container, () =>\n this.isShimmerActive(),\n );\n\n // Mark as preloaded\n this.isPreloaded = true;\n this.preloadUrl = url;\n\n // Keep the container hidden during preload\n this.hide();\n\n this.logger.debug(\"Iframe preloaded successfully\", { url });\n return this.iframe;\n }\n\n public createIframe(url: string): HTMLIFrameElement {\n // If we have a preloaded iframe, show it instantly (even if URL differs)\n // URLs may differ due to fresh PKCE challenges and other dynamic parameters\n if (this.isPreloaded && this.iframe) {\n this.logger.debug(\"Using preloaded iframe for instant display\", {\n preloadedUrl: this.preloadUrl,\n requestedUrl: url,\n urlsMatch: this.preloadUrl === url,\n });\n\n // Don't change iframe.src for preloaded iframes - use them as-is to avoid reload\n // The preloaded authentication flow will work perfectly without URL changes\n this.logger.debug(\"Using preloaded iframe without reload\", {\n preloadedUrl: this.preloadUrl,\n requestedUrl: url,\n action: \"skipping_url_change_to_prevent_reload\",\n });\n\n // Make the preloaded iframe visible and interactable\n this.iframe.style.display = \"block\";\n this.iframe.style.visibility = \"visible\";\n this.iframe.style.pointerEvents = \"auto\";\n this.iframe.style.position = \"relative\";\n this.iframe.style.left = \"0\";\n this.iframe.style.top = \"0\";\n\n // Show the wrappers that were hidden during preload\n if (this.displayMode === \"modal\") {\n if (this.contentWrapper) {\n this.contentWrapper.style.display = \"block\";\n // Apply modal visual styling that was skipped during preload\n this.applyModalVisualStyling();\n\n // Set up modal behaviors (backdrop click, etc.)\n this.setupModalBehaviors();\n }\n } else {\n if (this.iframeWrapper) {\n this.iframeWrapper.style.display = \"flex\";\n // Apply wrapper styling that was skipped during preload\n this.applyIframeWrapperStyling();\n // Add loading spinner if content isn't loaded yet\n if (!this.isIframeLoaded) {\n this.showLoadingSpinner();\n }\n }\n }\n\n // Show the container\n this.show();\n\n // Reset preload state since we're now showing the iframe\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n return this.iframe;\n }\n\n // Clean up any existing iframe content, but preserve container styles for modal mode\n this.cleanupIframeOnly();\n\n // Create new iframe\n this.iframe = document.createElement(\"iframe\");\n this.iframe.id = this.iframeId;\n this.iframe.src = url;\n this.iframe.setAttribute(\"data-testid\", \"civic-auth-iframe-with-resizer\");\n\n // Apply iframe styles\n this.applyIframeStyles();\n\n // Add attributes that prevent scrollbars\n this.setIframeAttributes();\n\n // Add CSS to prevent scrollbars\n this.addScrollbarHidingStyles();\n\n // Set up message listener for iframe ready events (more reliable than onload)\n this.setupIframeMessageListener();\n\n // Set up iframe onload handler\n this.setupIframeOnloadHandler();\n\n if (this.displayMode === \"modal\") {\n this.setupModalIframe();\n } else {\n this.setupEmbeddedIframe();\n }\n\n // Initialize resizer - this will handle all the message-based resizing\n this.resizer = new CivicIframeResizer(this.iframe, this.container, () =>\n this.isShimmerActive(),\n );\n\n // Show the iframe container for non-preloaded iframes\n // Note: For preloaded iframes, show() is called earlier in the createIframe method\n // For modal mode, setupModalIframe() handles visibility, but embedded mode needs explicit show()\n if (this.displayMode === \"embedded\") {\n this.show();\n }\n\n return this.iframe;\n }\n\n /**\n * Applies base styles to the iframe element\n */\n private applyIframeStyles(): void {\n if (!this.iframe) return;\n\n const baseStyles = {\n border: \"none\",\n display: \"block\",\n pointerEvents: \"auto\",\n width: \"100%\",\n minWidth: \"100%\",\n overflow: \"hidden\",\n overflowX: \"hidden\",\n overflowY: \"hidden\",\n opacity: \"0\",\n transition: `opacity ${IframeManager.TRANSITION_DURATION} ease, height ${IframeManager.TRANSITION_DURATION} ease`,\n };\n\n Object.entries(baseStyles).forEach(([property, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required to handle dynamic CSS property assignment since CSSStyleDeclaration type doesn't fully capture all possible properties\n this.iframe!.style[property as any] = value;\n });\n\n // Set initial height based on display mode\n if (this.displayMode === \"modal\") {\n this.iframe!.style.height = IframeManager.MODAL_MIN_HEIGHT;\n this.iframe!.style.minHeight = IframeManager.MODAL_MIN_HEIGHT;\n } else {\n this.iframe!.style.height = \"auto\";\n this.iframe!.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT; // Embedded mode minimum\n }\n }\n\n /**\n * Sets iframe attributes to prevent scrollbars\n */\n private setIframeAttributes(): void {\n if (!this.iframe) return;\n\n this.iframe.setAttribute(\"scrolling\", \"no\");\n this.iframe.setAttribute(\"frameborder\", \"0\");\n this.iframe.setAttribute(\"seamless\", \"seamless\");\n this.iframe.setAttribute(\n \"allow\",\n \"camera; screen-wake-lock; publickey-credentials-get *; publickey-credentials-create *\",\n );\n this.iframe.setAttribute(\"allowFullScreen\", \"true\");\n\n // Add additional CSS to prevent scrollbars\n this.iframe.style.cssText +=\n \"; -ms-overflow-style: none; scrollbar-width: none;\";\n }\n\n /**\n * Adds CSS styles to hide scrollbars across different browsers\n */\n private addScrollbarHidingStyles(): void {\n const iframeStyle = document.createElement(\"style\");\n iframeStyle.textContent = `\n iframe[id=\"${this.iframeId}\"] {\n -webkit-overflow-scrolling: touch !important;\n }\n iframe[id=\"${this.iframeId}\"]::webkit-scrollbar {\n display: none !important;\n width: 0 !important;\n height: 0 !important;\n }\n `;\n document.head.appendChild(iframeStyle);\n }\n\n /**\n * Sets up the message listener for iframe ready events\n */\n private setupIframeMessageListener(): void {\n this.iframeReadyMessageListener = (event: MessageEvent) => {\n try {\n // Only handle messages from our iframe\n if (\n !this.iframe?.contentWindow ||\n event.source !== this.iframe.contentWindow\n ) {\n return;\n }\n\n const message = event.data;\n\n // Handle ready message from iframe resizer\n if (message.type === \"civic-iframe-ready\") {\n this.logger.debug(\"Iframe content is ready - hiding shimmer loader\");\n // wait a bit to ensure any initial loading is complete\n // to give the login-app time to send any post message signals\n setTimeout(() => {\n // Mark iframe as loaded FIRST to disable shimmer blocking\n this.markIframeAsLoaded();\n\n // Replay any blocked resize messages now that shimmer is inactive\n this.resizer?.replayBlockedMessages();\n this.resizer?.resize();\n }, WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT);\n }\n } catch (error) {\n this.logger.debug(\"Error processing iframe ready message:\", error);\n }\n };\n\n window.addEventListener(\"message\", this.iframeReadyMessageListener);\n }\n\n /**\n * Sets up the iframe onload handler with CSS injection\n */\n private setupIframeOnloadHandler(): void {\n if (!this.iframe) return;\n\n this.iframe.onload = () => {\n // Use a small delay to allow ready message to arrive first\n setTimeout(() => {\n if (!this.isIframeLoaded) {\n this.logger.debug(\n \"Iframe onload fired - hiding shimmer loader (fallback)\",\n );\n this.markIframeAsLoaded();\n }\n }, IframeManager.IFRAME_READY_DELAY);\n\n try {\n const iframeDoc =\n this.iframe?.contentDocument || this.iframe?.contentWindow?.document;\n if (iframeDoc && iframeDoc.head) {\n const style = iframeDoc.createElement(\"style\");\n style.textContent = `\n html, body {\n overflow: hidden !important;\n overflow-x: hidden !important;\n overflow-y: hidden !important;\n -ms-overflow-style: none !important;\n scrollbar-width: none !important;\n margin: 0 !important;\n padding: 0 !important;\n }\n body::-webkit-scrollbar {\n display: none !important;\n }\n * {\n box-sizing: border-box !important;\n }\n `;\n iframeDoc.head.appendChild(style);\n }\n } catch (error) {\n this.logger.debug(\n \"Could not inject CSS into iframe (likely cross-origin):\",\n error,\n );\n }\n };\n }\n\n /**\n * Sets up the iframe for modal display mode during preload\n * Creates the structure but keeps everything hidden\n */\n private setupModalIframeForPreload(): void {\n if (!this.iframe) return;\n\n // Create content wrapper for modal but keep it hidden\n this.contentWrapper = document.createElement(\"div\");\n this.contentWrapper.style.position = \"relative\";\n this.contentWrapper.style.overflow = \"hidden\";\n this.contentWrapper.style.width = IframeManager.MODAL_WIDTH;\n this.contentWrapper.style.display = \"none\"; // Keep hidden during preload\n\n // Create inner iframe wrapper\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = `all ${IframeManager.TRANSITION_DURATION} ease`;\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.MODAL_MIN_HEIGHT;\n\n // Add iframe to wrapper, then wrapper to content, then content to container\n this.iframeWrapper.appendChild(this.iframe);\n this.contentWrapper.appendChild(this.iframeWrapper);\n this.container.appendChild(this.contentWrapper);\n }\n\n /**\n * Sets up the iframe for embedded display mode during preload\n * Creates the structure but keeps everything hidden\n */\n private setupEmbeddedIframeForPreload(): void {\n if (!this.iframe) return;\n\n // Create wrapper but keep it hidden\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = \"all 0.5s ease-in-out\";\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT;\n this.iframeWrapper.style.backgroundColor = this.getBackgroundColor();\n this.iframeWrapper.style.display = \"none\"; // Keep hidden during preload\n this.iframeWrapper.style.alignItems = \"center\";\n this.iframeWrapper.style.justifyContent = \"center\";\n\n // Apply initial wrapper styling (border radius)\n this.applyIframeWrapperStyling();\n\n // Create a content wrapper for the iframe\n const iframeContentWrapper = document.createElement(\"div\");\n iframeContentWrapper.style.width = \"100%\";\n iframeContentWrapper.style.minWidth = \"100%\";\n iframeContentWrapper.style.alignItems = \"center\";\n iframeContentWrapper.style.justifyContent = \"center\";\n iframeContentWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n iframeContentWrapper.style.overflow = \"hidden\";\n iframeContentWrapper.style.opacity = \"1\"; // Already loaded during preload\n iframeContentWrapper.style.transition = \"opacity 0.5s ease-in-out\";\n\n // Add iframe to content wrapper\n iframeContentWrapper.appendChild(this.iframe);\n\n // Add content wrapper to main wrapper\n this.iframeWrapper.appendChild(iframeContentWrapper);\n\n // Store reference for later use\n this.contentWrapper = iframeContentWrapper;\n\n // Add wrapper to container\n this.container.appendChild(this.iframeWrapper);\n }\n\n /**\n * Sets up the iframe for modal display mode\n */\n private setupModalIframe(): void {\n if (!this.iframe) return;\n\n // Ensure modal is visible (in case it was hidden by cleanup)\n this.container.style.setProperty(\"display\", \"flex\", \"important\");\n\n // Create content wrapper for modal\n this.contentWrapper = document.createElement(\"div\");\n this.contentWrapper.style.position = \"relative\";\n this.contentWrapper.style.overflow = \"hidden\";\n this.contentWrapper.style.width = IframeManager.MODAL_WIDTH; // 360px like React version\n\n // Apply initial visual styling\n this.applyModalVisualStyling();\n\n // Create inner iframe wrapper to match React structure\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = `all ${IframeManager.TRANSITION_DURATION} ease`;\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.MODAL_MIN_HEIGHT; // Start small for modal mode\n\n // Apply initial wrapper styling\n this.applyIframeWrapperStyling();\n\n // Add shimmer loader for modal mode\n this.showShimmerLoader(this.iframeWrapper, \"white\");\n\n // Add iframe to wrapper, then wrapper to content, then content to container\n this.iframeWrapper.appendChild(this.iframe);\n this.contentWrapper.appendChild(this.iframeWrapper);\n this.container.appendChild(this.contentWrapper);\n\n this.setupModalBehaviors();\n }\n\n /**\n * Sets up modal-specific behaviors like click handlers and close button\n */\n private setupModalBehaviors(): void {\n if (!this.contentWrapper) return;\n\n // Stop propagation on content wrapper to prevent backdrop clicks\n this.contentWrapper.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n });\n\n // Add close button for modal mode (initially hidden if not loaded)\n if (this.onClose && !this.closeButton) {\n this.closeButton = createCloseButton(this.onClose);\n // Show close button immediately if iframe is already loaded, otherwise keep hidden\n this.closeButton.style.opacity = this.isIframeLoaded ? \"1\" : \"0\";\n this.contentWrapper.appendChild(this.closeButton);\n }\n\n // Add click-to-close functionality after content is added\n if (!this.clickHandler) {\n this.clickHandler = (e: MouseEvent) => {\n if (e.target === this.container) {\n // Only close if clicking the backdrop, not the iframe content\n this.onClose?.();\n }\n };\n this.container.addEventListener(\"click\", this.clickHandler);\n }\n }\n\n /**\n * Sets up the iframe for embedded display mode\n */\n private setupEmbeddedIframe(): void {\n if (!this.iframe) return;\n\n // Embedded mode - create wrapper with border radius and overflow hidden\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = \"all 0.5s ease-in-out\";\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT; // Embedded mode minimum\n this.iframeWrapper.style.backgroundColor = this.getBackgroundColor();\n this.iframeWrapper.style.display = \"flex\";\n this.iframeWrapper.style.alignItems = \"center\";\n this.iframeWrapper.style.justifyContent = \"center\";\n this.iframeWrapper.setAttribute(\"data-civic-wrapper\", \"true\");\n\n // Apply initial wrapper styling (border radius)\n this.applyIframeWrapperStyling();\n\n // Add centered loading spinner for embedded mode\n this.showLoadingSpinner();\n\n // Create a content wrapper for the iframe\n const iframeContentWrapper = document.createElement(\"div\");\n iframeContentWrapper.style.width = \"100%\";\n iframeContentWrapper.style.minWidth = \"100%\";\n iframeContentWrapper.style.alignItems = \"center\";\n iframeContentWrapper.style.justifyContent = \"center\";\n iframeContentWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n iframeContentWrapper.style.overflow = \"hidden\";\n iframeContentWrapper.style.opacity = \"0\";\n iframeContentWrapper.style.transition = \"opacity 0.5s ease-in-out\";\n\n // Add iframe to content wrapper\n iframeContentWrapper.appendChild(this.iframe);\n\n // Add content wrapper to main wrapper\n this.iframeWrapper.appendChild(iframeContentWrapper);\n\n // Store reference for later use\n this.contentWrapper = iframeContentWrapper;\n\n // Add wrapper to container\n this.container.appendChild(this.iframeWrapper);\n }\n\n private showShimmerLoader(\n parentElement: HTMLElement,\n backgroundColor = \"white\",\n maxWidth?: string,\n ): void {\n if (!this.isIframeLoaded && !this.shimmerLoader) {\n this.shimmerLoader = createIframeShimmerLoader(backgroundColor, maxWidth);\n parentElement.appendChild(this.shimmerLoader);\n }\n }\n\n /**\n * Shows a centered loading spinner for embedded mode\n */\n private showLoadingSpinner(): void {\n if (!this.isIframeLoaded && !this.shimmerLoader && this.iframeWrapper) {\n this.shimmerLoader = createCenteredLoadingSpinner();\n this.iframeWrapper.appendChild(this.shimmerLoader);\n }\n }\n\n /**\n * Gets the background color based on the user's theme preference\n */\n private getBackgroundColor(): string {\n // Check if we're in a browser environment\n if (typeof window === \"undefined\") {\n return \"#8E949D\"; // Default gray when SSR\n }\n\n // Use media query to detect dark mode preference\n const isDarkMode =\n window.matchMedia &&\n window.matchMedia(\"(prefers-color-scheme: dark)\").matches;\n\n // Return appropriate background color - matching React constants\n return isDarkMode ? \"rgb(30, 41, 59)\" : \"white\";\n }\n\n private hideShimmerLoader(): void {\n if (this.shimmerLoader && this.shimmerLoader.parentNode) {\n // Store reference for cleanup\n const shimmerElement = this.shimmerLoader;\n\n // Clear reference immediately to allow resize operations\n this.shimmerLoader = null;\n\n // Add fade-out transition before removing\n shimmerElement.style.opacity = \"0\";\n shimmerElement.style.transition = `opacity ${IframeManager.TRANSITION_DURATION} ease`;\n\n // Remove after transition completes\n setTimeout(() => {\n if (shimmerElement && shimmerElement.parentNode) {\n shimmerElement.parentNode.removeChild(shimmerElement);\n }\n }, parseInt(IframeManager.TRANSITION_DURATION));\n }\n }\n\n private markIframeAsLoaded(): void {\n if (IframeManager.browserCorsFailsSilentlyUrl) {\n return;\n }\n if (!this.isIframeLoaded) {\n this.isIframeLoaded = true;\n this.hideShimmerLoader();\n this.updateWrapperForLoadedContent();\n }\n }\n\n private updateWrapperForLoadedContent(): void {\n // For embedded mode, fade in both the content wrapper and iframe\n if (this.displayMode === \"embedded\" && this.contentWrapper) {\n this.contentWrapper.style.opacity = \"1\";\n // Also make sure the iframe itself is visible\n if (this.iframe) {\n this.iframe.style.opacity = \"1\";\n }\n } else if (this.iframe) {\n // For modal mode, fade in the iframe directly\n this.iframe.style.opacity = \"1\";\n }\n\n // Show close button for modal mode when content is loaded\n if (this.displayMode === \"modal\" && this.closeButton) {\n this.closeButton.style.opacity = \"1\";\n }\n\n // Find the iframe wrapper and update its styles for loaded content\n const iframeWrapper = this.iframe?.parentElement;\n if (iframeWrapper) {\n // Remove minimum height constraints to allow natural sizing\n if (this.displayMode === \"modal\") {\n iframeWrapper.style.minHeight = \"auto\";\n } else {\n // For embedded mode, keep some minimum but allow natural growth\n iframeWrapper.style.minHeight = \"auto\";\n }\n\n // Add border radius transition for loaded state (matching React implementation)\n iframeWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n }\n }\n\n public hide(): void {\n if (this.displayMode === \"modal\") {\n // Hide immediately without transition\n this.container.style.transition = \"none\";\n this.container.style.opacity = \"0\";\n }\n this.container.style.display = \"none\";\n }\n\n public show(): void {\n if (this.displayMode === \"modal\") {\n // Show immediately, then fade in\n this.container.style.display = \"flex\";\n this.container.style.opacity = \"0\";\n this.container.style.transition = `opacity ${IframeManager.TRANSITION_DURATION} ease`;\n\n // Use setTimeout to ensure display change takes effect before opacity transition\n setTimeout(() => {\n this.container.style.opacity = \"1\";\n }, 10);\n } else {\n // For embedded mode, just show immediately\n this.container.style.display = \"block\";\n this.container.style.opacity = \"1\";\n\n // Fix: Ensure the iframe itself is also visible immediately for embedded mode\n // The iframe starts with opacity: 0 from applyIframeStyles, but embedded mode\n // should show the iframe immediately without waiting for loaded content\n if (this.iframe) {\n this.iframe.style.opacity = \"1\";\n }\n }\n }\n\n private cleanupIframeOnly(): void {\n if (this.resizer) {\n this.resizer.cleanup();\n this.resizer = null;\n }\n\n // Clean up shimmer loader\n this.hideShimmerLoader();\n\n // Clean up close button\n if (this.closeButton && this.closeButton.parentNode) {\n this.closeButton.parentNode.removeChild(this.closeButton);\n this.closeButton = null;\n }\n\n // Clean up message listener\n if (this.iframeReadyMessageListener) {\n window.removeEventListener(\"message\", this.iframeReadyMessageListener);\n this.iframeReadyMessageListener = undefined;\n }\n\n if (this.iframe && this.iframe.parentNode) {\n this.iframe.parentNode.removeChild(this.iframe);\n this.iframe = null;\n }\n\n // Reset loading state\n this.isIframeLoaded = false;\n\n // Reset preload state\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n // Clear wrapper references\n this.contentWrapper = null;\n this.iframeWrapper = null;\n\n // Clear container content but DON'T reset styles for modal mode\n this.container.innerHTML = \"\";\n }\n\n public cleanup(): void {\n if (this.resizer) {\n this.resizer.cleanup();\n this.resizer = null;\n }\n\n // Clean up shimmer loader\n this.hideShimmerLoader();\n\n // Clean up close button\n if (this.closeButton && this.closeButton.parentNode) {\n this.closeButton.parentNode.removeChild(this.closeButton);\n this.closeButton = null;\n }\n\n // Clean up message listener\n if (this.iframeReadyMessageListener) {\n window.removeEventListener(\"message\", this.iframeReadyMessageListener);\n this.iframeReadyMessageListener = undefined;\n }\n\n if (this.iframe && this.iframe.parentNode) {\n this.iframe.parentNode.removeChild(this.iframe);\n this.iframe = null;\n }\n\n // Reset loading state\n this.isIframeLoaded = false;\n\n // Reset preload state\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n // Remove keyboard event listener\n if (this.keydownHandler) {\n window.removeEventListener(\"keydown\", this.keydownHandler);\n this.keydownHandler = undefined;\n }\n\n // Remove click event listener\n if (this.clickHandler) {\n this.container.removeEventListener(\"click\", this.clickHandler);\n this.clickHandler = undefined;\n }\n\n // Clear wrapper references\n this.contentWrapper = null;\n this.iframeWrapper = null;\n\n // Clear container content and reset styles\n this.container.innerHTML = \"\";\n\n if (this.displayMode === \"modal\") {\n // Reset all modal-specific styles to ensure clean state\n this.resetModalStyles();\n }\n }\n\n /**\n * Clean up resources without removing the iframe - useful for embedded mode\n * This preserves the iframe and shows loading state after auth success\n */\n public cleanupResourcesOnly(): void {\n if (this.resizer) {\n this.resizer.cleanup();\n this.resizer = null;\n }\n\n // Clean up shimmer loader\n this.hideShimmerLoader();\n\n // Clean up close button (only exists in modal mode)\n if (this.closeButton && this.closeButton.parentNode) {\n this.closeButton.parentNode.removeChild(this.closeButton);\n this.closeButton = null;\n }\n\n // Clean up message listener\n if (this.iframeReadyMessageListener) {\n window.removeEventListener(\"message\", this.iframeReadyMessageListener);\n this.iframeReadyMessageListener = undefined;\n }\n\n // Remove keyboard event listener\n if (this.keydownHandler) {\n window.removeEventListener(\"keydown\", this.keydownHandler);\n this.keydownHandler = undefined;\n }\n\n // Remove click event listener\n if (this.clickHandler) {\n this.container.removeEventListener(\"click\", this.clickHandler);\n this.clickHandler = undefined;\n }\n\n // Reset loading state but keep iframe structure\n this.isIframeLoaded = false;\n\n // Reset preload state\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n // Clear wrapper references but don't remove from DOM\n this.contentWrapper = null;\n this.iframeWrapper = null;\n\n // For embedded mode, show loading state after cleanup\n if (this.displayMode === \"embedded\") {\n // Find the existing wrapper or create structure for loading state\n const existingWrapper = this.container.querySelector(\n \"[data-civic-wrapper]\",\n );\n if (existingWrapper) {\n this.iframeWrapper = existingWrapper as HTMLElement;\n this.forceShowLoader();\n } else {\n // Fallback: recreate basic structure for embedded mode\n this.recreateEmbeddedStructure();\n }\n }\n }\n\n /**\n * Recreate basic embedded structure after cleanup for showing loading state\n */\n private recreateEmbeddedStructure(): void {\n // Create wrapper for embedded mode\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT;\n this.iframeWrapper.style.backgroundColor = this.getBackgroundColor();\n this.iframeWrapper.style.display = \"flex\";\n this.iframeWrapper.style.alignItems = \"center\";\n this.iframeWrapper.style.justifyContent = \"center\";\n this.iframeWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n this.iframeWrapper.setAttribute(\"data-civic-wrapper\", \"true\");\n\n // Add to container\n this.container.appendChild(this.iframeWrapper);\n\n // Show loading spinner\n this.forceShowLoader();\n }\n\n /**\n * Resets all modal-specific styles by removing CSS properties that were set with !important\n */\n private resetModalStyles(): void {\n const modalStyleProperties = [\n \"position\",\n \"left\",\n \"top\",\n \"width\",\n \"height\",\n \"z-index\",\n \"display\",\n \"align-items\",\n \"justify-content\",\n \"background-color\",\n \"backdrop-filter\",\n \"opacity\",\n \"transition\",\n \"margin\",\n \"padding\",\n \"border\",\n \"border-radius\",\n \"min-height\",\n ];\n\n modalStyleProperties.forEach((property) => {\n this.container.style.removeProperty(property);\n });\n }\n\n public resize(): void {\n if (this.resizer) {\n this.resizer.resize();\n }\n }\n\n /**\n * Get the current display mode\n */\n public getDisplayMode(): \"embedded\" | \"modal\" {\n return this.displayMode;\n }\n\n /**\n * Force show the appropriate loader and hide iframe content\n * Used when we want to mask non-login content\n */\n public forceShowLoader(): void {\n // Reset loading state to show loader\n this.isIframeLoaded = false;\n\n // Hide iframe content\n if (this.iframe) {\n this.iframe.style.opacity = \"0\";\n }\n\n // Hide close button\n if (this.displayMode === \"modal\" && this.closeButton) {\n this.closeButton.style.opacity = \"0\";\n }\n\n // Hide visual decorations (borders, shadows) when masking content\n if (this.displayMode === \"modal\") {\n this.removeModalVisualStyling();\n }\n this.removeIframeWrapperStyling();\n\n // Show appropriate loader based on display mode\n if (this.iframeWrapper && !this.shimmerLoader) {\n if (this.displayMode === \"embedded\") {\n // For embedded mode, use the centered loading spinner (original loader)\n this.showLoadingSpinner();\n } else {\n // For modal mode, use the shimmer loader\n this.showShimmerLoader(this.iframeWrapper, \"white\");\n }\n }\n }\n\n /**\n * Force hide the shimmer loader and show iframe content\n * Used when we want to show the login app\n */\n public forceHideLoader(): void {\n // Restore visual decorations when showing content\n if (this.displayMode === \"modal\") {\n this.applyModalVisualStyling();\n }\n this.applyIframeWrapperStyling();\n\n this.markIframeAsLoaded();\n }\n\n /**\n * Applies visual styling (borders, shadows) to modal content wrapper\n */\n private applyModalVisualStyling(): void {\n if (!this.contentWrapper) return;\n\n this.contentWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n this.contentWrapper.style.boxShadow =\n \"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)\";\n }\n\n /**\n * Removes visual styling (borders, shadows) from modal content wrapper\n */\n private removeModalVisualStyling(): void {\n if (!this.contentWrapper) return;\n\n this.contentWrapper.style.boxShadow = \"none\";\n }\n\n /**\n * Applies visual styling (borders) to iframe wrapper\n */\n private applyIframeWrapperStyling(): void {\n if (!this.iframeWrapper) return;\n\n this.iframeWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n }\n\n /**\n * Removes visual styling (borders) from iframe wrapper\n */\n private removeIframeWrapperStyling(): void {\n if (!this.iframeWrapper) return;\n\n // Add any styles you want to remove here\n }\n\n /**\n * Check if an iframe is currently preloaded\n */\n public isIframePreloaded(): boolean {\n return this.isPreloaded;\n }\n\n /**\n * Get the URL of the preloaded iframe\n */\n public getPreloadedUrl(): string | null {\n return this.preloadUrl;\n }\n\n /**\n * Check if shimmer loader is currently active/showing\n */\n private isShimmerActive(): boolean {\n return !this.isIframeLoaded || !!this.shimmerLoader;\n }\n\n /**\n * Update the onClose handler for the iframe manager\n * This is useful when transitioning from preload to active authentication\n */\n public updateOnCloseHandler(onClose: () => void): void {\n this.onClose = onClose;\n }\n\n public showSubtlePopupFallbackIndicator(): void {\n if (!this.iframeWrapper && !this.contentWrapper) {\n this.logger.warn(\n \"Cannot show popup fallback indicator, no iframe wrapper or content wrapper found.\",\n );\n return;\n }\n\n const targetElement = this.iframeWrapper || this.contentWrapper;\n\n if (targetElement) {\n this.logger.debug(\"Showing popup fallback overlay.\");\n\n // Create overlay element\n const overlay = document.createElement(\"div\");\n overlay.id = \"civic-popup-fallback-overlay\";\n overlay.style.cssText = `\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: transparent;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n z-index: 1000;\n border-radius: ${IframeManager.BORDER_RADIUS};\n backdrop-filter: blur(.4px);\n opacity: 1;\n `;\n\n // Add overlay to target element\n targetElement.style.position = \"relative\";\n targetElement.appendChild(overlay);\n\n // Remove overlay quickly\n setTimeout(() => {\n if (overlay.parentNode) {\n overlay.parentNode.removeChild(overlay);\n }\n this.logger.debug(\"Popup fallback overlay removed.\");\n }, 500); // Remove after 500ms\n\n this.logger.debug(\"Popup fallback overlay displayed.\");\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IframeManager.js","sourceRoot":"","sources":["../../../src/vanillajs/iframe/IframeManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,yBAAyB,EACzB,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,4CAA4C,EAAE,MAAM,gBAAgB,CAAC;AAW9E;;;GAGG;AACH,MAAM,OAAO,aAAa;IACxB,0CAA0C;IAClC,MAAM,CAAU,aAAa,GAAG,M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G,UAAU,CAAC;YAC1C,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAEnC,yBAAyB;YACzB,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;oBACvB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAC1C,CAAC;gBACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACvD,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,qBAAqB;YAE9B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACzD,CAAC;IACH,CAAC","sourcesContent":["import { CivicIframeResizer } from \"./IframeResizer.js\";\nimport {\n createIframeShimmerLoader,\n createCenteredLoadingSpinner,\n createCloseButton,\n} from \"../ui/LoadingComponents.js\";\nimport { createLogger } from \"../utils/logger.js\";\nimport { WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT } from \"@/constants.js\";\n\nexport interface IframeConfig {\n container: HTMLElement;\n displayMode: \"embedded\" | \"modal\";\n width?: string;\n height?: string;\n iframeId?: string;\n onClose?: () => void;\n}\n\n/**\n * IframeManager - Manages iframe visual presentation and DOM lifecycle\n * Handles styling, positioning, UI components, and iframe element creation/cleanup\n */\nexport class IframeManager {\n // Constants for styling and configuration\n private static readonly MODAL_Z_INDEX = \"1050\";\n private static readonly MODAL_WIDTH = \"22rem\"; // 360px\n private static readonly MODAL_BACKDROP_COLOR = \"rgba(17, 24, 39, 0.5)\";\n private static readonly MODAL_BACKDROP_BLUR = \"blur(4px)\";\n private static readonly BORDER_RADIUS = \"26px\";\n private static readonly TRANSITION_DURATION = \"250ms\";\n private static readonly MODAL_MIN_HEIGHT = \"26px\";\n private static readonly EMBEDDED_MIN_HEIGHT = \"225px\";\n private static readonly IFRAME_READY_DELAY = 100; // ms\n\n private iframe: HTMLIFrameElement | null = null;\n private container: HTMLElement;\n private resizer: CivicIframeResizer | null = null;\n private displayMode: \"embedded\" | \"modal\";\n private keydownHandler?: (event: KeyboardEvent) => void;\n private clickHandler?: (event: MouseEvent) => void;\n private iframeId: string;\n private onClose?: () => void;\n private shimmerLoader: HTMLElement | null = null;\n private closeButton: HTMLButtonElement | null = null;\n private isIframeLoaded = false;\n private iframeReadyMessageListener?: (event: MessageEvent) => void;\n private logger: ReturnType<typeof createLogger>;\n // Store references to wrapper elements for styling control\n private contentWrapper: HTMLElement | null = null;\n private iframeWrapper: HTMLElement | null = null;\n // Preloading support\n private isPreloaded = false;\n private preloadUrl: string | null = null;\n public static browserCorsFailsSilentlyUrl: string | null = null;\n\n public static handleBrowserCorsFailsSilently(url: string): void {\n // Store the URL that caused CORS failure for later reference\n IframeManager.browserCorsFailsSilentlyUrl = url;\n }\n\n constructor(config: IframeConfig) {\n // we aren't going to render the iframe if the browser fails silently as we're redirecting\n\n this.container = config.container;\n this.displayMode = config.displayMode;\n this.iframeId = config.iframeId || \"civic-auth-iframe\";\n this.onClose = config.onClose;\n this.logger = createLogger(\"iframe\");\n this.initializeContainer(config);\n this.setupKeyboardHandlers();\n }\n\n private initializeContainer(config: IframeConfig): void {\n if (this.displayMode === \"modal\") {\n this.applyModalStyles();\n return;\n }\n\n // Embedded mode\n this.container.style.position = \"relative\";\n this.container.style.width = config.width || \"auto\";\n this.container.style.height = config.height || \"auto\";\n this.container.style.backgroundColor = \"transparent\";\n this.container.style.background = \"transparent\";\n this.container.style.borderRadius = IframeManager.BORDER_RADIUS;\n this.container.style.overflow = \"hidden\";\n this.container.style.transition = \"all 0.5s ease-in-out\";\n }\n\n /**\n * Applies modal backdrop styles to create a full-screen overlay\n * Uses !important to override any existing styles\n */\n private applyModalStyles(): void {\n const modalStyles = {\n position: \"fixed\",\n left: \"0\",\n top: \"0\",\n width: \"100vw\",\n height: \"100vh\",\n \"z-index\": IframeManager.MODAL_Z_INDEX,\n display: \"flex\",\n \"align-items\": \"center\",\n \"justify-content\": \"center\",\n \"background-color\": IframeManager.MODAL_BACKDROP_COLOR,\n \"backdrop-filter\": IframeManager.MODAL_BACKDROP_BLUR,\n opacity: \"1\",\n transition: `opacity ${IframeManager.TRANSITION_DURATION} ease`,\n // Reset any conflicting styles that might prevent modal from working\n margin: \"0\",\n padding: \"0\",\n border: \"none\",\n \"border-radius\": \"0\",\n \"min-height\": \"100vh\",\n };\n\n Object.entries(modalStyles).forEach(([property, value]) => {\n this.container.style.setProperty(property, value, \"important\");\n });\n }\n\n private setupKeyboardHandlers(): void {\n if (this.displayMode === \"modal\") {\n this.keydownHandler = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n this.onClose?.();\n }\n };\n window.addEventListener(\"keydown\", this.keydownHandler);\n }\n }\n\n /**\n * Preloads an iframe in the background for instant display later\n * The iframe is created but kept completely hidden and non-interactable\n */\n public preloadIframe(url: string): HTMLIFrameElement {\n this.logger.debug(\"Preloading iframe in background\", { url });\n\n // Clean up any existing iframe content, but preserve container styles for modal mode\n this.cleanupIframeOnly();\n\n // Create new iframe for preloading\n this.iframe = document.createElement(\"iframe\");\n this.iframe.id = this.iframeId;\n this.iframe.src = url;\n this.iframe.setAttribute(\"data-testid\", \"civic-auth-iframe-with-resizer\");\n\n // Apply base iframe styles but keep it completely hidden for preloading\n this.applyIframeStyles();\n\n // Make iframe completely invisible and non-interactable during preload\n this.iframe.style.display = \"none\";\n this.iframe.style.visibility = \"hidden\";\n this.iframe.style.pointerEvents = \"none\";\n this.iframe.style.position = \"absolute\";\n this.iframe.style.left = \"-9999px\";\n this.iframe.style.top = \"-9999px\";\n\n // Add attributes that prevent scrollbars\n this.setIframeAttributes();\n\n // Add CSS to prevent scrollbars\n this.addScrollbarHidingStyles();\n\n // Set up message listener for iframe ready events (more reliable than onload)\n this.setupIframeMessageListener();\n\n // Set up iframe onload handler\n this.setupIframeOnloadHandler();\n\n // For preloading, we need to add the iframe to the DOM but keep it hidden\n // Create a minimal container structure without showing it\n if (this.displayMode === \"modal\") {\n this.setupModalIframeForPreload();\n } else {\n this.setupEmbeddedIframeForPreload();\n }\n\n // Initialize resizer - this will handle all the message-based resizing\n this.resizer = new CivicIframeResizer(this.iframe, this.container, () =>\n this.isShimmerActive(),\n );\n\n // Mark as preloaded\n this.isPreloaded = true;\n this.preloadUrl = url;\n\n // Keep the container hidden during preload\n this.hide();\n\n this.logger.debug(\"Iframe preloaded successfully\", { url });\n return this.iframe;\n }\n\n public createIframe(url: string): HTMLIFrameElement {\n // If we have a preloaded iframe, show it instantly (even if URL differs)\n // URLs may differ due to fresh PKCE challenges and other dynamic parameters\n if (this.isPreloaded && this.iframe) {\n this.logger.debug(\"Using preloaded iframe for instant display\", {\n preloadedUrl: this.preloadUrl,\n requestedUrl: url,\n urlsMatch: this.preloadUrl === url,\n });\n\n // Don't change iframe.src for preloaded iframes - use them as-is to avoid reload\n // The preloaded authentication flow will work perfectly without URL changes\n this.logger.debug(\"Using preloaded iframe without reload\", {\n preloadedUrl: this.preloadUrl,\n requestedUrl: url,\n action: \"skipping_url_change_to_prevent_reload\",\n });\n\n // Make the preloaded iframe visible and interactable\n this.iframe.style.display = \"block\";\n this.iframe.style.visibility = \"visible\";\n this.iframe.style.pointerEvents = \"auto\";\n this.iframe.style.position = \"relative\";\n this.iframe.style.left = \"0\";\n this.iframe.style.top = \"0\";\n\n // Show the wrappers that were hidden during preload\n if (this.displayMode === \"modal\") {\n if (this.contentWrapper) {\n this.contentWrapper.style.display = \"block\";\n // Apply modal visual styling that was skipped during preload\n this.applyModalVisualStyling();\n\n // Set up modal behaviors (backdrop click, etc.)\n this.setupModalBehaviors();\n }\n } else {\n if (this.iframeWrapper) {\n this.iframeWrapper.style.display = \"flex\";\n // Apply wrapper styling that was skipped during preload\n this.applyIframeWrapperStyling();\n // Add loading spinner if content isn't loaded yet\n if (!this.isIframeLoaded) {\n this.showLoadingSpinner();\n }\n }\n }\n\n // Show the container\n this.show();\n\n // Reset preload state since we're now showing the iframe\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n return this.iframe;\n }\n\n // Clean up any existing iframe content, but preserve container styles for modal mode\n this.cleanupIframeOnly();\n\n // Create new iframe\n this.iframe = document.createElement(\"iframe\");\n this.iframe.id = this.iframeId;\n this.iframe.src = url;\n this.iframe.setAttribute(\"data-testid\", \"civic-auth-iframe-with-resizer\");\n\n // Apply iframe styles\n this.applyIframeStyles();\n\n // Add attributes that prevent scrollbars\n this.setIframeAttributes();\n\n // Add CSS to prevent scrollbars\n this.addScrollbarHidingStyles();\n\n // Set up message listener for iframe ready events (more reliable than onload)\n this.setupIframeMessageListener();\n\n // Set up iframe onload handler\n this.setupIframeOnloadHandler();\n\n if (this.displayMode === \"modal\") {\n this.setupModalIframe();\n } else {\n this.setupEmbeddedIframe();\n }\n\n // Initialize resizer - this will handle all the message-based resizing\n this.resizer = new CivicIframeResizer(this.iframe, this.container, () =>\n this.isShimmerActive(),\n );\n\n // Show the iframe container for non-preloaded iframes\n // Note: For preloaded iframes, show() is called earlier in the createIframe method\n // For modal mode, setupModalIframe() handles visibility, but embedded mode needs explicit show()\n if (this.displayMode === \"embedded\") {\n this.show();\n }\n\n return this.iframe;\n }\n\n /**\n * Applies base styles to the iframe element\n */\n private applyIframeStyles(): void {\n if (!this.iframe) return;\n\n const baseStyles = {\n border: \"none\",\n display: \"block\",\n pointerEvents: \"auto\",\n width: \"100%\",\n minWidth: \"100%\",\n overflow: \"hidden\",\n overflowX: \"hidden\",\n overflowY: \"hidden\",\n opacity: \"0\",\n transition: `opacity ${IframeManager.TRANSITION_DURATION} ease, height ${IframeManager.TRANSITION_DURATION} ease`,\n };\n\n Object.entries(baseStyles).forEach(([property, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required to handle dynamic CSS property assignment since CSSStyleDeclaration type doesn't fully capture all possible properties\n this.iframe!.style[property as any] = value;\n });\n\n // Set initial height based on display mode\n if (this.displayMode === \"modal\") {\n this.iframe!.style.height = IframeManager.MODAL_MIN_HEIGHT;\n this.iframe!.style.minHeight = IframeManager.MODAL_MIN_HEIGHT;\n } else {\n this.iframe!.style.height = \"auto\";\n this.iframe!.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT; // Embedded mode minimum\n }\n }\n\n /**\n * Sets iframe attributes to prevent scrollbars and enable local network access\n */\n private setIframeAttributes(): void {\n if (!this.iframe) return;\n\n this.iframe.setAttribute(\"scrolling\", \"no\");\n this.iframe.setAttribute(\"frameborder\", \"0\");\n this.iframe.setAttribute(\"seamless\", \"seamless\");\n // Include local-network-access permission to allow OAuth redirects to localhost in Chrome 142+\n // The wildcard (*) allows all origins that load in the iframe (including during SSO redirects)\n // to make local network requests when redirecting back to localhost callback URLs.\n //\n // Security Note: The wildcard is necessary because the iframe navigates through multiple origins\n // during OAuth/SSO flows (auth.civic.com → IdP → auth.civic.com → localhost). Third-party IdPs\n // (Google, Microsoft, Apple, custom OIDC) cannot be enumerated ahead of time. This is explicitly\n // recommended by Chrome for SSO scenarios. Security is maintained through:\n // - OAuth state validation preventing redirect hijacking\n // - Server-side redirect_uri whitelist validation\n // - HTTPS requirement preventing MitM attacks\n // - Limited permission lifetime (only while iframe exists)\n //\n // See: https://developer.chrome.com/blog/private-network-access-preflight\n this.iframe.setAttribute(\n \"allow\",\n \"camera; screen-wake-lock; publickey-credentials-get *; publickey-credentials-create *; local-network-access *\",\n );\n this.iframe.setAttribute(\"allowFullScreen\", \"true\");\n\n // Add additional CSS to prevent scrollbars\n this.iframe.style.cssText +=\n \"; -ms-overflow-style: none; scrollbar-width: none;\";\n }\n\n /**\n * Adds CSS styles to hide scrollbars across different browsers\n */\n private addScrollbarHidingStyles(): void {\n const iframeStyle = document.createElement(\"style\");\n iframeStyle.textContent = `\n iframe[id=\"${this.iframeId}\"] {\n -webkit-overflow-scrolling: touch !important;\n }\n iframe[id=\"${this.iframeId}\"]::webkit-scrollbar {\n display: none !important;\n width: 0 !important;\n height: 0 !important;\n }\n `;\n document.head.appendChild(iframeStyle);\n }\n\n /**\n * Sets up the message listener for iframe ready events\n */\n private setupIframeMessageListener(): void {\n this.iframeReadyMessageListener = (event: MessageEvent) => {\n try {\n // Only handle messages from our iframe\n if (\n !this.iframe?.contentWindow ||\n event.source !== this.iframe.contentWindow\n ) {\n return;\n }\n\n const message = event.data;\n\n // Handle ready message from iframe resizer\n if (message.type === \"civic-iframe-ready\") {\n this.logger.debug(\"Iframe content is ready - hiding shimmer loader\");\n // wait a bit to ensure any initial loading is complete\n // to give the login-app time to send any post message signals\n setTimeout(() => {\n // Mark iframe as loaded FIRST to disable shimmer blocking\n this.markIframeAsLoaded();\n\n // Replay any blocked resize messages now that shimmer is inactive\n this.resizer?.replayBlockedMessages();\n this.resizer?.resize();\n }, WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT);\n }\n } catch (error) {\n this.logger.debug(\"Error processing iframe ready message:\", error);\n }\n };\n\n window.addEventListener(\"message\", this.iframeReadyMessageListener);\n }\n\n /**\n * Sets up the iframe onload handler with CSS injection\n */\n private setupIframeOnloadHandler(): void {\n if (!this.iframe) return;\n\n this.iframe.onload = () => {\n // Use a small delay to allow ready message to arrive first\n setTimeout(() => {\n if (!this.isIframeLoaded) {\n this.logger.debug(\n \"Iframe onload fired - hiding shimmer loader (fallback)\",\n );\n this.markIframeAsLoaded();\n }\n }, IframeManager.IFRAME_READY_DELAY);\n\n try {\n const iframeDoc =\n this.iframe?.contentDocument || this.iframe?.contentWindow?.document;\n if (iframeDoc && iframeDoc.head) {\n const style = iframeDoc.createElement(\"style\");\n style.textContent = `\n html, body {\n overflow: hidden !important;\n overflow-x: hidden !important;\n overflow-y: hidden !important;\n -ms-overflow-style: none !important;\n scrollbar-width: none !important;\n margin: 0 !important;\n padding: 0 !important;\n }\n body::-webkit-scrollbar {\n display: none !important;\n }\n * {\n box-sizing: border-box !important;\n }\n `;\n iframeDoc.head.appendChild(style);\n }\n } catch (error) {\n this.logger.debug(\n \"Could not inject CSS into iframe (likely cross-origin):\",\n error,\n );\n }\n };\n }\n\n /**\n * Sets up the iframe for modal display mode during preload\n * Creates the structure but keeps everything hidden\n */\n private setupModalIframeForPreload(): void {\n if (!this.iframe) return;\n\n // Create content wrapper for modal but keep it hidden\n this.contentWrapper = document.createElement(\"div\");\n this.contentWrapper.style.position = \"relative\";\n this.contentWrapper.style.overflow = \"hidden\";\n this.contentWrapper.style.width = IframeManager.MODAL_WIDTH;\n this.contentWrapper.style.display = \"none\"; // Keep hidden during preload\n\n // Create inner iframe wrapper\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = `all ${IframeManager.TRANSITION_DURATION} ease`;\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.MODAL_MIN_HEIGHT;\n\n // Add iframe to wrapper, then wrapper to content, then content to container\n this.iframeWrapper.appendChild(this.iframe);\n this.contentWrapper.appendChild(this.iframeWrapper);\n this.container.appendChild(this.contentWrapper);\n }\n\n /**\n * Sets up the iframe for embedded display mode during preload\n * Creates the structure but keeps everything hidden\n */\n private setupEmbeddedIframeForPreload(): void {\n if (!this.iframe) return;\n\n // Create wrapper but keep it hidden\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = \"all 0.5s ease-in-out\";\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT;\n this.iframeWrapper.style.backgroundColor = this.getBackgroundColor();\n this.iframeWrapper.style.display = \"none\"; // Keep hidden during preload\n this.iframeWrapper.style.alignItems = \"center\";\n this.iframeWrapper.style.justifyContent = \"center\";\n\n // Apply initial wrapper styling (border radius)\n this.applyIframeWrapperStyling();\n\n // Create a content wrapper for the iframe\n const iframeContentWrapper = document.createElement(\"div\");\n iframeContentWrapper.style.width = \"100%\";\n iframeContentWrapper.style.minWidth = \"100%\";\n iframeContentWrapper.style.alignItems = \"center\";\n iframeContentWrapper.style.justifyContent = \"center\";\n iframeContentWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n iframeContentWrapper.style.overflow = \"hidden\";\n iframeContentWrapper.style.opacity = \"1\"; // Already loaded during preload\n iframeContentWrapper.style.transition = \"opacity 0.5s ease-in-out\";\n\n // Add iframe to content wrapper\n iframeContentWrapper.appendChild(this.iframe);\n\n // Add content wrapper to main wrapper\n this.iframeWrapper.appendChild(iframeContentWrapper);\n\n // Store reference for later use\n this.contentWrapper = iframeContentWrapper;\n\n // Add wrapper to container\n this.container.appendChild(this.iframeWrapper);\n }\n\n /**\n * Sets up the iframe for modal display mode\n */\n private setupModalIframe(): void {\n if (!this.iframe) return;\n\n // Ensure modal is visible (in case it was hidden by cleanup)\n this.container.style.setProperty(\"display\", \"flex\", \"important\");\n\n // Create content wrapper for modal\n this.contentWrapper = document.createElement(\"div\");\n this.contentWrapper.style.position = \"relative\";\n this.contentWrapper.style.overflow = \"hidden\";\n this.contentWrapper.style.width = IframeManager.MODAL_WIDTH; // 360px like React version\n\n // Apply initial visual styling\n this.applyModalVisualStyling();\n\n // Create inner iframe wrapper to match React structure\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = `all ${IframeManager.TRANSITION_DURATION} ease`;\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.MODAL_MIN_HEIGHT; // Start small for modal mode\n\n // Apply initial wrapper styling\n this.applyIframeWrapperStyling();\n\n // Add shimmer loader for modal mode\n this.showShimmerLoader(this.iframeWrapper, \"white\");\n\n // Add iframe to wrapper, then wrapper to content, then content to container\n this.iframeWrapper.appendChild(this.iframe);\n this.contentWrapper.appendChild(this.iframeWrapper);\n this.container.appendChild(this.contentWrapper);\n\n this.setupModalBehaviors();\n }\n\n /**\n * Sets up modal-specific behaviors like click handlers and close button\n */\n private setupModalBehaviors(): void {\n if (!this.contentWrapper) return;\n\n // Stop propagation on content wrapper to prevent backdrop clicks\n this.contentWrapper.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n });\n\n // Add close button for modal mode (initially hidden if not loaded)\n if (this.onClose && !this.closeButton) {\n this.closeButton = createCloseButton(this.onClose);\n // Show close button immediately if iframe is already loaded, otherwise keep hidden\n this.closeButton.style.opacity = this.isIframeLoaded ? \"1\" : \"0\";\n this.contentWrapper.appendChild(this.closeButton);\n }\n\n // Add click-to-close functionality after content is added\n if (!this.clickHandler) {\n this.clickHandler = (e: MouseEvent) => {\n if (e.target === this.container) {\n // Only close if clicking the backdrop, not the iframe content\n this.onClose?.();\n }\n };\n this.container.addEventListener(\"click\", this.clickHandler);\n }\n }\n\n /**\n * Sets up the iframe for embedded display mode\n */\n private setupEmbeddedIframe(): void {\n if (!this.iframe) return;\n\n // Embedded mode - create wrapper with border radius and overflow hidden\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.overflowX = \"hidden\";\n this.iframeWrapper.style.overflowY = \"hidden\";\n this.iframeWrapper.style.transition = \"all 0.5s ease-in-out\";\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT; // Embedded mode minimum\n this.iframeWrapper.style.backgroundColor = this.getBackgroundColor();\n this.iframeWrapper.style.display = \"flex\";\n this.iframeWrapper.style.alignItems = \"center\";\n this.iframeWrapper.style.justifyContent = \"center\";\n this.iframeWrapper.setAttribute(\"data-civic-wrapper\", \"true\");\n\n // Apply initial wrapper styling (border radius)\n this.applyIframeWrapperStyling();\n\n // Add centered loading spinner for embedded mode\n this.showLoadingSpinner();\n\n // Create a content wrapper for the iframe\n const iframeContentWrapper = document.createElement(\"div\");\n iframeContentWrapper.style.width = \"100%\";\n iframeContentWrapper.style.minWidth = \"100%\";\n iframeContentWrapper.style.alignItems = \"center\";\n iframeContentWrapper.style.justifyContent = \"center\";\n iframeContentWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n iframeContentWrapper.style.overflow = \"hidden\";\n iframeContentWrapper.style.opacity = \"0\";\n iframeContentWrapper.style.transition = \"opacity 0.5s ease-in-out\";\n\n // Add iframe to content wrapper\n iframeContentWrapper.appendChild(this.iframe);\n\n // Add content wrapper to main wrapper\n this.iframeWrapper.appendChild(iframeContentWrapper);\n\n // Store reference for later use\n this.contentWrapper = iframeContentWrapper;\n\n // Add wrapper to container\n this.container.appendChild(this.iframeWrapper);\n }\n\n private showShimmerLoader(\n parentElement: HTMLElement,\n backgroundColor = \"white\",\n maxWidth?: string,\n ): void {\n if (!this.isIframeLoaded && !this.shimmerLoader) {\n this.shimmerLoader = createIframeShimmerLoader(backgroundColor, maxWidth);\n parentElement.appendChild(this.shimmerLoader);\n }\n }\n\n /**\n * Shows a centered loading spinner for embedded mode\n */\n private showLoadingSpinner(): void {\n if (!this.isIframeLoaded && !this.shimmerLoader && this.iframeWrapper) {\n this.shimmerLoader = createCenteredLoadingSpinner();\n this.iframeWrapper.appendChild(this.shimmerLoader);\n }\n }\n\n /**\n * Gets the background color based on the user's theme preference\n */\n private getBackgroundColor(): string {\n // Check if we're in a browser environment\n if (typeof window === \"undefined\") {\n return \"#8E949D\"; // Default gray when SSR\n }\n\n // Use media query to detect dark mode preference\n const isDarkMode =\n window.matchMedia &&\n window.matchMedia(\"(prefers-color-scheme: dark)\").matches;\n\n // Return appropriate background color - matching React constants\n return isDarkMode ? \"rgb(30, 41, 59)\" : \"white\";\n }\n\n private hideShimmerLoader(): void {\n if (this.shimmerLoader && this.shimmerLoader.parentNode) {\n // Store reference for cleanup\n const shimmerElement = this.shimmerLoader;\n\n // Clear reference immediately to allow resize operations\n this.shimmerLoader = null;\n\n // Add fade-out transition before removing\n shimmerElement.style.opacity = \"0\";\n shimmerElement.style.transition = `opacity ${IframeManager.TRANSITION_DURATION} ease`;\n\n // Remove after transition completes\n setTimeout(() => {\n if (shimmerElement && shimmerElement.parentNode) {\n shimmerElement.parentNode.removeChild(shimmerElement);\n }\n }, parseInt(IframeManager.TRANSITION_DURATION));\n }\n }\n\n private markIframeAsLoaded(): void {\n if (IframeManager.browserCorsFailsSilentlyUrl) {\n return;\n }\n if (!this.isIframeLoaded) {\n this.isIframeLoaded = true;\n this.hideShimmerLoader();\n this.updateWrapperForLoadedContent();\n }\n }\n\n private updateWrapperForLoadedContent(): void {\n // For embedded mode, fade in both the content wrapper and iframe\n if (this.displayMode === \"embedded\" && this.contentWrapper) {\n this.contentWrapper.style.opacity = \"1\";\n // Also make sure the iframe itself is visible\n if (this.iframe) {\n this.iframe.style.opacity = \"1\";\n }\n } else if (this.iframe) {\n // For modal mode, fade in the iframe directly\n this.iframe.style.opacity = \"1\";\n }\n\n // Show close button for modal mode when content is loaded\n if (this.displayMode === \"modal\" && this.closeButton) {\n this.closeButton.style.opacity = \"1\";\n }\n\n // Find the iframe wrapper and update its styles for loaded content\n const iframeWrapper = this.iframe?.parentElement;\n if (iframeWrapper) {\n // Remove minimum height constraints to allow natural sizing\n if (this.displayMode === \"modal\") {\n iframeWrapper.style.minHeight = \"auto\";\n } else {\n // For embedded mode, keep some minimum but allow natural growth\n iframeWrapper.style.minHeight = \"auto\";\n }\n\n // Add border radius transition for loaded state (matching React implementation)\n iframeWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n }\n }\n\n public hide(): void {\n if (this.displayMode === \"modal\") {\n // Hide immediately without transition\n this.container.style.transition = \"none\";\n this.container.style.opacity = \"0\";\n }\n this.container.style.display = \"none\";\n }\n\n public show(): void {\n if (this.displayMode === \"modal\") {\n // Show immediately, then fade in\n this.container.style.display = \"flex\";\n this.container.style.opacity = \"0\";\n this.container.style.transition = `opacity ${IframeManager.TRANSITION_DURATION} ease`;\n\n // Use setTimeout to ensure display change takes effect before opacity transition\n setTimeout(() => {\n this.container.style.opacity = \"1\";\n }, 10);\n } else {\n // For embedded mode, just show immediately\n this.container.style.display = \"block\";\n this.container.style.opacity = \"1\";\n\n // Fix: Ensure the iframe itself is also visible immediately for embedded mode\n // The iframe starts with opacity: 0 from applyIframeStyles, but embedded mode\n // should show the iframe immediately without waiting for loaded content\n if (this.iframe) {\n this.iframe.style.opacity = \"1\";\n }\n }\n }\n\n private cleanupIframeOnly(): void {\n if (this.resizer) {\n this.resizer.cleanup();\n this.resizer = null;\n }\n\n // Clean up shimmer loader\n this.hideShimmerLoader();\n\n // Clean up close button\n if (this.closeButton && this.closeButton.parentNode) {\n this.closeButton.parentNode.removeChild(this.closeButton);\n this.closeButton = null;\n }\n\n // Clean up message listener\n if (this.iframeReadyMessageListener) {\n window.removeEventListener(\"message\", this.iframeReadyMessageListener);\n this.iframeReadyMessageListener = undefined;\n }\n\n if (this.iframe && this.iframe.parentNode) {\n this.iframe.parentNode.removeChild(this.iframe);\n this.iframe = null;\n }\n\n // Reset loading state\n this.isIframeLoaded = false;\n\n // Reset preload state\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n // Clear wrapper references\n this.contentWrapper = null;\n this.iframeWrapper = null;\n\n // Clear container content but DON'T reset styles for modal mode\n this.container.innerHTML = \"\";\n }\n\n public cleanup(): void {\n if (this.resizer) {\n this.resizer.cleanup();\n this.resizer = null;\n }\n\n // Clean up shimmer loader\n this.hideShimmerLoader();\n\n // Clean up close button\n if (this.closeButton && this.closeButton.parentNode) {\n this.closeButton.parentNode.removeChild(this.closeButton);\n this.closeButton = null;\n }\n\n // Clean up message listener\n if (this.iframeReadyMessageListener) {\n window.removeEventListener(\"message\", this.iframeReadyMessageListener);\n this.iframeReadyMessageListener = undefined;\n }\n\n if (this.iframe && this.iframe.parentNode) {\n this.iframe.parentNode.removeChild(this.iframe);\n this.iframe = null;\n }\n\n // Reset loading state\n this.isIframeLoaded = false;\n\n // Reset preload state\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n // Remove keyboard event listener\n if (this.keydownHandler) {\n window.removeEventListener(\"keydown\", this.keydownHandler);\n this.keydownHandler = undefined;\n }\n\n // Remove click event listener\n if (this.clickHandler) {\n this.container.removeEventListener(\"click\", this.clickHandler);\n this.clickHandler = undefined;\n }\n\n // Clear wrapper references\n this.contentWrapper = null;\n this.iframeWrapper = null;\n\n // Clear container content and reset styles\n this.container.innerHTML = \"\";\n\n if (this.displayMode === \"modal\") {\n // Reset all modal-specific styles to ensure clean state\n this.resetModalStyles();\n }\n }\n\n /**\n * Clean up resources without removing the iframe - useful for embedded mode\n * This preserves the iframe and shows loading state after auth success\n */\n public cleanupResourcesOnly(): void {\n if (this.resizer) {\n this.resizer.cleanup();\n this.resizer = null;\n }\n\n // Clean up shimmer loader\n this.hideShimmerLoader();\n\n // Clean up close button (only exists in modal mode)\n if (this.closeButton && this.closeButton.parentNode) {\n this.closeButton.parentNode.removeChild(this.closeButton);\n this.closeButton = null;\n }\n\n // Clean up message listener\n if (this.iframeReadyMessageListener) {\n window.removeEventListener(\"message\", this.iframeReadyMessageListener);\n this.iframeReadyMessageListener = undefined;\n }\n\n // Remove keyboard event listener\n if (this.keydownHandler) {\n window.removeEventListener(\"keydown\", this.keydownHandler);\n this.keydownHandler = undefined;\n }\n\n // Remove click event listener\n if (this.clickHandler) {\n this.container.removeEventListener(\"click\", this.clickHandler);\n this.clickHandler = undefined;\n }\n\n // Reset loading state but keep iframe structure\n this.isIframeLoaded = false;\n\n // Reset preload state\n this.isPreloaded = false;\n this.preloadUrl = null;\n\n // Clear wrapper references but don't remove from DOM\n this.contentWrapper = null;\n this.iframeWrapper = null;\n\n // For embedded mode, show loading state after cleanup\n if (this.displayMode === \"embedded\") {\n // Find the existing wrapper or create structure for loading state\n const existingWrapper = this.container.querySelector(\n \"[data-civic-wrapper]\",\n );\n if (existingWrapper) {\n this.iframeWrapper = existingWrapper as HTMLElement;\n this.forceShowLoader();\n } else {\n // Fallback: recreate basic structure for embedded mode\n this.recreateEmbeddedStructure();\n }\n }\n }\n\n /**\n * Recreate basic embedded structure after cleanup for showing loading state\n */\n private recreateEmbeddedStructure(): void {\n // Create wrapper for embedded mode\n this.iframeWrapper = document.createElement(\"div\");\n this.iframeWrapper.style.position = \"relative\";\n this.iframeWrapper.style.overflow = \"hidden\";\n this.iframeWrapper.style.width = \"100%\";\n this.iframeWrapper.style.height = \"auto\";\n this.iframeWrapper.style.minHeight = IframeManager.EMBEDDED_MIN_HEIGHT;\n this.iframeWrapper.style.backgroundColor = this.getBackgroundColor();\n this.iframeWrapper.style.display = \"flex\";\n this.iframeWrapper.style.alignItems = \"center\";\n this.iframeWrapper.style.justifyContent = \"center\";\n this.iframeWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n this.iframeWrapper.setAttribute(\"data-civic-wrapper\", \"true\");\n\n // Add to container\n this.container.appendChild(this.iframeWrapper);\n\n // Show loading spinner\n this.forceShowLoader();\n }\n\n /**\n * Resets all modal-specific styles by removing CSS properties that were set with !important\n */\n private resetModalStyles(): void {\n const modalStyleProperties = [\n \"position\",\n \"left\",\n \"top\",\n \"width\",\n \"height\",\n \"z-index\",\n \"display\",\n \"align-items\",\n \"justify-content\",\n \"background-color\",\n \"backdrop-filter\",\n \"opacity\",\n \"transition\",\n \"margin\",\n \"padding\",\n \"border\",\n \"border-radius\",\n \"min-height\",\n ];\n\n modalStyleProperties.forEach((property) => {\n this.container.style.removeProperty(property);\n });\n }\n\n public resize(): void {\n if (this.resizer) {\n this.resizer.resize();\n }\n }\n\n /**\n * Get the current display mode\n */\n public getDisplayMode(): \"embedded\" | \"modal\" {\n return this.displayMode;\n }\n\n /**\n * Force show the appropriate loader and hide iframe content\n * Used when we want to mask non-login content\n */\n public forceShowLoader(): void {\n // Reset loading state to show loader\n this.isIframeLoaded = false;\n\n // Hide iframe content\n if (this.iframe) {\n this.iframe.style.opacity = \"0\";\n }\n\n // Hide close button\n if (this.displayMode === \"modal\" && this.closeButton) {\n this.closeButton.style.opacity = \"0\";\n }\n\n // Hide visual decorations (borders, shadows) when masking content\n if (this.displayMode === \"modal\") {\n this.removeModalVisualStyling();\n }\n this.removeIframeWrapperStyling();\n\n // Show appropriate loader based on display mode\n if (this.iframeWrapper && !this.shimmerLoader) {\n if (this.displayMode === \"embedded\") {\n // For embedded mode, use the centered loading spinner (original loader)\n this.showLoadingSpinner();\n } else {\n // For modal mode, use the shimmer loader\n this.showShimmerLoader(this.iframeWrapper, \"white\");\n }\n }\n }\n\n /**\n * Force hide the shimmer loader and show iframe content\n * Used when we want to show the login app\n */\n public forceHideLoader(): void {\n // Restore visual decorations when showing content\n if (this.displayMode === \"modal\") {\n this.applyModalVisualStyling();\n }\n this.applyIframeWrapperStyling();\n\n this.markIframeAsLoaded();\n }\n\n /**\n * Applies visual styling (borders, shadows) to modal content wrapper\n */\n private applyModalVisualStyling(): void {\n if (!this.contentWrapper) return;\n\n this.contentWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n this.contentWrapper.style.boxShadow =\n \"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)\";\n }\n\n /**\n * Removes visual styling (borders, shadows) from modal content wrapper\n */\n private removeModalVisualStyling(): void {\n if (!this.contentWrapper) return;\n\n this.contentWrapper.style.boxShadow = \"none\";\n }\n\n /**\n * Applies visual styling (borders) to iframe wrapper\n */\n private applyIframeWrapperStyling(): void {\n if (!this.iframeWrapper) return;\n\n this.iframeWrapper.style.borderRadius = IframeManager.BORDER_RADIUS;\n }\n\n /**\n * Removes visual styling (borders) from iframe wrapper\n */\n private removeIframeWrapperStyling(): void {\n if (!this.iframeWrapper) return;\n\n // Add any styles you want to remove here\n }\n\n /**\n * Check if an iframe is currently preloaded\n */\n public isIframePreloaded(): boolean {\n return this.isPreloaded;\n }\n\n /**\n * Get the URL of the preloaded iframe\n */\n public getPreloadedUrl(): string | null {\n return this.preloadUrl;\n }\n\n /**\n * Check if shimmer loader is currently active/showing\n */\n private isShimmerActive(): boolean {\n return !this.isIframeLoaded || !!this.shimmerLoader;\n }\n\n /**\n * Update the onClose handler for the iframe manager\n * This is useful when transitioning from preload to active authentication\n */\n public updateOnCloseHandler(onClose: () => void): void {\n this.onClose = onClose;\n }\n\n public showSubtlePopupFallbackIndicator(): void {\n if (!this.iframeWrapper && !this.contentWrapper) {\n this.logger.warn(\n \"Cannot show popup fallback indicator, no iframe wrapper or content wrapper found.\",\n );\n return;\n }\n\n const targetElement = this.iframeWrapper || this.contentWrapper;\n\n if (targetElement) {\n this.logger.debug(\"Showing popup fallback overlay.\");\n\n // Create overlay element\n const overlay = document.createElement(\"div\");\n overlay.id = \"civic-popup-fallback-overlay\";\n overlay.style.cssText = `\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: transparent;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n z-index: 1000;\n border-radius: ${IframeManager.BORDER_RADIUS};\n backdrop-filter: blur(.4px);\n opacity: 1;\n `;\n\n // Add overlay to target element\n targetElement.style.position = \"relative\";\n targetElement.appendChild(overlay);\n\n // Remove overlay quickly\n setTimeout(() => {\n if (overlay.parentNode) {\n overlay.parentNode.removeChild(overlay);\n }\n this.logger.debug(\"Popup fallback overlay removed.\");\n }, 500); // Remove after 500ms\n\n this.logger.debug(\"Popup fallback overlay displayed.\");\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civic/auth",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -89,8 +89,8 @@
|
|
|
89
89
|
"vite": "^5",
|
|
90
90
|
"vite-plugin-dts": "^4.2.3",
|
|
91
91
|
"vitest": "^2.1.8",
|
|
92
|
-
"@repo/
|
|
93
|
-
"@repo/
|
|
92
|
+
"@repo/typescript-config": "0.0.0",
|
|
93
|
+
"@repo/eslint-config": "0.0.0"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
96
|
"express": ">=4.0.0",
|