@civic/auth 0.9.5 → 0.9.6-beta.2

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.
Files changed (224) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/nextjs/actions.d.ts +12 -0
  3. package/dist/nextjs/actions.d.ts.map +1 -0
  4. package/dist/nextjs/actions.js +26 -0
  5. package/dist/nextjs/actions.js.map +1 -0
  6. package/dist/nextjs/config.d.ts +2 -0
  7. package/dist/nextjs/config.d.ts.map +1 -1
  8. package/dist/nextjs/config.js +3 -2
  9. package/dist/nextjs/config.js.map +1 -1
  10. package/dist/nextjs/cookies.d.ts.map +1 -1
  11. package/dist/nextjs/cookies.js +45 -3
  12. package/dist/nextjs/cookies.js.map +1 -1
  13. package/dist/nextjs/hooks/useInitialAuthConfig.d.ts +31 -0
  14. package/dist/nextjs/hooks/useInitialAuthConfig.d.ts.map +1 -0
  15. package/dist/nextjs/hooks/useInitialAuthConfig.js +109 -0
  16. package/dist/nextjs/hooks/useInitialAuthConfig.js.map +1 -0
  17. package/dist/nextjs/index.d.ts +1 -0
  18. package/dist/nextjs/index.d.ts.map +1 -1
  19. package/dist/nextjs/index.js +13 -3
  20. package/dist/nextjs/index.js.map +1 -1
  21. package/dist/nextjs/providers/NextAuthProvider.d.ts +6 -7
  22. package/dist/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
  23. package/dist/nextjs/providers/NextAuthProvider.js +19 -138
  24. package/dist/nextjs/providers/NextAuthProvider.js.map +1 -1
  25. package/dist/nextjs/providers/NextAuthProviderClient.d.ts +11 -0
  26. package/dist/nextjs/providers/NextAuthProviderClient.d.ts.map +1 -0
  27. package/dist/nextjs/providers/NextAuthProviderClient.js +62 -0
  28. package/dist/nextjs/providers/NextAuthProviderClient.js.map +1 -0
  29. package/dist/nextjs/providers/ServerUserContext.d.ts +2 -0
  30. package/dist/nextjs/providers/ServerUserContext.d.ts.map +1 -0
  31. package/dist/nextjs/providers/ServerUserContext.js +5 -0
  32. package/dist/nextjs/providers/ServerUserContext.js.map +1 -0
  33. package/dist/nextjs/routeHandler.d.ts.map +1 -1
  34. package/dist/nextjs/routeHandler.js +241 -352
  35. package/dist/nextjs/routeHandler.js.map +1 -1
  36. package/dist/react-router-7/components/UserButton.js +1 -1
  37. package/dist/react-router-7/components/UserButton.js.map +1 -1
  38. package/dist/react-router-7/routeHandler.d.ts.map +1 -1
  39. package/dist/react-router-7/routeHandler.js +1 -0
  40. package/dist/react-router-7/routeHandler.js.map +1 -1
  41. package/dist/react-router-7/useUser.d.ts.map +1 -1
  42. package/dist/react-router-7/useUser.js +13 -2
  43. package/dist/react-router-7/useUser.js.map +1 -1
  44. package/dist/reactjs/components/ButtonContentOrLoader.d.ts.map +1 -1
  45. package/dist/reactjs/components/ButtonContentOrLoader.js +2 -4
  46. package/dist/reactjs/components/ButtonContentOrLoader.js.map +1 -1
  47. package/dist/reactjs/components/CivicAuthIframeContainer.d.ts +2 -0
  48. package/dist/reactjs/components/CivicAuthIframeContainer.d.ts.map +1 -0
  49. package/dist/reactjs/components/CivicAuthIframeContainer.js +26 -0
  50. package/dist/reactjs/components/CivicAuthIframeContainer.js.map +1 -0
  51. package/dist/reactjs/components/SignInButton.d.ts.map +1 -1
  52. package/dist/reactjs/components/SignInButton.js +11 -1
  53. package/dist/reactjs/components/SignInButton.js.map +1 -1
  54. package/dist/reactjs/components/UserButton.d.ts +9 -2
  55. package/dist/reactjs/components/UserButton.d.ts.map +1 -1
  56. package/dist/reactjs/components/UserButton.js +41 -9
  57. package/dist/reactjs/components/UserButton.js.map +1 -1
  58. package/dist/reactjs/components/index.d.ts +1 -0
  59. package/dist/reactjs/components/index.d.ts.map +1 -1
  60. package/dist/reactjs/components/index.js +1 -0
  61. package/dist/reactjs/components/index.js.map +1 -1
  62. package/dist/reactjs/core/GlobalAuthManager.d.ts +26 -0
  63. package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
  64. package/dist/reactjs/core/GlobalAuthManager.js +76 -5
  65. package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
  66. package/dist/reactjs/hooks/useUser.d.ts +19 -2
  67. package/dist/reactjs/hooks/useUser.d.ts.map +1 -1
  68. package/dist/reactjs/hooks/useUser.js +95 -7
  69. package/dist/reactjs/hooks/useUser.js.map +1 -1
  70. package/dist/reactjs/index.d.ts +1 -2
  71. package/dist/reactjs/index.d.ts.map +1 -1
  72. package/dist/reactjs/index.js +1 -2
  73. package/dist/reactjs/index.js.map +1 -1
  74. package/dist/reactjs/providers/CivicAuthProvider.d.ts +2 -1
  75. package/dist/reactjs/providers/CivicAuthProvider.d.ts.map +1 -1
  76. package/dist/reactjs/providers/CivicAuthProvider.js +3 -1
  77. package/dist/reactjs/providers/CivicAuthProvider.js.map +1 -1
  78. package/dist/server/ServerAuthenticationResolver.d.ts.map +1 -1
  79. package/dist/server/ServerAuthenticationResolver.js +18 -0
  80. package/dist/server/ServerAuthenticationResolver.js.map +1 -1
  81. package/dist/server/index.d.ts +1 -1
  82. package/dist/server/index.d.ts.map +1 -1
  83. package/dist/server/index.js.map +1 -1
  84. package/dist/server/session.d.ts +51 -0
  85. package/dist/server/session.d.ts.map +1 -1
  86. package/dist/server/session.js +276 -15
  87. package/dist/server/session.js.map +1 -1
  88. package/dist/shared/components/SVGLoading.js +1 -1
  89. package/dist/shared/components/SVGLoading.js.map +1 -1
  90. package/dist/shared/components/UserButtonPresentation.d.ts.map +1 -0
  91. package/dist/shared/components/UserButtonPresentation.js.map +1 -0
  92. package/dist/shared/hooks/index.d.ts +1 -2
  93. package/dist/shared/hooks/index.d.ts.map +1 -1
  94. package/dist/shared/hooks/index.js +1 -2
  95. package/dist/shared/hooks/index.js.map +1 -1
  96. package/dist/shared/hooks/useBfcacheHandler.d.ts +23 -0
  97. package/dist/shared/hooks/useBfcacheHandler.d.ts.map +1 -0
  98. package/dist/shared/hooks/useBfcacheHandler.js +65 -0
  99. package/dist/shared/hooks/useBfcacheHandler.js.map +1 -0
  100. package/dist/shared/index.d.ts +1 -0
  101. package/dist/shared/index.d.ts.map +1 -1
  102. package/dist/shared/index.js +1 -0
  103. package/dist/shared/index.js.map +1 -1
  104. package/dist/shared/lib/util.d.ts +32 -0
  105. package/dist/shared/lib/util.d.ts.map +1 -1
  106. package/dist/shared/lib/util.js +79 -0
  107. package/dist/shared/lib/util.js.map +1 -1
  108. package/dist/shared/providers/AuthStatusContext.d.ts.map +1 -1
  109. package/dist/shared/providers/AuthStatusContext.js +2 -1
  110. package/dist/shared/providers/AuthStatusContext.js.map +1 -1
  111. package/dist/shared/providers/CivicAuthConfigContext.d.ts +2 -1
  112. package/dist/shared/providers/CivicAuthConfigContext.d.ts.map +1 -1
  113. package/dist/shared/providers/CivicAuthConfigContext.js +5 -2
  114. package/dist/shared/providers/CivicAuthConfigContext.js.map +1 -1
  115. package/dist/shared/providers/types.d.ts +1 -0
  116. package/dist/shared/providers/types.d.ts.map +1 -1
  117. package/dist/shared/providers/types.js.map +1 -1
  118. package/dist/shared/utils/locationChange.d.ts +34 -0
  119. package/dist/shared/utils/locationChange.d.ts.map +1 -0
  120. package/dist/shared/utils/locationChange.js +28 -0
  121. package/dist/shared/utils/locationChange.js.map +1 -0
  122. package/dist/shared/version.d.ts +1 -1
  123. package/dist/shared/version.d.ts.map +1 -1
  124. package/dist/shared/version.js +1 -1
  125. package/dist/shared/version.js.map +1 -1
  126. package/dist/vanillajs/auth/AuthenticationEvents.d.ts +10 -1
  127. package/dist/vanillajs/auth/AuthenticationEvents.d.ts.map +1 -1
  128. package/dist/vanillajs/auth/AuthenticationEvents.js +29 -0
  129. package/dist/vanillajs/auth/AuthenticationEvents.js.map +1 -1
  130. package/dist/vanillajs/auth/BackendAuthenticationRefresher.d.ts.map +1 -1
  131. package/dist/vanillajs/auth/BackendAuthenticationRefresher.js +2 -2
  132. package/dist/vanillajs/auth/BackendAuthenticationRefresher.js.map +1 -1
  133. package/dist/vanillajs/auth/CivicAuth.d.ts +32 -0
  134. package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -1
  135. package/dist/vanillajs/auth/CivicAuth.js +255 -55
  136. package/dist/vanillajs/auth/CivicAuth.js.map +1 -1
  137. package/dist/vanillajs/auth/SessionManager.d.ts +3 -2
  138. package/dist/vanillajs/auth/SessionManager.d.ts.map +1 -1
  139. package/dist/vanillajs/auth/SessionManager.js +33 -7
  140. package/dist/vanillajs/auth/SessionManager.js.map +1 -1
  141. package/dist/vanillajs/auth/config/ConfigProcessor.d.ts.map +1 -1
  142. package/dist/vanillajs/auth/config/ConfigProcessor.js +2 -14
  143. package/dist/vanillajs/auth/config/ConfigProcessor.js.map +1 -1
  144. package/dist/vanillajs/auth/handlers/IframeAuthHandler.d.ts.map +1 -1
  145. package/dist/vanillajs/auth/handlers/IframeAuthHandler.js +64 -11
  146. package/dist/vanillajs/auth/handlers/IframeAuthHandler.js.map +1 -1
  147. package/dist/vanillajs/auth/handlers/MessageHandler.d.ts.map +1 -1
  148. package/dist/vanillajs/auth/handlers/MessageHandler.js +4 -1
  149. package/dist/vanillajs/auth/handlers/MessageHandler.js.map +1 -1
  150. package/dist/vanillajs/auth/handlers/PopupHandler.d.ts.map +1 -1
  151. package/dist/vanillajs/auth/handlers/PopupHandler.js +3 -1
  152. package/dist/vanillajs/auth/handlers/PopupHandler.js.map +1 -1
  153. package/dist/vanillajs/auth/types/AuthTypes.d.ts +11 -1
  154. package/dist/vanillajs/auth/types/AuthTypes.d.ts.map +1 -1
  155. package/dist/vanillajs/auth/types/AuthTypes.js.map +1 -1
  156. package/dist/vanillajs/iframe/IframeManager.d.ts +22 -1
  157. package/dist/vanillajs/iframe/IframeManager.d.ts.map +1 -1
  158. package/dist/vanillajs/iframe/IframeManager.js +184 -22
  159. package/dist/vanillajs/iframe/IframeManager.js.map +1 -1
  160. package/dist/vanillajs/types/index.d.ts +1 -1
  161. package/dist/vanillajs/types/index.d.ts.map +1 -1
  162. package/dist/vanillajs/types/index.js +1 -1
  163. package/dist/vanillajs/types/index.js.map +1 -1
  164. package/dist/vanillajs/ui/LoadingComponents.d.ts +4 -0
  165. package/dist/vanillajs/ui/LoadingComponents.d.ts.map +1 -1
  166. package/dist/vanillajs/ui/LoadingComponents.js +51 -1
  167. package/dist/vanillajs/ui/LoadingComponents.js.map +1 -1
  168. package/package.json +3 -3
  169. package/dist/nextjs/hooks/index.d.ts +0 -2
  170. package/dist/nextjs/hooks/index.d.ts.map +0 -1
  171. package/dist/nextjs/hooks/index.js +0 -2
  172. package/dist/nextjs/hooks/index.js.map +0 -1
  173. package/dist/nextjs/hooks/usePrevious.d.ts +0 -2
  174. package/dist/nextjs/hooks/usePrevious.d.ts.map +0 -1
  175. package/dist/nextjs/hooks/usePrevious.js +0 -9
  176. package/dist/nextjs/hooks/usePrevious.js.map +0 -1
  177. package/dist/nextjs/hooks/useUserCookie.d.ts +0 -9
  178. package/dist/nextjs/hooks/useUserCookie.d.ts.map +0 -1
  179. package/dist/nextjs/hooks/useUserCookie.js +0 -109
  180. package/dist/nextjs/hooks/useUserCookie.js.map +0 -1
  181. package/dist/react-router-7/components/UserButtonPresentation.d.ts.map +0 -1
  182. package/dist/react-router-7/components/UserButtonPresentation.js.map +0 -1
  183. package/dist/shared/components/BlockDisplay.d.ts +0 -6
  184. package/dist/shared/components/BlockDisplay.d.ts.map +0 -1
  185. package/dist/shared/components/BlockDisplay.js +0 -30
  186. package/dist/shared/components/BlockDisplay.js.map +0 -1
  187. package/dist/shared/components/CivicAuthIframe.d.ts +0 -10
  188. package/dist/shared/components/CivicAuthIframe.d.ts.map +0 -1
  189. package/dist/shared/components/CivicAuthIframe.js +0 -49
  190. package/dist/shared/components/CivicAuthIframe.js.map +0 -1
  191. package/dist/shared/components/CivicAuthIframeContainer.d.ts +0 -15
  192. package/dist/shared/components/CivicAuthIframeContainer.d.ts.map +0 -1
  193. package/dist/shared/components/CivicAuthIframeContainer.js +0 -177
  194. package/dist/shared/components/CivicAuthIframeContainer.js.map +0 -1
  195. package/dist/shared/components/CivicAuthLogoutIframeContainer.d.ts +0 -6
  196. package/dist/shared/components/CivicAuthLogoutIframeContainer.d.ts.map +0 -1
  197. package/dist/shared/components/CivicAuthLogoutIframeContainer.js +0 -51
  198. package/dist/shared/components/CivicAuthLogoutIframeContainer.js.map +0 -1
  199. package/dist/shared/components/IFrameAndLoading.d.ts +0 -7
  200. package/dist/shared/components/IFrameAndLoading.d.ts.map +0 -1
  201. package/dist/shared/components/IFrameAndLoading.js +0 -66
  202. package/dist/shared/components/IFrameAndLoading.js.map +0 -1
  203. package/dist/shared/hooks/useAuth.d.ts +0 -3
  204. package/dist/shared/hooks/useAuth.d.ts.map +0 -1
  205. package/dist/shared/hooks/useAuth.js +0 -12
  206. package/dist/shared/hooks/useAuth.js.map +0 -1
  207. package/dist/shared/hooks/useIframe.d.ts +0 -3
  208. package/dist/shared/hooks/useIframe.d.ts.map +0 -1
  209. package/dist/shared/hooks/useIframe.js +0 -13
  210. package/dist/shared/hooks/useIframe.js.map +0 -1
  211. package/dist/shared/hooks/useIsInIframe.d.ts +0 -7
  212. package/dist/shared/hooks/useIsInIframe.d.ts.map +0 -1
  213. package/dist/shared/hooks/useIsInIframe.js +0 -23
  214. package/dist/shared/hooks/useIsInIframe.js.map +0 -1
  215. package/dist/shared/hooks/useSignIn.d.ts +0 -20
  216. package/dist/shared/hooks/useSignIn.d.ts.map +0 -1
  217. package/dist/shared/hooks/useSignIn.js +0 -358
  218. package/dist/shared/hooks/useSignIn.js.map +0 -1
  219. package/dist/shared/providers/IframeProvider.d.ts +0 -28
  220. package/dist/shared/providers/IframeProvider.d.ts.map +0 -1
  221. package/dist/shared/providers/IframeProvider.js +0 -64
  222. package/dist/shared/providers/IframeProvider.js.map +0 -1
  223. /package/dist/{react-router-7 → shared}/components/UserButtonPresentation.d.ts +0 -0
  224. /package/dist/{react-router-7 → shared}/components/UserButtonPresentation.js +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"CivicAuthLogoutIframeContainer.js","sourceRoot":"","sources":["../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AAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;wBAC9C,IAAI,WAAW,IAAI,WAAW,KAAK,GAAG,EAAE,CAAC;4BACvC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,WAAW,CAAC;4BACnC,OAAO,IAAI,CAAC;wBACd,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,CAAC,gCAAgC;IAChD,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACxB,MAAC,YAAY,IAAC,aAAa,EAAE,IAAI,aAC9B,SAAS,CAAC,CAAC,CAAC,CACX,cACE,EAAE,EAAC,iCAAiC,EACpC,KAAK,EAAE;oBACL,QAAQ,EAAE,UAAU;oBACpB,KAAK,EAAE,CAAC;oBACR,OAAO,EAAE,MAAM;oBACf,UAAU,EAAE,QAAQ;oBACpB,cAAc,EAAE,QAAQ;iBACzB,YAED,KAAC,WAAW,KAAG,GACX,CACP,CAAC,CAAC,CAAC,IAAI,EACR,KAAC,eAAe,IACd,GAAG,EAAE,eAAe,EACpB,EAAE,EAAE,0BAA0B,EAC9B,MAAM,EAAE,sBAAsB,GAC9B,IACW,CAChB,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["\"use client\";\n\nimport { CivicAuthIframe } from \"@/shared/components/CivicAuthIframe.js\";\nimport { useIframe } from \"@/shared/hooks/index.js\";\nimport { LoadingIcon } from \"./LoadingIcon.js\";\nimport { IframeChrome } from \"./CivicAuthIframeContainer.js\";\nimport { useIsClient } from \"usehooks-ts\";\nimport { useCallback } from \"react\";\nimport { getIframeRef } from \"../lib/iframeUtils.js\";\nimport { LOGOUT_SUCCESS_TEXT } from \"@/constants.js\";\n\ntype CivicAuthLogoutIframeContainerProps = {\n isLoading?: boolean;\n};\n\nconst CivicAuthLogoutIframeContainer = ({\n isLoading = false,\n}: CivicAuthLogoutIframeContainerProps) => {\n const { logoutIframeRef } = useIframe();\n const isClient = useIsClient();\n\n const processLogoutIframeUrl = useCallback(() => {\n if (logoutIframeRef && logoutIframeRef.current) {\n const ref = getIframeRef(logoutIframeRef.current)!;\n\n if (!ref?.contentWindow) {\n return;\n }\n\n try {\n const iframeBody = ref.contentWindow.document.body.innerHTML;\n\n // If we have LOGOUT_SUCCESS_TEXT in the body, we know the logout succeeded on the server,\n // and we should redirect the parent to the post logout success URL indicated in the included link tag.\n if (iframeBody.includes(LOGOUT_SUCCESS_TEXT)) {\n const link = ref.contentWindow.document.querySelector(\n \"a[rel='civic-auth-post-logout-redirect-url']\",\n );\n if (link) {\n const redirectUrl = link.getAttribute(\"href\");\n if (redirectUrl && redirectUrl !== \"#\") {\n window.location.href = redirectUrl;\n return true;\n }\n }\n }\n } catch {\n // ignore errors while waiting for redirect\n }\n }\n return false; // Haven't processed the URL yet\n }, [logoutIframeRef]);\n\n // don't render the in server-mode as the appearance changes after load\n return !isClient ? null : (\n <IframeChrome isFrameLoaded={true}>\n {isLoading ? (\n <div\n id=\"civic-auth-loading-icon-wrapper\"\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n <LoadingIcon />\n </div>\n ) : null}\n <CivicAuthIframe\n ref={logoutIframeRef}\n id={\"civic-auth-logout-iframe\"}\n onLoad={processLogoutIframeUrl}\n />\n </IframeChrome>\n );\n};\n\nexport { CivicAuthLogoutIframeContainer };\n"]}
@@ -1,7 +0,0 @@
1
- declare const IFrameAndLoading: ({ error, showIframeOnLogout, }: {
2
- error: Error | null;
3
- isLoading: boolean;
4
- showIframeOnLogout?: boolean;
5
- }) => import("@emotion/react/jsx-runtime").JSX.Element;
6
- export { IFrameAndLoading };
7
- //# sourceMappingURL=IFrameAndLoading.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IFrameAndLoading.d.ts","sourceRoot":"","sources":["../../../src/shared/components/IFrameAndLoading.tsx"],"names":[],"mappings":"AAWA,QAAA,MAAM,gBAAgB,mCAGnB;IACD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,qDAwGA,CAAC;AACF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,66 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
- import React, { useEffect, useState } from "react";
3
- import { useIframe } from "../hooks/useIframe.js";
4
- import { useIsInIframe } from "../hooks/useIsInIframe.js";
5
- import { CivicAuthIframeContainer } from "./CivicAuthIframeContainer.js";
6
- import { BlockDisplay } from "./BlockDisplay.js";
7
- import { LoadingIcon } from "./LoadingIcon.js";
8
- import { CivicAuthLogoutIframeContainer } from "./CivicAuthLogoutIframeContainer.js";
9
- import { useSession } from "../hooks/useSession.js";
10
- import { useAuthStatus } from "../providers/AuthStatusContext.js";
11
- import { AuthStatus } from "../../types.js";
12
- const IFrameAndLoading = ({ error, showIframeOnLogout = false, }) => {
13
- const isInIframe = useIsInIframe();
14
- const [logoutIframeLoading, setLogoutIframeLoading] = useState(true);
15
- const { renderIframe, iframeIsVisible, setIframeIsVisible, logoutIframeIsVisible, } = useIframe();
16
- const { authStatus } = useAuthStatus();
17
- const session = useSession();
18
- // we show a loading overlay to block the display for the user
19
- // as the page that loads within the iframe will be the actual customer
20
- // login page just after authenticatino, which shouldn't be shown to the user during login
21
- // there's a small period where we're resolving the session and the iframe is showing
22
- const showLoadingOverlay = isInIframe;
23
- useEffect(() => {
24
- const handleErrorMessage = (event) => {
25
- const thisURL = new URL(window.location.href);
26
- if (!(event.origin.endsWith("civic.com") || thisURL.hostname === "localhost")) {
27
- return;
28
- }
29
- // The login app has thrown an error, so we need to show the logout iframe
30
- if (event.data?.source === "civicloginApp" &&
31
- event.data?.type === "auth_error") {
32
- setLogoutIframeLoading(false);
33
- return;
34
- }
35
- setLogoutIframeLoading(true);
36
- };
37
- window.addEventListener("message", handleErrorMessage);
38
- return () => window.removeEventListener("message", handleErrorMessage);
39
- }, []);
40
- const [iframeShouldRender, setIframeShouldRender] = useState(renderIframe);
41
- useEffect(() => {
42
- // We can't remove the iframe from the DOM immediately on authentication,
43
- // because it needs a short window to render a special 'TOKEN_EXCHANGE_SUCCESS' message
44
- // which the parent needs to detect in order to redirect to the loginSuccessUrl if any.
45
- // So we wait 500ms to allow that to happen before removing the iframe.
46
- if (session.data?.authenticated) {
47
- setTimeout(() => {
48
- return setIframeShouldRender(false);
49
- }, 500);
50
- }
51
- }, [session.data?.authenticated]);
52
- /**
53
- * This useEffect resets the iframeShouldRender state when the authStatus changes. We need it
54
- * as the iframeShouldRender state is set to false when the user is authenticated, but it needs to be reset
55
- */
56
- useEffect(() => {
57
- if (authStatus !== AuthStatus.AUTHENTICATED) {
58
- setIframeShouldRender(renderIframe);
59
- }
60
- }, [authStatus, renderIframe, iframeIsVisible]);
61
- return (_jsxs(_Fragment, { children: [iframeShouldRender && (_jsx("div", { id: "civic-auth-iframe-container", style: iframeIsVisible ? { display: "block" } : { display: "none" }, children: _jsx(CivicAuthIframeContainer, { onClose: () => setIframeIsVisible(false) }) })), _jsx("div", { style: showIframeOnLogout && logoutIframeIsVisible
62
- ? { display: "block" }
63
- : { display: "none" }, children: _jsx(CivicAuthLogoutIframeContainer, { isLoading: logoutIframeLoading }) }), error && (_jsx(BlockDisplay, { children: _jsxs("div", { children: ["Error: ", error?.message] }) })), showLoadingOverlay && !error && (_jsx(BlockDisplay, { children: _jsx(LoadingIcon, {}) }))] }));
64
- };
65
- export { IFrameAndLoading };
66
- //# sourceMappingURL=IFrameAndLoading.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"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AE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAEhD,OAAO,CACL,8BAGG,kBAAkB,IAAI,CACrB,cACE,EAAE,EAAC,6BAA6B,EAChC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,YAEnE,KAAC,wBAAwB,IAAC,OAAO,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAI,GAClE,CACP,EAED,cACE,KAAK,EACH,kBAAkB,IAAI,qBAAqB;oBACzC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;oBACtB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,YAGzB,KAAC,8BAA8B,IAAC,SAAS,EAAE,mBAAmB,GAAI,GAC9D,EAEL,KAAK,IAAI,CACR,KAAC,YAAY,cACX,qCAAa,KAAK,EAAE,OAAO,IAAO,GACrB,CAChB,EAEA,kBAAkB,IAAI,CAAC,KAAK,IAAI,CAC/B,KAAC,YAAY,cACX,KAAC,WAAW,KAAG,GACF,CAChB,IACA,CACJ,CAAC;AACJ,CAAC,CAAC;AACF,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { useIframe } from \"../hooks/useIframe.js\";\nimport { useIsInIframe } from \"../hooks/useIsInIframe.js\";\nimport { CivicAuthIframeContainer } from \"./CivicAuthIframeContainer.js\";\nimport { BlockDisplay } from \"./BlockDisplay.js\";\nimport { LoadingIcon } from \"./LoadingIcon.js\";\nimport { CivicAuthLogoutIframeContainer } from \"./CivicAuthLogoutIframeContainer.js\";\nimport { useSession } from \"../hooks/useSession.js\";\nimport { useAuthStatus } from \"../providers/AuthStatusContext.js\";\nimport { AuthStatus } from \"@/types.js\";\n\nconst IFrameAndLoading = ({\n error,\n showIframeOnLogout = false,\n}: {\n error: Error | null;\n isLoading: boolean;\n showIframeOnLogout?: boolean;\n}) => {\n const isInIframe = useIsInIframe();\n const [logoutIframeLoading, setLogoutIframeLoading] = useState(true);\n const {\n renderIframe,\n iframeIsVisible,\n setIframeIsVisible,\n logoutIframeIsVisible,\n } = useIframe();\n const { authStatus } = useAuthStatus();\n const session = useSession();\n // we show a loading overlay to block the display for the user\n // as the page that loads within the iframe will be the actual customer\n // login page just after authenticatino, which shouldn't be shown to the user during login\n // there's a small period where we're resolving the session and the iframe is showing\n const showLoadingOverlay = isInIframe;\n\n useEffect(() => {\n const handleErrorMessage = (event: MessageEvent) => {\n const thisURL = new URL(window.location.href);\n if (\n !(\n event.origin.endsWith(\"civic.com\") || thisURL.hostname === \"localhost\"\n )\n ) {\n return;\n }\n\n // The login app has thrown an error, so we need to show the logout iframe\n if (\n event.data?.source === \"civicloginApp\" &&\n event.data?.type === \"auth_error\"\n ) {\n setLogoutIframeLoading(false);\n return;\n }\n\n setLogoutIframeLoading(true);\n };\n\n window.addEventListener(\"message\", handleErrorMessage);\n return () => window.removeEventListener(\"message\", handleErrorMessage);\n }, []);\n\n const [iframeShouldRender, setIframeShouldRender] = useState(renderIframe);\n\n useEffect(() => {\n // We can't remove the iframe from the DOM immediately on authentication,\n // because it needs a short window to render a special 'TOKEN_EXCHANGE_SUCCESS' message\n // which the parent needs to detect in order to redirect to the loginSuccessUrl if any.\n // So we wait 500ms to allow that to happen before removing the iframe.\n if (session.data?.authenticated) {\n setTimeout(() => {\n return setIframeShouldRender(false);\n }, 500);\n }\n }, [session.data?.authenticated]);\n\n /**\n * This useEffect resets the iframeShouldRender state when the authStatus changes. We need it\n * as the iframeShouldRender state is set to false when the user is authenticated, but it needs to be reset\n */\n useEffect(() => {\n if (authStatus !== AuthStatus.AUTHENTICATED) {\n setIframeShouldRender(renderIframe);\n }\n }, [authStatus, renderIframe, iframeIsVisible]);\n\n return (\n <>\n {/* when the user is authenticated we shouldn't render the iframe anymore\n so that we clear the session for the next time */}\n {iframeShouldRender && (\n <div\n id=\"civic-auth-iframe-container\"\n style={iframeIsVisible ? { display: \"block\" } : { display: \"none\" }}\n >\n <CivicAuthIframeContainer onClose={() => setIframeIsVisible(false)} />\n </div>\n )}\n\n <div\n style={\n showIframeOnLogout && logoutIframeIsVisible\n ? { display: \"block\" }\n : { display: \"none\" }\n }\n >\n <CivicAuthLogoutIframeContainer isLoading={logoutIframeLoading} />\n </div>\n\n {error && (\n <BlockDisplay>\n <div>Error: {error?.message}</div>\n </BlockDisplay>\n )}\n\n {showLoadingOverlay && !error && (\n <BlockDisplay>\n <LoadingIcon />\n </BlockDisplay>\n )}\n </>\n );\n};\nexport { IFrameAndLoading };\n"]}
@@ -1,3 +0,0 @@
1
- declare const useAuth: () => import("../../shared/providers/AuthContext.js").AuthContextType;
2
- export { useAuth };
3
- //# sourceMappingURL=useAuth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useAuth.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,OAAO,mEAQZ,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,12 +0,0 @@
1
- "use client";
2
- import { useContext } from "react";
3
- import { AuthContext } from "../../shared/providers/AuthContext.js";
4
- const useAuth = () => {
5
- const context = useContext(AuthContext);
6
- if (!context) {
7
- throw new Error("useAuth must be used within an AuthProvider");
8
- }
9
- return context;
10
- };
11
- export { useAuth };
12
- //# sourceMappingURL=useAuth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../../src/shared/hooks/useAuth.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAEhE,MAAM,OAAO,GAAG,GAAG,EAAE;IACnB,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["\"use client\";\nimport { useContext } from \"react\";\nimport { AuthContext } from \"@/shared/providers/AuthContext.js\";\n\nconst useAuth = () => {\n const context = useContext(AuthContext);\n\n if (!context) {\n throw new Error(\"useAuth must be used within an AuthProvider\");\n }\n\n return context;\n};\n\nexport { useAuth };\n"]}
@@ -1,3 +0,0 @@
1
- declare const useIframe: () => import("../../shared/providers/IframeProvider.js").IframeProviderOutput;
2
- export { useIframe };
3
- //# sourceMappingURL=useIframe.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIframe.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useIframe.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,SAAS,2EAMd,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,13 +0,0 @@
1
- "use client";
2
- import { useContext } from "react";
3
- import { IframeContext } from "../../shared/providers/IframeProvider.js";
4
- // TokenProvider will use this internal context to access Iframe
5
- const useIframe = () => {
6
- const context = useContext(IframeContext);
7
- if (!context) {
8
- throw new Error("useIframe must be used within an IframeProvider");
9
- }
10
- return context;
11
- };
12
- export { useIframe };
13
- //# sourceMappingURL=useIframe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIframe.js","sourceRoot":"","sources":["../../../src/shared/hooks/useIframe.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,gEAAgE;AAChE,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["\"use client\";\nimport { useContext } from \"react\";\nimport { IframeContext } from \"@/shared/providers/IframeProvider.js\";\n\n// TokenProvider will use this internal context to access Iframe\nconst useIframe = () => {\n const context = useContext(IframeContext);\n if (!context) {\n throw new Error(\"useIframe must be used within an IframeProvider\");\n }\n return context;\n};\n\nexport { useIframe };\n"]}
@@ -1,7 +0,0 @@
1
- /**
2
- * React hook to detect if the current window is running inside an iframe
3
- * @returns boolean indicating whether the current window is in an iframe
4
- */
5
- declare const useIsInIframe: () => boolean;
6
- export { useIsInIframe };
7
- //# sourceMappingURL=useIsInIframe.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIsInIframe.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useIsInIframe.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,QAAA,MAAM,aAAa,eAelB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- import { isWindowInIframe } from "../../lib/windowUtil.js";
2
- import { useEffect, useState } from "react";
3
- /**
4
- * React hook to detect if the current window is running inside an iframe
5
- * @returns boolean indicating whether the current window is in an iframe
6
- */
7
- const useIsInIframe = () => {
8
- // Start with undefined to indicate we don't know yet
9
- const [isInIframe, setIsInIframe] = useState(undefined);
10
- useEffect(() => {
11
- if (typeof globalThis.window !== "undefined") {
12
- const isInIframeVal = isWindowInIframe(globalThis.window);
13
- setIsInIframe(isInIframeVal);
14
- }
15
- else {
16
- setIsInIframe(false);
17
- }
18
- }, []);
19
- // Return false if undefined to be safe
20
- return isInIframe === undefined ? false : isInIframe;
21
- };
22
- export { useIsInIframe };
23
- //# sourceMappingURL=useIsInIframe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIsInIframe.js","sourceRoot":"","sources":["../../../src/shared/hooks/useIsInIframe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C;;;GAGG;AACH,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,qDAAqD;IACrD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAsB,SAAS,CAAC,CAAC;IAE7E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;YAC7C,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC1D,aAAa,CAAC,aAAa,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,uCAAuC;IACvC,OAAO,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;AACvD,CAAC,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import { isWindowInIframe } from \"@/lib/windowUtil.js\";\nimport { useEffect, useState } from \"react\";\n\n/**\n * React hook to detect if the current window is running inside an iframe\n * @returns boolean indicating whether the current window is in an iframe\n */\nconst useIsInIframe = () => {\n // Start with undefined to indicate we don't know yet\n const [isInIframe, setIsInIframe] = useState<boolean | undefined>(undefined);\n\n useEffect(() => {\n if (typeof globalThis.window !== \"undefined\") {\n const isInIframeVal = isWindowInIframe(globalThis.window);\n setIsInIframe(isInIframeVal);\n } else {\n setIsInIframe(false);\n }\n }, []);\n\n // Return false if undefined to be safe\n return isInIframe === undefined ? false : isInIframe;\n};\n\nexport { useIsInIframe };\n"]}
@@ -1,20 +0,0 @@
1
- import { AuthStatus, type DisplayMode } from "../../types.js";
2
- import { type PKCEConsumer } from "../../services/types.js";
3
- type SignInProps = {
4
- pkceConsumer?: PKCEConsumer;
5
- preSignOut?: () => Promise<void>;
6
- postSignOut?: () => Promise<void>;
7
- displayMode: DisplayMode;
8
- };
9
- /**
10
- * Hook to manage authentication flow.
11
- */
12
- declare const useSignIn: ({ pkceConsumer, preSignOut, postSignOut, displayMode }?: SignInProps) => {
13
- signIn: () => Promise<void>;
14
- signOut: () => Promise<void>;
15
- startSignIn: () => Promise<void>;
16
- authStatus: AuthStatus;
17
- displayMode: DisplayMode;
18
- };
19
- export { useSignIn };
20
- //# sourceMappingURL=useSignIn.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSignIn.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useSignIn.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,UAAU,EACV,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQpE,KAAK,WAAW,GAAG;IACjB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAcF;;GAEG;AACH,QAAA,MAAM,SAAS,4DAC2C,WAAW;kBAkQ9B,OAAO,CAAC,IAAI,CAAC;;uBAxGR,OAAO,CAAC,IAAI,CAAC;;;CAsSxD,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,358 +0,0 @@
1
- import { BrowserAuthenticationInitiator } from "../../services/AuthenticationService.js";
2
- import { BrowserPublicClientPKCEProducer } from "../../services/PKCE.js";
3
- import { useCivicAuthConfig } from "../../shared/hooks/useCivicAuthConfig.js";
4
- import { AuthStatus, } from "../../types.js";
5
- import { useIframe } from "../../shared/hooks/useIframe.js";
6
- import { useCallback, useEffect, useMemo, useRef } from "react";
7
- import { PopupError } from "../../services/types.js";
8
- import { useSession } from "./useSession.js";
9
- import { LocalStorageAdapter } from "../../browser/storage.js";
10
- import { clearTokens, clearUser } from "../lib/util.js";
11
- import { useLocalStorage } from "usehooks-ts";
12
- import { LOGOUT_STATE } from "../../constants.js";
13
- import { useAuthStatus } from "../../shared/providers/AuthStatusContext.js";
14
- const SIGN_IN_TIMEOUT_MS = 9 * 60 * 1000; // 9 minutes in milliseconds
15
- /**
16
- * Hook to manage authentication flow.
17
- */
18
- const useSignIn = ({ pkceConsumer, preSignOut, postSignOut, displayMode } = {
19
- displayMode: "iframe",
20
- }) => {
21
- // Config and external state
22
- const civicAuthConfig = useCivicAuthConfig();
23
- const { iframeRef, logoutIframeRef, setIframeIsVisible, setLogoutIframeIsVisible, iframeAborted, setIframeAborted, } = useIframe();
24
- const { data: session } = useSession();
25
- const { authStatus, setAuthStatus } = useAuthStatus();
26
- const [, setDesignOption] = useLocalStorage(`loginAppDesign`, { colorMode: "auto" });
27
- // Internal state tracking
28
- const timeoutRef = useRef(null);
29
- const authStatusRef = useRef(AuthStatus.UNAUTHENTICATED);
30
- const isSigningInRef = useRef(false);
31
- // Promise handling
32
- const signInPromiseRef = useRef();
33
- const signInResolveRef = useRef(null);
34
- const signInRejectRef = useRef(null);
35
- // Event handlers
36
- const handlersRef = useRef({
37
- handleSignInComplete: null,
38
- handleSignInError: null,
39
- });
40
- // Helper to resolve/reject sign-in promise with cleanup
41
- const resolveSignInPromise = useCallback(() => {
42
- if (signInResolveRef.current) {
43
- setAuthStatus(AuthStatus.AUTHENTICATED);
44
- authStatusRef.current = AuthStatus.AUTHENTICATED;
45
- isSigningInRef.current = false;
46
- signInResolveRef.current();
47
- // Clean up after resolving
48
- signInResolveRef.current = null;
49
- signInRejectRef.current = null;
50
- signInPromiseRef.current = undefined;
51
- if (timeoutRef.current !== null) {
52
- window.clearTimeout(timeoutRef.current);
53
- timeoutRef.current = null;
54
- }
55
- }
56
- }, [setAuthStatus]);
57
- const rejectSignInPromise = useCallback((error, newStatus = AuthStatus.ERROR) => {
58
- if (signInRejectRef.current) {
59
- signInRejectRef.current(error);
60
- // Clean up after rejecting
61
- signInResolveRef.current = null;
62
- signInRejectRef.current = null;
63
- signInPromiseRef.current = undefined;
64
- isSigningInRef.current = false;
65
- setAuthStatus(newStatus);
66
- if (timeoutRef.current !== null) {
67
- window.clearTimeout(timeoutRef.current);
68
- timeoutRef.current = null;
69
- }
70
- }
71
- }, [setAuthStatus]);
72
- // Create authentication initiator
73
- const authInitiator = useMemo(() => {
74
- if (!civicAuthConfig)
75
- return null;
76
- const { clientId, redirectUrl, logoutUrl, loginSuccessUrl, logoutRedirectUrl, nonce, oauthServer, endpoints, scopes, autoRedirect, } = civicAuthConfig;
77
- return new BrowserAuthenticationInitiator({
78
- pkceConsumer: pkceConsumer || new BrowserPublicClientPKCEProducer(),
79
- clientId,
80
- redirectUrl,
81
- loginSuccessUrl,
82
- logoutUrl,
83
- logoutRedirectUrl,
84
- scopes,
85
- displayMode,
86
- oauthServer,
87
- endpointOverrides: endpoints,
88
- nonce,
89
- framework: civicAuthConfig.framework,
90
- autoRedirect,
91
- }, setDesignOption);
92
- }, [civicAuthConfig, displayMode, pkceConsumer, setDesignOption]);
93
- // Cleanup resources when component unmounts
94
- useEffect(() => {
95
- return () => {
96
- if (authInitiator) {
97
- authInitiator.cleanup();
98
- }
99
- if (timeoutRef.current !== null) {
100
- window.clearTimeout(timeoutRef.current);
101
- timeoutRef.current = null;
102
- }
103
- };
104
- }, [authInitiator]);
105
- // Handle logout state cleanup
106
- useEffect(() => {
107
- const params = new URLSearchParams(window.location.search);
108
- const state = params.get("state");
109
- const localStorage = new LocalStorageAdapter();
110
- localStorage.get(LOGOUT_STATE).then((storedLogoutState) => {
111
- if (state && state === storedLogoutState) {
112
- // Clear storage
113
- clearTokens(localStorage);
114
- clearUser(localStorage);
115
- LocalStorageAdapter.emitter.emit("signOut");
116
- // Clean up storage and URL
117
- sessionStorage.removeItem(LOGOUT_STATE);
118
- const cleanUrl = window.location.href.split("?")[0];
119
- window.history.replaceState({}, document.title, cleanUrl);
120
- }
121
- });
122
- }, []);
123
- // Main sign-in logic
124
- const startSignIn = useCallback(async () => {
125
- if (!authInitiator)
126
- return;
127
- // Create the promise and store its handlers
128
- const promise = new Promise((resolve, reject) => {
129
- signInResolveRef.current = resolve;
130
- signInRejectRef.current = reject;
131
- });
132
- signInPromiseRef.current = promise;
133
- // Check if sign-in is already in progress using the ref, if so, return signIn promise
134
- if (isSigningInRef.current) {
135
- return promise;
136
- }
137
- // State machine for sign-in flow
138
- switch (authStatus) {
139
- case AuthStatus.AUTHENTICATED:
140
- return Promise.resolve();
141
- case AuthStatus.UNAUTHENTICATED:
142
- case AuthStatus.ERROR:
143
- break;
144
- case AuthStatus.AUTHENTICATING:
145
- // if we're already authenticating, return the existing promise
146
- return promise;
147
- default:
148
- return Promise.reject(new Error(`Invalid state for sign-in: ${authStatus}`));
149
- }
150
- // Set signing in flag first
151
- isSigningInRef.current = true;
152
- // Clear any existing timeout
153
- if (timeoutRef.current !== null) {
154
- window.clearTimeout(timeoutRef.current);
155
- timeoutRef.current = null;
156
- }
157
- try {
158
- // Set authenticating status before any async operations
159
- setAuthStatus(AuthStatus.AUTHENTICATING);
160
- authStatusRef.current = AuthStatus.AUTHENTICATING;
161
- authInitiator.setDisplayMode(displayMode);
162
- // Set a timeout to reject the promise if authentication takes too long
163
- timeoutRef.current = window.setTimeout(() => {
164
- if (authStatusRef.current === AuthStatus.AUTHENTICATING) {
165
- rejectSignInPromise(new Error("Sign-in timeout"));
166
- }
167
- }, SIGN_IN_TIMEOUT_MS);
168
- // Start the authentication process
169
- const useIframeRef = iframeRef?.current || null;
170
- await authInitiator.signIn(useIframeRef);
171
- }
172
- catch (error) {
173
- // Reset the signing in flag on error
174
- isSigningInRef.current = false;
175
- if (error instanceof PopupError) {
176
- // Fallback to redirect if popup fails
177
- setIframeIsVisible(false);
178
- authInitiator.cleanup();
179
- authInitiator.setDisplayMode("redirect");
180
- try {
181
- // Call signIn again with redirect mode
182
- await authInitiator.signIn(iframeRef?.current || null);
183
- }
184
- catch (retryError) {
185
- console.error("[useSignIn] Redirect sign-in initiation error", retryError);
186
- rejectSignInPromise(retryError instanceof Error
187
- ? retryError
188
- : new Error(String(retryError)));
189
- return promise;
190
- }
191
- }
192
- else {
193
- rejectSignInPromise(error instanceof Error ? error : new Error(String(error)));
194
- return promise;
195
- }
196
- }
197
- return promise;
198
- }, [
199
- authInitiator,
200
- displayMode,
201
- iframeRef,
202
- setIframeIsVisible,
203
- authStatus,
204
- setAuthStatus,
205
- rejectSignInPromise,
206
- ]);
207
- // Public sign-in method
208
- const signIn = useCallback(async () => {
209
- if (displayMode === "iframe") {
210
- const result = await authInitiator?.handleUserInteractionBrowserCorsFailsSilently();
211
- setIframeIsVisible(!result?.isRedirecting);
212
- }
213
- return startSignIn();
214
- }, [displayMode, startSignIn, setIframeIsVisible, authInitiator]);
215
- // Sign-out method
216
- const signOut = useCallback(async () => {
217
- const idToken = session?.idToken;
218
- if (!authInitiator)
219
- return;
220
- setAuthStatus(AuthStatus.SIGNING_OUT);
221
- if (displayMode === "iframe") {
222
- setIframeIsVisible(false);
223
- setLogoutIframeIsVisible(true);
224
- }
225
- try {
226
- await preSignOut?.();
227
- const useIframeRef = logoutIframeRef?.current || null;
228
- await authInitiator.signOut(idToken, useIframeRef).catch((error) => {
229
- setAuthStatus(AuthStatus.ERROR);
230
- console.error("signOut error", {
231
- error,
232
- isPopupError: error instanceof PopupError,
233
- });
234
- if (error instanceof PopupError) {
235
- setLogoutIframeIsVisible(false);
236
- authInitiator.cleanup();
237
- authInitiator.setDisplayMode("redirect");
238
- authInitiator.signOut(idToken, useIframeRef); // Retry sign out
239
- }
240
- });
241
- }
242
- catch (error) {
243
- console.error("Signout error:", error);
244
- setAuthStatus(AuthStatus.ERROR);
245
- }
246
- }, [
247
- session?.idToken,
248
- authInitiator,
249
- displayMode,
250
- setLogoutIframeIsVisible,
251
- setIframeIsVisible,
252
- preSignOut,
253
- logoutIframeRef,
254
- setAuthStatus,
255
- ]);
256
- // Set up event listeners for authentication status
257
- useEffect(() => {
258
- // Update the ref with current auth status
259
- authStatusRef.current = authStatus;
260
- // Define handlers
261
- handlersRef.current = {
262
- handleSignInComplete: () => {
263
- if (authStatusRef.current === AuthStatus.AUTHENTICATING) {
264
- resolveSignInPromise();
265
- }
266
- },
267
- handleSignInError: (event) => {
268
- if (authStatusRef.current === AuthStatus.AUTHENTICATING) {
269
- const error = event.detail.error;
270
- rejectSignInPromise(error instanceof Error
271
- ? error
272
- : new Error(error.message || "Sign-in failed"));
273
- }
274
- },
275
- };
276
- // Add listeners only when in authenticating state
277
- if (authStatus === AuthStatus.AUTHENTICATING &&
278
- handlersRef.current.handleSignInComplete &&
279
- handlersRef.current.handleSignInError) {
280
- LocalStorageAdapter.emitter.on("civic-auth-signin-complete", handlersRef.current.handleSignInComplete);
281
- LocalStorageAdapter.emitter.on("civic-auth-signin-error", handlersRef.current.handleSignInError);
282
- }
283
- else if (authStatus !== AuthStatus.AUTHENTICATING &&
284
- timeoutRef.current !== null) {
285
- // Clean up timeout when not in authenticating state
286
- window.clearTimeout(timeoutRef.current);
287
- timeoutRef.current = null;
288
- }
289
- // Cleanup listeners
290
- return () => {
291
- if (handlersRef.current.handleSignInComplete) {
292
- LocalStorageAdapter.emitter.off("civic-auth-signin-complete", handlersRef.current.handleSignInComplete);
293
- }
294
- if (handlersRef.current.handleSignInError) {
295
- LocalStorageAdapter.emitter.off("civic-auth-signin-error", handlersRef.current.handleSignInError);
296
- }
297
- };
298
- }, [authStatus, resolveSignInPromise, rejectSignInPromise]);
299
- // Effect to handle session updates and iframe aborts
300
- useEffect(() => {
301
- // If session becomes authenticated, update state and resolve pending promises
302
- if (session?.authenticated &&
303
- authStatusRef.current !== AuthStatus.AUTHENTICATED) {
304
- setAuthStatus(AuthStatus.AUTHENTICATED);
305
- // If we have a pending sign-in promise, resolve it
306
- if (authStatusRef.current === AuthStatus.AUTHENTICATING &&
307
- signInResolveRef.current) {
308
- resolveSignInPromise();
309
- }
310
- }
311
- // Handle iframe abortion
312
- if (displayMode === "iframe" && iframeAborted) {
313
- setIframeAborted(false);
314
- if (authStatusRef.current === AuthStatus.AUTHENTICATING) {
315
- rejectSignInPromise(new Error("Sign-in aborted by user"), AuthStatus.UNAUTHENTICATED);
316
- }
317
- }
318
- // Update unauthenticated state when session is absent
319
- if (!session?.authenticated &&
320
- ![AuthStatus.AUTHENTICATING, AuthStatus.SIGNING_OUT].includes(authStatusRef.current)) {
321
- if (authStatusRef.current !== AuthStatus.UNAUTHENTICATED) {
322
- setAuthStatus(AuthStatus.UNAUTHENTICATED);
323
- }
324
- }
325
- }, [
326
- displayMode,
327
- iframeAborted,
328
- session?.authenticated,
329
- setIframeAborted,
330
- resolveSignInPromise,
331
- rejectSignInPromise,
332
- setAuthStatus,
333
- ]);
334
- // Handle logout completion
335
- useEffect(() => {
336
- if (authStatus === AuthStatus.SIGNING_OUT && !session?.authenticated) {
337
- setAuthStatus(AuthStatus.UNAUTHENTICATED);
338
- postSignOut?.().then(() => {
339
- setLogoutIframeIsVisible(false);
340
- });
341
- }
342
- }, [
343
- session,
344
- postSignOut,
345
- setLogoutIframeIsVisible,
346
- authStatus,
347
- setAuthStatus,
348
- ]);
349
- return {
350
- signIn,
351
- signOut,
352
- startSignIn,
353
- authStatus,
354
- displayMode,
355
- };
356
- };
357
- export { useSignIn };
358
- //# sourceMappingURL=useSignIn.js.map