@civic/auth 0.11.2 → 0.11.3-alpha.1

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 (57) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/nextjs/NextClientAuthenticationRefresher.d.ts +8 -0
  6. package/dist/nextjs/NextClientAuthenticationRefresher.d.ts.map +1 -0
  7. package/dist/nextjs/NextClientAuthenticationRefresher.js +24 -0
  8. package/dist/nextjs/NextClientAuthenticationRefresher.js.map +1 -0
  9. package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts +12 -0
  10. package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts.map +1 -0
  11. package/dist/nextjs/NextServerAuthenticationRefresherImpl.js +25 -0
  12. package/dist/nextjs/NextServerAuthenticationRefresherImpl.js.map +1 -0
  13. package/dist/nextjs/hooks/useRefresh.d.ts +5 -0
  14. package/dist/nextjs/hooks/useRefresh.d.ts.map +1 -0
  15. package/dist/nextjs/hooks/useRefresh.js +57 -0
  16. package/dist/nextjs/hooks/useRefresh.js.map +1 -0
  17. package/dist/nextjs/providers/NextAuthProvider.d.ts +1 -1
  18. package/dist/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
  19. package/dist/nextjs/providers/NextAuthProvider.js.map +1 -1
  20. package/dist/nextjs/providers/NextAuthProviderClient.d.ts.map +1 -1
  21. package/dist/nextjs/providers/NextAuthProviderClient.js +2 -3
  22. package/dist/nextjs/providers/NextAuthProviderClient.js.map +1 -1
  23. package/dist/react-router-7/auth-loader.d.ts +18 -0
  24. package/dist/react-router-7/auth-loader.d.ts.map +1 -0
  25. package/dist/react-router-7/auth-loader.js +36 -0
  26. package/dist/react-router-7/auth-loader.js.map +1 -0
  27. package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
  28. package/dist/reactjs/core/GlobalAuthManager.js +18 -0
  29. package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
  30. package/dist/reactjs/providers/CivicAuthContext.d.ts +44 -0
  31. package/dist/reactjs/providers/CivicAuthContext.d.ts.map +1 -0
  32. package/dist/reactjs/providers/CivicAuthContext.js +313 -0
  33. package/dist/reactjs/providers/CivicAuthContext.js.map +1 -0
  34. package/dist/reactjs/providers/index.d.ts +0 -3
  35. package/dist/reactjs/providers/index.d.ts.map +1 -1
  36. package/dist/reactjs/providers/index.js +0 -4
  37. package/dist/reactjs/providers/index.js.map +1 -1
  38. package/dist/shared/hooks/index.d.ts +0 -7
  39. package/dist/shared/hooks/index.d.ts.map +1 -1
  40. package/dist/shared/hooks/index.js +0 -7
  41. package/dist/shared/hooks/index.js.map +1 -1
  42. package/dist/shared/hooks/useRefresh.d.ts +6 -0
  43. package/dist/shared/hooks/useRefresh.d.ts.map +1 -0
  44. package/dist/shared/hooks/useRefresh.js +47 -0
  45. package/dist/shared/hooks/useRefresh.js.map +1 -0
  46. package/dist/shared/version.d.ts +1 -1
  47. package/dist/shared/version.d.ts.map +1 -1
  48. package/dist/shared/version.js +1 -1
  49. package/dist/shared/version.js.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -0
  51. package/dist/types.d.ts +9 -0
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/types.js.map +1 -1
  54. package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -1
  55. package/dist/vanillajs/auth/CivicAuth.js +4 -0
  56. package/dist/vanillajs/auth/CivicAuth.js.map +1 -1
  57. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC","sourcesContent":["export { useToken } from \"@/shared/hooks/useToken.js\";\nexport { useSession } from \"@/shared/hooks/useSession.js\";\nexport { useCivicAuthConfig } from \"@/shared/hooks/useCivicAuthConfig.js\";\nexport { useOAuthEndpoints } from \"@/shared/hooks/useOAuthEndpoints.js\";\nexport { useCurrentUrl } from \"@/shared/hooks/useCurrentUrl.js\";\nexport { useClientTokenExchangeSession } from \"@/shared/hooks/useClientTokenExchangeSession.js\";\nexport { useWindowFocused } from \"@/shared/hooks/useWindowFocused.js\";\nexport { useBfcacheHandler } from \"@/shared/hooks/useBfcacheHandler.js\";\n\nexport { useAuthStatus } from \"@/shared/providers/AuthStatusContext.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC","sourcesContent":["export { useBfcacheHandler } from \"@/shared/hooks/useBfcacheHandler.js\";\n\nexport { useAuthStatus } from \"@/shared/providers/AuthStatusContext.js\";\n"]}
@@ -0,0 +1,6 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,47 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRefresh.js","sourceRoot":"","sources":["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AY,CAAC,YAAY,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,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,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,uCAAuC;IAElE,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;IACxC,OAAO;QACL,KAAK;KACN,CAAC;AACJ,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"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "@civic/auth:0.11.2";
1
+ export declare const VERSION = "@civic/auth:0.11.3-alpha.1";
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,uBAAuB,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,+BAA+B,CAAC"}
@@ -1,3 +1,3 @@
1
1
  // This is an auto-generated file. Do not edit.
2
- export const VERSION = "@civic/auth:0.11.2";
2
+ export const VERSION = "@civic/auth:0.11.3-alpha.1";
3
3
  //# sourceMappingURL=version.js.map
@@ -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,oBAAoB,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.11.2\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.11.3-alpha.1\";\n"]}