@civic/auth 0.10.0-beta.9 → 0.10.0

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 (47) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/lib/logger.d.ts +1 -0
  3. package/dist/lib/logger.d.ts.map +1 -1
  4. package/dist/lib/logger.js +1 -0
  5. package/dist/lib/logger.js.map +1 -1
  6. package/dist/nextjs/hooks/useInitialAuthConfig.d.ts.map +1 -1
  7. package/dist/nextjs/hooks/useInitialAuthConfig.js +16 -4
  8. package/dist/nextjs/hooks/useInitialAuthConfig.js.map +1 -1
  9. package/dist/nextjs/utils.d.ts.map +1 -1
  10. package/dist/nextjs/utils.js +8 -3
  11. package/dist/nextjs/utils.js.map +1 -1
  12. package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
  13. package/dist/reactjs/core/GlobalAuthManager.js +1 -1
  14. package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
  15. package/dist/shared/hooks/index.d.ts +0 -1
  16. package/dist/shared/hooks/index.d.ts.map +1 -1
  17. package/dist/shared/hooks/index.js +0 -1
  18. package/dist/shared/hooks/index.js.map +1 -1
  19. package/dist/shared/lib/BrowserAuthenticationRefresher.d.ts.map +1 -1
  20. package/dist/shared/lib/BrowserAuthenticationRefresher.js +8 -5
  21. package/dist/shared/lib/BrowserAuthenticationRefresher.js.map +1 -1
  22. package/dist/shared/lib/GenericAuthenticationRefresher.d.ts +1 -0
  23. package/dist/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
  24. package/dist/shared/lib/GenericAuthenticationRefresher.js +2 -0
  25. package/dist/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
  26. package/dist/shared/version.d.ts +1 -1
  27. package/dist/shared/version.d.ts.map +1 -1
  28. package/dist/shared/version.js +1 -1
  29. package/dist/shared/version.js.map +1 -1
  30. package/dist/vanillajs/auth/BackendAuthenticationRefresher.d.ts.map +1 -1
  31. package/dist/vanillajs/auth/BackendAuthenticationRefresher.js +8 -4
  32. package/dist/vanillajs/auth/BackendAuthenticationRefresher.js.map +1 -1
  33. package/dist/vanillajs/auth/SessionManager.js +2 -2
  34. package/dist/vanillajs/auth/SessionManager.js.map +1 -1
  35. package/dist/vanillajs/auth/TokenRefresher.d.ts +3 -0
  36. package/dist/vanillajs/auth/TokenRefresher.d.ts.map +1 -1
  37. package/dist/vanillajs/auth/TokenRefresher.js +24 -1
  38. package/dist/vanillajs/auth/TokenRefresher.js.map +1 -1
  39. package/package.json +1 -1
  40. package/dist/nextjs/hooks/useRefresh.d.ts +0 -5
  41. package/dist/nextjs/hooks/useRefresh.d.ts.map +0 -1
  42. package/dist/nextjs/hooks/useRefresh.js +0 -57
  43. package/dist/nextjs/hooks/useRefresh.js.map +0 -1
  44. package/dist/shared/hooks/useRefresh.d.ts +0 -6
  45. package/dist/shared/hooks/useRefresh.d.ts.map +0 -1
  46. package/dist/shared/hooks/useRefresh.js +0 -47
  47. package/dist/shared/hooks/useRefresh.js.map +0 -1
@@ -1,5 +0,0 @@
1
- declare const useRefresh: () => {
2
- error: Error | undefined;
3
- };
4
- export { useRefresh };
5
- //# sourceMappingURL=useRefresh.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRefresh.d.ts","sourceRoot":"","sources":["../../../src/nextjs/hooks/useRefresh.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,UAAU;;CAwDf,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,57 +0,0 @@
1
- import { useCivicAuthConfig } from "../../shared/hooks/useCivicAuthConfig.js";
2
- import { useEffect, useState } from "react";
3
- import { BrowserCookieStorage } from "../../shared/index.js";
4
- import { resolveAuthConfig } from "../config.js";
5
- import { NextClientAuthenticationRefresher } from "../NextClientAuthenticationRefresher.js";
6
- import { useSession } from "../../shared/hooks/useSession.js";
7
- const useRefresh = () => {
8
- const [error, setError] = useState();
9
- const { data: session } = useSession();
10
- const authConfig = useCivicAuthConfig();
11
- // setup token autorefresh
12
- const [refresher, setRefresher] = useState(undefined);
13
- useEffect(() => {
14
- if (!authConfig)
15
- return;
16
- const abortController = new AbortController();
17
- const currentRefresher = refresher;
18
- const config = resolveAuthConfig(authConfig ?? {});
19
- const storage = new BrowserCookieStorage(config.cookies.tokens.access_token);
20
- const onError = async (error) => {
21
- console.error("Error refreshing token", error);
22
- refresher?.clearAutorefresh();
23
- setError(error);
24
- };
25
- NextClientAuthenticationRefresher.build({ ...authConfig }, storage, onError)
26
- .then((newRefresher) => {
27
- if (abortController.signal.aborted)
28
- return;
29
- currentRefresher?.clearAutorefresh();
30
- setRefresher(newRefresher);
31
- })
32
- .catch((error) => {
33
- if (abortController.signal.aborted)
34
- return;
35
- setError(error);
36
- });
37
- return () => {
38
- abortController.abort();
39
- currentRefresher?.clearAutorefresh();
40
- };
41
- // eslint-disable-next-line react-hooks/exhaustive-deps
42
- }, [authConfig]); // Only depend on what actually changes
43
- useEffect(() => {
44
- if (session?.authenticated) {
45
- refresher?.setupAutorefresh();
46
- }
47
- else {
48
- refresher?.clearAutorefresh();
49
- }
50
- return () => refresher?.clearAutorefresh();
51
- }, [refresher, session?.authenticated]);
52
- return {
53
- error,
54
- };
55
- };
56
- export { useRefresh };
57
- //# sourceMappingURL=useRefresh.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRefresh.js","sourceRoot":"","sources":["../../../src/nextjs/hooks/useRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC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AAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,eAAe,CAAC,KAAK,EAAE,CAAC;YACxB,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;QACvC,CAAC,CAAC;QACF,uDAAuD;IACzD,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,uCAAuC;IAEzD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;YAC3B,SAAS,EAAE,gBAAgB,EAAE,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,SAAS,EAAE,gBAAgB,EAAE,CAAC;QAChC,CAAC;QAED,OAAO,GAAG,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC7C,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;IAExC,OAAO;QACL,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { useCivicAuthConfig } from \"@/shared/hooks/useCivicAuthConfig.js\";\nimport { useEffect, useState } from \"react\";\nimport { BrowserCookieStorage } from \"@/shared/index.js\";\nimport { resolveAuthConfig } from \"../config.js\";\nimport { NextClientAuthenticationRefresher } from \"../NextClientAuthenticationRefresher.js\";\nimport { useSession } from \"@/shared/hooks/useSession.js\";\n\nconst useRefresh = () => {\n const [error, setError] = useState<Error>();\n const { data: session } = useSession();\n const authConfig = useCivicAuthConfig();\n\n // setup token autorefresh\n const [refresher, setRefresher] = useState<\n NextClientAuthenticationRefresher | undefined\n >(undefined);\n\n useEffect(() => {\n if (!authConfig) return;\n const abortController = new AbortController();\n const currentRefresher = refresher;\n const config = resolveAuthConfig(authConfig ?? {});\n const storage = new BrowserCookieStorage(\n config.cookies.tokens.access_token,\n );\n const onError = async (error: Error) => {\n console.error(\"Error refreshing token\", error);\n refresher?.clearAutorefresh();\n setError(error);\n };\n\n NextClientAuthenticationRefresher.build({ ...authConfig }, storage, onError)\n .then((newRefresher) => {\n if (abortController.signal.aborted) return;\n\n currentRefresher?.clearAutorefresh();\n setRefresher(newRefresher);\n })\n .catch((error: Error) => {\n if (abortController.signal.aborted) return;\n setError(error);\n });\n\n return () => {\n abortController.abort();\n currentRefresher?.clearAutorefresh();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [authConfig]); // Only depend on what actually changes\n\n useEffect(() => {\n if (session?.authenticated) {\n refresher?.setupAutorefresh();\n } else {\n refresher?.clearAutorefresh();\n }\n\n return () => refresher?.clearAutorefresh();\n }, [refresher, session?.authenticated]);\n\n return {\n error,\n };\n};\n\nexport { useRefresh };\n"]}
@@ -1,6 +0,0 @@
1
- import type { SessionData } from "../../types.js";
2
- declare const useRefresh: (session: SessionData | null) => {
3
- error: Error | undefined;
4
- };
5
- export { useRefresh };
6
- //# sourceMappingURL=useRefresh.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRefresh.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useRefresh.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,QAAA,MAAM,UAAU,YAAa,WAAW,GAAG,IAAI;;CAiD9C,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,47 +0,0 @@
1
- import { useEffect, useMemo, useState } from "react";
2
- import { useCivicAuthConfig } from "./useCivicAuthConfig.js";
3
- import { LocalStorageAdapter } from "../../browser/storage.js";
4
- import { BrowserAuthenticationRefresher } from "../lib/BrowserAuthenticationRefresher.js";
5
- const useRefresh = (session) => {
6
- const authConfig = useCivicAuthConfig();
7
- const storage = useMemo(() => new LocalStorageAdapter(), []);
8
- const [error, setError] = useState();
9
- // setup token autorefresh
10
- const [refresher, setRefresher] = useState(undefined);
11
- useEffect(() => {
12
- if (!authConfig)
13
- return;
14
- const abortController = new AbortController();
15
- const currentRefresher = refresher;
16
- const onError = async (error) => {
17
- console.error("Error refreshing token", error);
18
- refresher?.clearAutorefresh();
19
- setError(error);
20
- };
21
- BrowserAuthenticationRefresher.build({ ...authConfig }, storage, onError).then((newRefresher) => {
22
- if (abortController.signal.aborted)
23
- return;
24
- currentRefresher?.clearAutorefresh();
25
- setRefresher(newRefresher);
26
- });
27
- return () => {
28
- abortController.abort();
29
- currentRefresher?.clearAutorefresh();
30
- };
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
32
- }, [authConfig, storage]); // Only depend on what actually changes
33
- useEffect(() => {
34
- if (session?.authenticated) {
35
- refresher?.setupAutorefresh();
36
- }
37
- else {
38
- refresher?.clearAutorefresh();
39
- }
40
- return () => refresher?.clearAutorefresh();
41
- }, [refresher, session?.authenticated]);
42
- return {
43
- error,
44
- };
45
- };
46
- export { useRefresh };
47
- //# sourceMappingURL=useRefresh.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRefresh.js","sourceRoot":"","sources":["../../../src/shared/hooks/useRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,0CAA0C,CAAC;AAE1F,MAAM,UAAU,GAAG,CAAC,OAA2B,EAAE,EAAE;IACjD,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAC;IAC5C,0BAA0B;IAC1B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAExC,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,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport { useCivicAuthConfig } from \"./useCivicAuthConfig.js\";\nimport type { SessionData } from \"@/types.js\";\nimport { LocalStorageAdapter } from \"@/browser/storage.js\";\nimport { BrowserAuthenticationRefresher } from \"../lib/BrowserAuthenticationRefresher.js\";\n\nconst useRefresh = (session: SessionData | null) => {\n const authConfig = useCivicAuthConfig();\n const storage = useMemo(() => new LocalStorageAdapter(), []);\n const [error, setError] = useState<Error>();\n // setup token autorefresh\n const [refresher, setRefresher] = useState<\n BrowserAuthenticationRefresher | undefined\n >(undefined);\n\n useEffect(() => {\n if (!authConfig) return;\n const abortController = new AbortController();\n const currentRefresher = refresher;\n\n const onError = async (error: Error) => {\n console.error(\"Error refreshing token\", error);\n refresher?.clearAutorefresh();\n setError(error);\n };\n BrowserAuthenticationRefresher.build(\n { ...authConfig },\n storage,\n onError,\n ).then((newRefresher) => {\n if (abortController.signal.aborted) return;\n\n currentRefresher?.clearAutorefresh();\n setRefresher(newRefresher);\n });\n\n return () => {\n abortController.abort();\n currentRefresher?.clearAutorefresh();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [authConfig, storage]); // Only depend on what actually changes\n\n useEffect(() => {\n if (session?.authenticated) {\n refresher?.setupAutorefresh();\n } else {\n refresher?.clearAutorefresh();\n }\n\n return () => refresher?.clearAutorefresh();\n }, [refresher, session?.authenticated]);\n return {\n error,\n };\n};\n\nexport { useRefresh };\n"]}