@civic/auth 0.1.4-beta.2 → 0.1.4-beta.3

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 (269) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/README.md +8 -10
  3. package/dist/cjs/index.d.ts.map +1 -1
  4. package/dist/cjs/index.js +5 -0
  5. package/dist/cjs/index.js.map +1 -1
  6. package/dist/cjs/nextjs/index.d.ts.map +1 -1
  7. package/dist/cjs/nextjs/index.js +2 -0
  8. package/dist/cjs/nextjs/index.js.map +1 -1
  9. package/dist/cjs/nextjs/providers/NextAuthProvider.js +2 -2
  10. package/dist/cjs/nextjs/providers/NextAuthProvider.js.map +1 -1
  11. package/dist/cjs/reactjs/index.d.ts.map +1 -1
  12. package/dist/cjs/reactjs/index.js +2 -0
  13. package/dist/cjs/reactjs/index.js.map +1 -1
  14. package/dist/cjs/server/index.d.ts.map +1 -1
  15. package/dist/cjs/server/index.js +2 -0
  16. package/dist/cjs/server/index.js.map +1 -1
  17. package/dist/cjs/shared/components/IFrameAndLoading.d.ts.map +1 -1
  18. package/dist/cjs/shared/components/IFrameAndLoading.js +3 -3
  19. package/dist/cjs/shared/components/IFrameAndLoading.js.map +1 -1
  20. package/dist/cjs/version.d.ts +2 -0
  21. package/dist/cjs/version.d.ts.map +1 -0
  22. package/dist/cjs/version.js +6 -0
  23. package/dist/cjs/version.js.map +1 -0
  24. package/dist/esm/index.d.ts.map +1 -1
  25. package/dist/esm/index.js +5 -1
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/nextjs/index.d.ts.map +1 -1
  28. package/dist/esm/nextjs/index.js +2 -0
  29. package/dist/esm/nextjs/index.js.map +1 -1
  30. package/dist/esm/nextjs/providers/NextAuthProvider.js +1 -1
  31. package/dist/esm/nextjs/providers/NextAuthProvider.js.map +1 -1
  32. package/dist/esm/reactjs/index.d.ts.map +1 -1
  33. package/dist/esm/reactjs/index.js +2 -0
  34. package/dist/esm/reactjs/index.js.map +1 -1
  35. package/dist/esm/server/index.d.ts.map +1 -1
  36. package/dist/esm/server/index.js +2 -0
  37. package/dist/esm/server/index.js.map +1 -1
  38. package/dist/esm/shared/components/IFrameAndLoading.d.ts.map +1 -1
  39. package/dist/esm/shared/components/IFrameAndLoading.js +3 -3
  40. package/dist/esm/shared/components/IFrameAndLoading.js.map +1 -1
  41. package/dist/esm/version.d.ts +2 -0
  42. package/dist/esm/version.d.ts.map +1 -0
  43. package/dist/esm/version.js +3 -0
  44. package/dist/esm/version.js.map +1 -0
  45. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  46. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  47. package/package.json +9 -6
  48. package/dist/src/browser/storage.d.ts +0 -9
  49. package/dist/src/browser/storage.d.ts.map +0 -1
  50. package/dist/src/browser/storage.js +0 -17
  51. package/dist/src/browser/storage.js.map +0 -1
  52. package/dist/src/config.d.ts.map +0 -1
  53. package/dist/src/index.d.ts.map +0 -1
  54. package/dist/src/lib/cookies.d.ts +0 -7
  55. package/dist/src/lib/cookies.d.ts.map +0 -1
  56. package/dist/src/lib/cookies.js +0 -25
  57. package/dist/src/lib/cookies.js.map +0 -1
  58. package/dist/src/lib/jwt.d.ts.map +0 -1
  59. package/dist/src/lib/oauth.d.ts.map +0 -1
  60. package/dist/src/lib/postMessage.d.ts.map +0 -1
  61. package/dist/src/lib/postMessage.js +0 -15
  62. package/dist/src/lib/postMessage.js.map +0 -1
  63. package/dist/src/lib/windowUtil.d.ts.map +0 -1
  64. package/dist/src/lib/windowUtil.js +0 -31
  65. package/dist/src/lib/windowUtil.js.map +0 -1
  66. package/dist/src/nextjs/GetUser.d.ts.map +0 -1
  67. package/dist/src/nextjs/GetUser.js +0 -7
  68. package/dist/src/nextjs/GetUser.js.map +0 -1
  69. package/dist/src/nextjs/config.d.ts.map +0 -1
  70. package/dist/src/nextjs/config.js +0 -173
  71. package/dist/src/nextjs/config.js.map +0 -1
  72. package/dist/src/nextjs/cookies.d.ts.map +0 -1
  73. package/dist/src/nextjs/hooks/index.d.ts +0 -2
  74. package/dist/src/nextjs/hooks/index.d.ts.map +0 -1
  75. package/dist/src/nextjs/hooks/index.js +0 -2
  76. package/dist/src/nextjs/hooks/index.js.map +0 -1
  77. package/dist/src/nextjs/hooks/useRefresh.d.ts +0 -4
  78. package/dist/src/nextjs/hooks/useRefresh.d.ts.map +0 -1
  79. package/dist/src/nextjs/hooks/useRefresh.js +0 -38
  80. package/dist/src/nextjs/hooks/useRefresh.js.map +0 -1
  81. package/dist/src/nextjs/hooks/useTokenCookie.d.ts +0 -3
  82. package/dist/src/nextjs/hooks/useTokenCookie.d.ts.map +0 -1
  83. package/dist/src/nextjs/hooks/useTokenCookie.js +0 -37
  84. package/dist/src/nextjs/hooks/useTokenCookie.js.map +0 -1
  85. package/dist/src/nextjs/hooks/useUserCookie.d.ts +0 -6
  86. package/dist/src/nextjs/hooks/useUserCookie.d.ts.map +0 -1
  87. package/dist/src/nextjs/hooks/useUserCookie.js +0 -64
  88. package/dist/src/nextjs/hooks/useUserCookie.js.map +0 -1
  89. package/dist/src/nextjs/index.d.ts.map +0 -1
  90. package/dist/src/nextjs/middleware/index.d.ts.map +0 -1
  91. package/dist/src/nextjs/middleware.d.ts.map +0 -1
  92. package/dist/src/nextjs/providers/NextAuthProvider.d.ts +0 -13
  93. package/dist/src/nextjs/providers/NextAuthProvider.d.ts.map +0 -1
  94. package/dist/src/nextjs/providers/NextAuthProvider.js +0 -79
  95. package/dist/src/nextjs/providers/NextAuthProvider.js.map +0 -1
  96. package/dist/src/nextjs/routeHandler.d.ts.map +0 -1
  97. package/dist/src/nextjs/routeHandler.js +0 -212
  98. package/dist/src/nextjs/routeHandler.js.map +0 -1
  99. package/dist/src/nextjs/utils.d.ts.map +0 -1
  100. package/dist/src/reactjs/components/SignInButton.d.ts.map +0 -1
  101. package/dist/src/reactjs/components/SignOutButton.d.ts.map +0 -1
  102. package/dist/src/reactjs/components/UserButton.d.ts.map +0 -1
  103. package/dist/src/reactjs/components/UserButton.js +0 -118
  104. package/dist/src/reactjs/components/UserButton.js.map +0 -1
  105. package/dist/src/reactjs/components/index.d.ts.map +0 -1
  106. package/dist/src/reactjs/hooks/index.d.ts +0 -6
  107. package/dist/src/reactjs/hooks/index.d.ts.map +0 -1
  108. package/dist/src/reactjs/hooks/index.js +0 -6
  109. package/dist/src/reactjs/hooks/index.js.map +0 -1
  110. package/dist/src/reactjs/hooks/useAuth.d.ts.map +0 -1
  111. package/dist/src/reactjs/hooks/useRefresh.d.ts +0 -4
  112. package/dist/src/reactjs/hooks/useRefresh.d.ts.map +0 -1
  113. package/dist/src/reactjs/hooks/useRefresh.js +0 -28
  114. package/dist/src/reactjs/hooks/useRefresh.js.map +0 -1
  115. package/dist/src/reactjs/hooks/useUser.d.ts.map +0 -1
  116. package/dist/src/reactjs/index.d.ts.map +0 -1
  117. package/dist/src/reactjs/providers/index.d.ts.map +0 -1
  118. package/dist/src/server/ServerAuthenticationResolver.d.ts.map +0 -1
  119. package/dist/src/server/config.d.ts.map +0 -1
  120. package/dist/src/server/index.d.ts.map +0 -1
  121. package/dist/src/server/login.d.ts.map +0 -1
  122. package/dist/src/server/refresh.d.ts.map +0 -1
  123. package/dist/src/services/AuthenticationService.d.ts +0 -90
  124. package/dist/src/services/AuthenticationService.d.ts.map +0 -1
  125. package/dist/src/services/AuthenticationService.js +0 -243
  126. package/dist/src/services/AuthenticationService.js.map +0 -1
  127. package/dist/src/services/PKCE.d.ts.map +0 -1
  128. package/dist/src/services/types.d.ts.map +0 -1
  129. package/dist/src/shared/components/BlockDisplay.d.ts +0 -7
  130. package/dist/src/shared/components/BlockDisplay.d.ts.map +0 -1
  131. package/dist/src/shared/components/BlockDisplay.js +0 -25
  132. package/dist/src/shared/components/BlockDisplay.js.map +0 -1
  133. package/dist/src/shared/components/CivicAuthIframe.d.ts.map +0 -1
  134. package/dist/src/shared/components/CivicAuthIframe.js +0 -9
  135. package/dist/src/shared/components/CivicAuthIframe.js.map +0 -1
  136. package/dist/src/shared/components/CivicAuthIframeContainer.d.ts.map +0 -1
  137. package/dist/src/shared/components/CivicAuthIframeContainer.js +0 -138
  138. package/dist/src/shared/components/CivicAuthIframeContainer.js.map +0 -1
  139. package/dist/src/shared/components/IFrameAndLoading.d.ts +0 -7
  140. package/dist/src/shared/components/IFrameAndLoading.d.ts.map +0 -1
  141. package/dist/src/shared/components/IFrameAndLoading.js +0 -22
  142. package/dist/src/shared/components/IFrameAndLoading.js.map +0 -1
  143. package/dist/src/shared/hooks/index.d.ts +0 -9
  144. package/dist/src/shared/hooks/index.d.ts.map +0 -1
  145. package/dist/src/shared/hooks/index.js +0 -9
  146. package/dist/src/shared/hooks/index.js.map +0 -1
  147. package/dist/src/shared/hooks/useAuth.d.ts.map +0 -1
  148. package/dist/src/shared/hooks/useCivicAuthConfig.d.ts +0 -3
  149. package/dist/src/shared/hooks/useCivicAuthConfig.d.ts.map +0 -1
  150. package/dist/src/shared/hooks/useCivicAuthConfig.js +0 -10
  151. package/dist/src/shared/hooks/useCivicAuthConfig.js.map +0 -1
  152. package/dist/src/shared/hooks/useClientTokenExchangeSession.d.ts +0 -3
  153. package/dist/src/shared/hooks/useClientTokenExchangeSession.d.ts.map +0 -1
  154. package/dist/src/shared/hooks/useClientTokenExchangeSession.js +0 -13
  155. package/dist/src/shared/hooks/useClientTokenExchangeSession.js.map +0 -1
  156. package/dist/src/shared/hooks/useConfig.d.ts +0 -3
  157. package/dist/src/shared/hooks/useConfig.d.ts.map +0 -1
  158. package/dist/src/shared/hooks/useConfig.js +0 -13
  159. package/dist/src/shared/hooks/useConfig.js.map +0 -1
  160. package/dist/src/shared/hooks/useCurrentUrl.d.ts +0 -3
  161. package/dist/src/shared/hooks/useCurrentUrl.d.ts.map +0 -1
  162. package/dist/src/shared/hooks/useCurrentUrl.js +0 -24
  163. package/dist/src/shared/hooks/useCurrentUrl.js.map +0 -1
  164. package/dist/src/shared/hooks/useIframe.d.ts.map +0 -1
  165. package/dist/src/shared/hooks/useIsInIframe.d.ts +0 -3
  166. package/dist/src/shared/hooks/useIsInIframe.d.ts.map +0 -1
  167. package/dist/src/shared/hooks/useIsInIframe.js +0 -14
  168. package/dist/src/shared/hooks/useIsInIframe.js.map +0 -1
  169. package/dist/src/shared/hooks/useOAuthEndpoints.d.ts +0 -4
  170. package/dist/src/shared/hooks/useOAuthEndpoints.d.ts.map +0 -1
  171. package/dist/src/shared/hooks/useOAuthEndpoints.js +0 -14
  172. package/dist/src/shared/hooks/useOAuthEndpoints.js.map +0 -1
  173. package/dist/src/shared/hooks/useRefresh.d.ts +0 -4
  174. package/dist/src/shared/hooks/useRefresh.d.ts.map +0 -1
  175. package/dist/src/shared/hooks/useRefresh.js +0 -38
  176. package/dist/src/shared/hooks/useRefresh.js.map +0 -1
  177. package/dist/src/shared/hooks/useSession.d.ts +0 -3
  178. package/dist/src/shared/hooks/useSession.d.ts.map +0 -1
  179. package/dist/src/shared/hooks/useSignIn.d.ts +0 -14
  180. package/dist/src/shared/hooks/useSignIn.d.ts.map +0 -1
  181. package/dist/src/shared/hooks/useSignIn.js +0 -71
  182. package/dist/src/shared/hooks/useSignIn.js.map +0 -1
  183. package/dist/src/shared/hooks/useToken.d.ts.map +0 -1
  184. package/dist/src/shared/lib/GenericAuthenticationRefresher.d.ts +0 -20
  185. package/dist/src/shared/lib/GenericAuthenticationRefresher.d.ts.map +0 -1
  186. package/dist/src/shared/lib/GenericAuthenticationRefresher.js +0 -73
  187. package/dist/src/shared/lib/GenericAuthenticationRefresher.js.map +0 -1
  188. package/dist/src/shared/lib/UserSession.d.ts.map +0 -1
  189. package/dist/src/shared/lib/session.d.ts +0 -3
  190. package/dist/src/shared/lib/session.d.ts.map +0 -1
  191. package/dist/src/shared/lib/session.js +0 -21
  192. package/dist/src/shared/lib/session.js.map +0 -1
  193. package/dist/src/shared/lib/storage.d.ts.map +0 -1
  194. package/dist/src/shared/lib/types.d.ts +0 -35
  195. package/dist/src/shared/lib/types.d.ts.map +0 -1
  196. package/dist/src/shared/lib/types.js +0 -18
  197. package/dist/src/shared/lib/types.js.map +0 -1
  198. package/dist/src/shared/lib/util.d.ts.map +0 -1
  199. package/dist/src/shared/lib/util.js +0 -133
  200. package/dist/src/shared/lib/util.js.map +0 -1
  201. package/dist/src/shared/providers/AuthContext.d.ts.map +0 -1
  202. package/dist/src/shared/providers/AuthProvider.d.ts +0 -21
  203. package/dist/src/shared/providers/AuthProvider.d.ts.map +0 -1
  204. package/dist/src/shared/providers/AuthProvider.js +0 -63
  205. package/dist/src/shared/providers/AuthProvider.js.map +0 -1
  206. package/dist/src/shared/providers/CivicAuthConfigContext.d.ts +0 -16
  207. package/dist/src/shared/providers/CivicAuthConfigContext.d.ts.map +0 -1
  208. package/dist/src/shared/providers/CivicAuthConfigContext.js +0 -43
  209. package/dist/src/shared/providers/CivicAuthConfigContext.js.map +0 -1
  210. package/dist/src/shared/providers/CivicAuthProvider.d.ts.map +0 -1
  211. package/dist/src/shared/providers/CivicAuthProvider.js +0 -32
  212. package/dist/src/shared/providers/CivicAuthProvider.js.map +0 -1
  213. package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.d.ts +0 -17
  214. package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.d.ts.map +0 -1
  215. package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.js +0 -146
  216. package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.js.map +0 -1
  217. package/dist/src/shared/providers/ConfigProvider.d.ts +0 -21
  218. package/dist/src/shared/providers/ConfigProvider.d.ts.map +0 -1
  219. package/dist/src/shared/providers/ConfigProvider.js +0 -19
  220. package/dist/src/shared/providers/ConfigProvider.js.map +0 -1
  221. package/dist/src/shared/providers/IframeProvider.d.ts +0 -19
  222. package/dist/src/shared/providers/IframeProvider.d.ts.map +0 -1
  223. package/dist/src/shared/providers/IframeProvider.js +0 -29
  224. package/dist/src/shared/providers/IframeProvider.js.map +0 -1
  225. package/dist/src/shared/providers/SessionProvider.d.ts +0 -19
  226. package/dist/src/shared/providers/SessionProvider.d.ts.map +0 -1
  227. package/dist/src/shared/providers/SessionProvider.js +0 -23
  228. package/dist/src/shared/providers/SessionProvider.js.map +0 -1
  229. package/dist/src/shared/providers/TokenProvider.d.ts.map +0 -1
  230. package/dist/src/shared/providers/TokenProvider.js +0 -42
  231. package/dist/src/shared/providers/TokenProvider.js.map +0 -1
  232. package/dist/src/shared/providers/UserProvider.d.ts +0 -20
  233. package/dist/src/shared/providers/UserProvider.d.ts.map +0 -1
  234. package/dist/src/shared/providers/UserProvider.js +0 -51
  235. package/dist/src/shared/providers/UserProvider.js.map +0 -1
  236. package/dist/src/types.d.ts +0 -146
  237. package/dist/src/types.d.ts.map +0 -1
  238. package/dist/src/types.js +0 -4
  239. package/dist/src/types.js.map +0 -1
  240. package/dist/test/integration/sdk.test.d.ts.map +0 -1
  241. package/dist/test/integration/sdk.test.js +0 -189
  242. package/dist/test/integration/sdk.test.js.map +0 -1
  243. package/dist/test/unit/lib/oauth.test.d.ts.map +0 -1
  244. package/dist/test/unit/nextjs/NextAuthProvider.test.d.ts.map +0 -1
  245. package/dist/test/unit/nextjs/NextAuthProvider.test.js +0 -31
  246. package/dist/test/unit/nextjs/NextAuthProvider.test.js.map +0 -1
  247. package/dist/test/unit/nextjs/config.test.d.ts.map +0 -1
  248. package/dist/test/unit/nextjs/getUser.test.d.ts.map +0 -1
  249. package/dist/test/unit/nextjs/getUser.test.js +0 -22
  250. package/dist/test/unit/nextjs/getUser.test.js.map +0 -1
  251. package/dist/test/unit/nextjs/middleware.test.d.ts.map +0 -1
  252. package/dist/test/unit/nextjs/utils.test.d.ts.map +0 -1
  253. package/dist/test/unit/publicApi/apiSnapshot.test.d.ts.map +0 -1
  254. package/dist/test/unit/react/components/SignInButton.test.d.ts.map +0 -1
  255. package/dist/test/unit/react/components/SignOutButton.test.d.ts.map +0 -1
  256. package/dist/test/unit/server/login.test.d.ts.map +0 -1
  257. package/dist/test/unit/server/refresh.test.d.ts.map +0 -1
  258. package/dist/test/unit/server/session.test.d.ts.map +0 -1
  259. package/dist/test/unit/services/AuthenticationService.test.d.ts.map +0 -1
  260. package/dist/test/unit/services/AuthenticationService.test.js +0 -121
  261. package/dist/test/unit/services/AuthenticationService.test.js.map +0 -1
  262. package/dist/test/unit/services/ServerAuthenticationResolver.test.d.ts.map +0 -1
  263. package/dist/test/unit/shared/GenericAuthenticationRefresher.test.d.ts.map +0 -1
  264. package/dist/test/unit/shared/UserSession.test.d.ts.map +0 -1
  265. package/dist/test/unit/shared/components/CivicAuthIframeContainer.test.d.ts.map +0 -1
  266. package/dist/test/unit/shared/components/CivicAuthIframeContainer.test.js +0 -122
  267. package/dist/test/unit/shared/components/CivicAuthIframeContainer.test.js.map +0 -1
  268. package/dist/test/unit/shared/storage.test.d.ts.map +0 -1
  269. package/dist/tsconfig.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civic/auth",
3
- "version": "0.1.4-beta.2",
3
+ "version": "0.1.4-beta.3",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "main": "dist/index.ts",
@@ -92,25 +92,28 @@
92
92
  "ts-jest": "^29.2.5",
93
93
  "tsc-alias": "^1.8.10",
94
94
  "tsup": "^8.3.0",
95
+ "tsx": "^4.19.1",
95
96
  "vite": "^5.4.8",
96
97
  "vite-plugin-dts": "^4.2.3",
97
98
  "vitest": "^2.1.2",
98
- "@repo/typescript-config": "0.0.0",
99
- "@repo/eslint-config": "0.0.0"
99
+ "@repo/eslint-config": "0.0.0",
100
+ "@repo/typescript-config": "0.0.0"
100
101
  },
101
102
  "optionalDependency": {
102
103
  "next": "^14"
103
104
  },
104
105
  "scripts": {
106
+ "prebuild": "rm -rf .turbo dist && pnpm generate-version",
105
107
  "build": "pnpm build:cjs && pnpm build:esm",
106
108
  "build:cjs": "tsc -p tsconfig.cjs.json --noEmit false && tsc-alias -p tsconfig.cjs.json",
107
109
  "build:esm": "tsc -p tsconfig.esm.json --noEmit false && tsc-alias -p tsconfig.esm.json",
108
- "prepublish": "node ../../etc/scripts/prompt-changelog.js && pnpm build",
110
+ "prepublish": "pnpm generate-version && node ../../etc/scripts/prompt-changelog.js && pnpm build",
109
111
  "dev": "tsc --watch",
112
+ "pretest": "pnpm generate-version",
110
113
  "test": "vitest",
111
114
  "lint": "eslint \"src/**/*.ts*\" --max-warnings 0",
112
115
  "lint:fix": "pnpm lint --fix",
113
- "clean": "rm -rf .turbo dist node_modules",
114
- "test:update": "vitest --update"
116
+ "test:update": "vitest --update",
117
+ "generate-version": "npx tsx ./generateVersion.ts"
115
118
  }
116
119
  }
@@ -1,9 +0,0 @@
1
- import type { AuthStorage } from "@/types.js";
2
- import { EventEmitter } from "eventemitter3";
3
- export declare class LocalStorageAdapter implements AuthStorage {
4
- static _emitter: EventEmitter;
5
- static get emitter(): EventEmitter;
6
- get(key: string): Promise<string>;
7
- set(key: string, value: string): Promise<void>;
8
- }
9
- //# sourceMappingURL=storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/browser/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,qBAAa,mBAAoB,YAAW,WAAW;IACrD,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC;IAC9B,MAAM,KAAK,OAAO,IAAI,YAAY,CAKjC;IACK,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrD"}
@@ -1,17 +0,0 @@
1
- import { EventEmitter } from "eventemitter3";
2
- export class LocalStorageAdapter {
3
- static _emitter;
4
- static get emitter() {
5
- if (!LocalStorageAdapter._emitter) {
6
- LocalStorageAdapter._emitter = new EventEmitter();
7
- }
8
- return LocalStorageAdapter._emitter;
9
- }
10
- async get(key) {
11
- return Promise.resolve(localStorage.getItem(key) || "");
12
- }
13
- async set(key, value) {
14
- localStorage.setItem(key, value);
15
- }
16
- }
17
- //# sourceMappingURL=storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/browser/storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,OAAO,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAe;IAC9B,MAAM,KAAK,OAAO;QAChB,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC;YAClC,mBAAmB,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;QACpD,CAAC;QACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC;IACtC,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa;QAClC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import type { AuthStorage } from \"@/types.js\";\nimport { EventEmitter } from \"eventemitter3\";\n\nexport class LocalStorageAdapter implements AuthStorage {\n static _emitter: EventEmitter;\n static get emitter(): EventEmitter {\n if (!LocalStorageAdapter._emitter) {\n LocalStorageAdapter._emitter = new EventEmitter();\n }\n return LocalStorageAdapter._emitter;\n }\n async get(key: string): Promise<string> {\n return Promise.resolve(localStorage.getItem(key) || \"\");\n }\n\n async set(key: string, value: string): Promise<void> {\n localStorage.setItem(key, value);\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,eAAO,MAAM,UAAU,EAAE,MAExB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,MAAM,EACN,SAAS,EACT,MAAM,EACN,IAAI,EACJ,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,mBAAmB,uBAAuB,CAAC;AAE3C,YAAY,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC"}
@@ -1,7 +0,0 @@
1
- declare const getWindowCookieValue: (requests: {
2
- key: string;
3
- window: Window;
4
- parseJson?: boolean;
5
- }[]) => Record<string, string | Record<string, unknown>> | null;
6
- export { getWindowCookieValue };
7
- //# sourceMappingURL=cookies.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../../src/lib/cookies.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,oBAAoB,aACd;IACR,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,EAAE,4DAqBJ,CAAC;AACF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,25 +0,0 @@
1
- const getWindowCookieValue = (requests) => {
2
- const cookie = window.document.cookie;
3
- if (!cookie)
4
- return null;
5
- const cookies = cookie.split(";");
6
- const response = {};
7
- for (const c of cookies) {
8
- const [name, value] = c.trim().split("=");
9
- const request = requests.find((r) => r.key === name);
10
- if (value && request) {
11
- try {
12
- const decodeURIComponentValue = decodeURIComponent(value);
13
- response[request.key] = request.parseJson
14
- ? JSON.parse(decodeURIComponentValue)
15
- : decodeURIComponentValue;
16
- }
17
- catch {
18
- response[request.key] = value;
19
- }
20
- }
21
- }
22
- return response;
23
- };
24
- export { getWindowCookieValue };
25
- //# sourceMappingURL=cookies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../../src/lib/cookies.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,CAC3B,QAIG,EACH,EAAE;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IACtC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAqD,EAAE,CAAC;IACtE,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;QACrD,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;gBAC1D,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,SAAS;oBACvC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC;oBACrC,CAAC,CAAC,uBAAuB,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACP,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AACF,OAAO,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["const getWindowCookieValue = (\n requests: {\n key: string;\n window: Window;\n parseJson?: boolean;\n }[],\n) => {\n const cookie = window.document.cookie;\n if (!cookie) return null;\n const cookies = cookie.split(\";\");\n const response: Record<string, string | Record<string, unknown>> = {};\n for (const c of cookies) {\n const [name, value] = c.trim().split(\"=\");\n const request = requests.find((r) => r.key === name);\n if (value && request) {\n try {\n const decodeURIComponentValue = decodeURIComponent(value);\n response[request.key] = request.parseJson\n ? JSON.parse(decodeURIComponentValue)\n : decodeURIComponentValue;\n } catch {\n response[request.key] = value;\n }\n }\n }\n return response;\n};\nexport { getWindowCookieValue };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../src/lib/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEtE,eAAO,MAAM,2BAA2B,gBACzB,kBAAkB,KAC9B,eAUA,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/lib/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAuB,MAAM,YAAY,CAAC;AAG9E,QAAA,MAAM,mBAAmB,WAAY,MAAM,KAAG,MAAM,EAQnD,CAAC;AAKF,QAAA,MAAM,iBAAiB,gBAAuB,MAAM,KAAG,OAAO,CAAC,SAAS,CAYvE,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,aAAa,gBACJ,WAAW,wBACF,OAAO,KAC5B,MAOF,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,oBAAoB,UACjB,MAAM,sBACO,WAAW,GAAG,SAAS,KAC1C,WAAW,GAAG,SAQhB,CAAC;AAEF,QAAA,MAAM,4BAA4B,UAAW,MAAM,KAAG,OAAO,GAAG,SAQ/D,CAAC;AAEF,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,GACd,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"postMessage.d.ts","sourceRoot":"","sources":["../../../src/lib/postMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,QAAA,MAAM,2BAA2B,UACxB,gBAAgB,YACb,MAAM,KACf,OAcF,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
@@ -1,15 +0,0 @@
1
- const validateLoginAppPostMessage = (event, clientId) => {
2
- const caseEvent = event;
3
- // console.log("caseEvent", caseEvent);
4
- if (!caseEvent.clientId ||
5
- !caseEvent.data.url ||
6
- !caseEvent.source ||
7
- !caseEvent.type ||
8
- caseEvent.clientId !== clientId ||
9
- caseEvent.source !== "civicloginApp") {
10
- return false;
11
- }
12
- return true;
13
- };
14
- export { validateLoginAppPostMessage };
15
- //# sourceMappingURL=postMessage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postMessage.js","sourceRoot":"","sources":["../../../src/lib/postMessage.ts"],"names":[],"mappings":"AAEA,MAAM,2BAA2B,GAAG,CAClC,KAAuB,EACvB,QAAgB,EACP,EAAE;IACX,MAAM,SAAS,GAAG,KAAyB,CAAC;IAC5C,uCAAuC;IACvC,IACE,CAAC,SAAS,CAAC,QAAQ;QACnB,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;QACnB,CAAC,SAAS,CAAC,MAAM;QACjB,CAAC,SAAS,CAAC,IAAI;QACf,SAAS,CAAC,QAAQ,KAAK,QAAQ;QAC/B,SAAS,CAAC,MAAM,KAAK,eAAe,EACpC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,CAAC","sourcesContent":["import type { LoginPostMessage } from \"@/types.js\";\n\nconst validateLoginAppPostMessage = (\n event: LoginPostMessage,\n clientId: string,\n): boolean => {\n const caseEvent = event as LoginPostMessage;\n // console.log(\"caseEvent\", caseEvent);\n if (\n !caseEvent.clientId ||\n !caseEvent.data.url ||\n !caseEvent.source ||\n !caseEvent.type ||\n caseEvent.clientId !== clientId ||\n caseEvent.source !== \"civicloginApp\"\n ) {\n return false;\n }\n return true;\n};\n\nexport { validateLoginAppPostMessage };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"windowUtil.d.ts","sourceRoot":"","sources":["../../../src/lib/windowUtil.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,WAAY,MAAM,KAAG,OAc1C,CAAC;AAEF,QAAA,MAAM,yBAAyB,mBAAoB,MAAM,EAAE,SAW1D,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,CAAC"}
@@ -1,31 +0,0 @@
1
- const isWindowInIframe = (window) => {
2
- if (typeof window !== "undefined") {
3
- // use the window width to determine if we're in an iframe or not
4
- try {
5
- if (window?.frameElement?.id === "civic-auth-iframe") {
6
- return true;
7
- }
8
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
- }
10
- catch (_e) {
11
- // If we get an error, we're not in an iframe
12
- return false;
13
- }
14
- }
15
- return false;
16
- };
17
- const removeParamsWithoutReload = (paramsToRemove) => {
18
- const url = new URL(window.location.href);
19
- paramsToRemove.forEach((param) => {
20
- url.searchParams.delete(param);
21
- });
22
- try {
23
- window.history.replaceState({}, "", url);
24
- window.dispatchEvent(new Event("popstate"));
25
- }
26
- catch (error) {
27
- console.warn("window.history.replaceState failed", error);
28
- }
29
- };
30
- export { isWindowInIframe, removeParamsWithoutReload };
31
- //# sourceMappingURL=windowUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"windowUtil.js","sourceRoot":"","sources":["../../../src/lib/windowUtil.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAW,EAAE;IACnD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,iEAAiE;QACjE,IAAI,CAAC;YACH,IAAI,MAAM,EAAE,YAAY,EAAE,EAAE,KAAK,mBAAmB,EAAE,CAAC;gBACrD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,6DAA6D;QAC/D,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,6CAA6C;YAC7C,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAC,cAAwB,EAAE,EAAE;IAC7D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,cAAc,CAAC,OAAO,CAAC,CAAC,KAAa,EAAE,EAAE;QACvC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;QACzC,MAAM,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,CAAC","sourcesContent":["const isWindowInIframe = (window: Window): boolean => {\n if (typeof window !== \"undefined\") {\n // use the window width to determine if we're in an iframe or not\n try {\n if (window?.frameElement?.id === \"civic-auth-iframe\") {\n return true;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_e) {\n // If we get an error, we're not in an iframe\n return false;\n }\n }\n return false;\n};\n\nconst removeParamsWithoutReload = (paramsToRemove: string[]) => {\n const url = new URL(window.location.href);\n paramsToRemove.forEach((param: string) => {\n url.searchParams.delete(param);\n });\n try {\n window.history.replaceState({}, \"\", url);\n window.dispatchEvent(new Event(\"popstate\"));\n } catch (error) {\n console.warn(\"window.history.replaceState failed\", error);\n }\n};\n\nexport { isWindowInIframe, removeParamsWithoutReload };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"GetUser.d.ts","sourceRoot":"","sources":["../../../src/nextjs/GetUser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,eAAO,MAAM,OAAO,QAAa,OAAO,CAAC,IAAI,GAAG,IAAI,CAGnD,CAAC"}
@@ -1,7 +0,0 @@
1
- import { NextjsClientStorage } from "@/nextjs/cookies.js";
2
- import { getUser as getSessionUser } from "@/shared/lib/session.js";
3
- export const getUser = async () => {
4
- const clientStorage = new NextjsClientStorage();
5
- return getSessionUser(clientStorage);
6
- };
7
- //# sourceMappingURL=GetUser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GetUser.js","sourceRoot":"","sources":["../../../src/nextjs/GetUser.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEpE,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,IAA0B,EAAE;IACtD,MAAM,aAAa,GAAG,IAAI,mBAAmB,EAAE,CAAC;IAChD,OAAO,cAAc,CAAC,aAAa,CAAC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["/**\n * Used on the server-side to get the user object from the cookie\n */\nimport type { User } from \"@/types.js\";\nimport { NextjsClientStorage } from \"@/nextjs/cookies.js\";\nimport { getUser as getSessionUser } from \"@/shared/lib/session.js\";\n\nexport const getUser = async (): Promise<User | null> => {\n const clientStorage = new NextjsClientStorage();\n return getSessionUser(clientStorage);\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/nextjs/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,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BAA8B,CAAC;0BAAkE,CAAC;;qBAA2C,CAAC;mBAAiC,CAAC;;wBAA+C,CAAC;eAAmD,CAAC;iBAA4C,CAAC;2BAAyC,CAAC;;;;;;;;;yBAA4zC,CAAC;6BAAwC,CAAC;;;eAAkD,CAAC;mBAAuB,CAAC;;;;CAD1ioB,CAAC"}
@@ -1,173 +0,0 @@
1
- import { loggers } from "@/lib/logger.js";
2
- import { withoutUndefined } from "@/utils.js";
3
- import { CodeVerifier, OAuthTokens, } from "@/shared/lib/types.js";
4
- import { DEFAULT_AUTH_SERVER } from "@/constants.js";
5
- const logger = loggers.nextjs.handlers.auth;
6
- const defaultServerSecure = !(process.env.NODE_ENV === "development");
7
- /**
8
- * Default configuration values that will be used if not overridden
9
- */
10
- export const defaultAuthConfig = {
11
- oauthServer: DEFAULT_AUTH_SERVER,
12
- callbackUrl: "/api/auth/callback",
13
- challengeUrl: "/api/auth/challenge",
14
- logoutUrl: "/api/auth/logout",
15
- loginUrl: "/",
16
- include: ["/*"],
17
- exclude: [],
18
- cookies: {
19
- tokens: {
20
- [OAuthTokens.ID_TOKEN]: {
21
- secure: defaultServerSecure,
22
- httpOnly: true,
23
- sameSite: "strict",
24
- path: "/",
25
- },
26
- [OAuthTokens.ACCESS_TOKEN]: {
27
- secure: defaultServerSecure,
28
- httpOnly: true,
29
- sameSite: "strict",
30
- path: "/",
31
- },
32
- [OAuthTokens.REFRESH_TOKEN]: {
33
- secure: defaultServerSecure,
34
- httpOnly: true,
35
- sameSite: "strict",
36
- path: "/",
37
- },
38
- [OAuthTokens.EXPIRES_IN]: {
39
- secure: defaultServerSecure,
40
- httpOnly: true,
41
- sameSite: "strict",
42
- path: "/",
43
- },
44
- [OAuthTokens.TIMESTAMP]: {
45
- secure: defaultServerSecure,
46
- httpOnly: true,
47
- sameSite: "strict",
48
- path: "/",
49
- },
50
- [CodeVerifier.COOKIE_NAME]: {
51
- secure: defaultServerSecure,
52
- httpOnly: true,
53
- sameSite: "strict",
54
- path: "/",
55
- },
56
- [CodeVerifier.APP_URL]: {
57
- secure: defaultServerSecure,
58
- httpOnly: true,
59
- sameSite: "strict",
60
- path: "/",
61
- },
62
- },
63
- user: {
64
- secure: defaultServerSecure,
65
- httpOnly: false,
66
- sameSite: "strict",
67
- path: "/",
68
- maxAge: 60 * 60, // 1 hour
69
- },
70
- },
71
- };
72
- /**
73
- * Resolves the authentication configuration by combining:
74
- * 1. Default values
75
- * 2. Environment variables (set internally by the plugin)
76
- * 3. Explicitly passed configuration
77
- *
78
- * Note: Developers should not set _civic_auth_* environment variables directly.
79
- * Instead, pass configuration to the createCivicAuthPlugin in next.config.js:
80
- *
81
- * @example
82
- * ```js
83
- * // next.config.js
84
- * export default createCivicAuthPlugin({
85
- * callbackUrl: '/custom/callback',
86
- * })
87
- * ```
88
- */
89
- export const resolveAuthConfig = (config = {}) => {
90
- // Read configuration that was set by the plugin via environment variables
91
- const configFromEnv = withoutUndefined({
92
- clientId: process.env._civic_auth_client_id,
93
- oauthServer: process.env._civic_oauth_server,
94
- callbackUrl: process.env._civic_auth_callback_url,
95
- challengeUrl: process.env._civic_auth_challenge_url,
96
- loginUrl: process.env._civic_auth_login_url,
97
- logoutUrl: process.env._civic_auth_logout_url,
98
- include: process.env._civic_auth_includes?.split(","),
99
- exclude: process.env._civic_auth_excludes?.split(","),
100
- cookies: process.env._civic_auth_cookie_config
101
- ? JSON.parse(process.env._civic_auth_cookie_config)
102
- : undefined,
103
- });
104
- const mergedConfig = {
105
- ...defaultAuthConfig,
106
- ...configFromEnv, // Apply plugin-set config
107
- ...config, // Override with directly passed config
108
- cookies: {
109
- tokens: {
110
- ...defaultAuthConfig.cookies.tokens,
111
- ...(configFromEnv?.cookies?.tokens || {}),
112
- ...(config.cookies?.tokens || {}),
113
- },
114
- user: {
115
- ...defaultAuthConfig.cookies.user,
116
- ...(configFromEnv?.cookies?.user || {}),
117
- ...(config.cookies?.user || {}),
118
- },
119
- },
120
- };
121
- logger.debug("Config from environment:", JSON.stringify(configFromEnv, null, 2));
122
- logger.debug("Resolved config:", JSON.stringify(mergedConfig, null, 2));
123
- if (mergedConfig.clientId === undefined) {
124
- throw new Error("Civic Auth client ID is required");
125
- }
126
- return mergedConfig;
127
- };
128
- /**
129
- * Creates a Next.js plugin that handles auth configuration.
130
- *
131
- * This is the main configuration point for the auth system.
132
- * Do not set _civic_auth_* environment variables directly - instead,
133
- * pass your configuration here:
134
- *
135
- * @example
136
- * ```js
137
- * // next.config.js
138
- * export default createCivicAuthPlugin({
139
- * clientId: 'my-client-id',
140
- * callbackUrl: '/custom/callback',
141
- * loginUrl: '/custom/login',
142
- * logoutUrl: '/custom/logout',
143
- * include: ['/protected/*'],
144
- * exclude: ['/public/*']
145
- * })
146
- * ```
147
- *
148
- * The plugin sets internal environment variables that are used by
149
- * the auth system. These variables should not be set manually.
150
- */
151
- export const createCivicAuthPlugin = (authConfig) => {
152
- return (nextConfig) => {
153
- logger.debug("createCivicAuthPlugin nextConfig", JSON.stringify(nextConfig, null, 2));
154
- const resolvedConfig = resolveAuthConfig({ ...authConfig });
155
- return {
156
- ...nextConfig,
157
- env: {
158
- ...nextConfig?.env,
159
- // Internal environment variables - do not set these manually
160
- _civic_auth_client_id: resolvedConfig.clientId,
161
- _civic_oauth_server: resolvedConfig.oauthServer,
162
- _civic_auth_callback_url: resolvedConfig.callbackUrl,
163
- _civic_auth_challenge_url: resolvedConfig.challengeUrl,
164
- _civic_auth_login_url: resolvedConfig.loginUrl,
165
- _civic_auth_logout_url: resolvedConfig.logoutUrl,
166
- _civic_auth_includes: resolvedConfig.include.join(","),
167
- _civic_auth_excludes: resolvedConfig.exclude.join(","),
168
- _civic_auth_cookie_config: JSON.stringify(resolvedConfig.cookies),
169
- },
170
- };
171
- };
172
- };
173
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/nextjs/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,i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AAM,qBAAqB,GAAG,CACnC,UAA+D,EAC/D,EAAE;IACF,OAAO,CAAC,UAAuB,EAAE,EAAE;QACjC,MAAM,CAAC,KAAK,CACV,kCAAkC,EAClC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CACpC,CAAC;QACF,MAAM,cAAc,GAAG,iBAAiB,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC;QAC5D,OAAO;YACL,GAAG,UAAU;YACb,GAAG,EAAE;gBACH,GAAG,UAAU,EAAE,GAAG;gBAClB,6DAA6D;gBAC7D,qBAAqB,EAAE,cAAc,CAAC,QAAQ;gBAC9C,mBAAmB,EAAE,cAAc,CAAC,WAAW;gBAC/C,wBAAwB,EAAE,cAAc,CAAC,WAAW;gBACpD,yBAAyB,EAAE,cAAc,CAAC,YAAY;gBACtD,qBAAqB,EAAE,cAAc,CAAC,QAAQ;gBAC9C,sBAAsB,EAAE,cAAc,CAAC,SAAS;gBAChD,oBAAoB,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtD,oBAAoB,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtD,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC;aAClE;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable turbo/no-undeclared-env-vars */\nimport type { NextConfig } from \"next\";\nimport { loggers } from \"@/lib/logger.js\";\nimport { withoutUndefined } from \"@/utils.js\";\nimport {\n CodeVerifier,\n type CookieConfig,\n OAuthTokens,\n type TokensCookieConfig,\n} from \"@/shared/lib/types.js\";\nimport { DEFAULT_AUTH_SERVER } from \"@/constants.js\";\n\nconst logger = loggers.nextjs.handlers.auth;\n\nexport type CookiesConfigObject = {\n tokens: TokensCookieConfig;\n user: CookieConfig;\n};\n\nexport type AuthConfigWithDefaults = {\n clientId: string;\n oauthServer: string;\n callbackUrl: string;\n loginUrl: string;\n logoutUrl: string;\n challengeUrl: string;\n include: string[];\n exclude: string[];\n cookies: CookiesConfigObject;\n};\n\nexport type AuthConfig = Partial<AuthConfigWithDefaults>;\n\nexport type DefinedAuthConfig = AuthConfigWithDefaults;\n\nconst defaultServerSecure = !(process.env.NODE_ENV === \"development\");\n/**\n * Default configuration values that will be used if not overridden\n */\nexport const defaultAuthConfig: Omit<AuthConfigWithDefaults, \"clientId\"> = {\n oauthServer: DEFAULT_AUTH_SERVER,\n callbackUrl: \"/api/auth/callback\",\n challengeUrl: \"/api/auth/challenge\",\n logoutUrl: \"/api/auth/logout\",\n loginUrl: \"/\",\n include: [\"/*\"],\n exclude: [],\n cookies: {\n tokens: {\n [OAuthTokens.ID_TOKEN]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n },\n [OAuthTokens.ACCESS_TOKEN]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n },\n [OAuthTokens.REFRESH_TOKEN]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n },\n [OAuthTokens.EXPIRES_IN]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n },\n [OAuthTokens.TIMESTAMP]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n },\n [CodeVerifier.COOKIE_NAME]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n },\n [CodeVerifier.APP_URL]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n },\n },\n user: {\n secure: defaultServerSecure,\n httpOnly: false,\n sameSite: \"strict\",\n path: \"/\",\n maxAge: 60 * 60, // 1 hour\n },\n },\n};\n\n/**\n * Resolves the authentication configuration by combining:\n * 1. Default values\n * 2. Environment variables (set internally by the plugin)\n * 3. Explicitly passed configuration\n *\n * Note: Developers should not set _civic_auth_* environment variables directly.\n * Instead, pass configuration to the createCivicAuthPlugin in next.config.js:\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * callbackUrl: '/custom/callback',\n * })\n * ```\n */\nexport const resolveAuthConfig = (\n config: AuthConfig = {},\n): AuthConfigWithDefaults => {\n // Read configuration that was set by the plugin via environment variables\n const configFromEnv = withoutUndefined({\n clientId: process.env._civic_auth_client_id,\n oauthServer: process.env._civic_oauth_server,\n callbackUrl: process.env._civic_auth_callback_url,\n challengeUrl: process.env._civic_auth_challenge_url,\n loginUrl: process.env._civic_auth_login_url,\n logoutUrl: process.env._civic_auth_logout_url,\n include: process.env._civic_auth_includes?.split(\",\"),\n exclude: process.env._civic_auth_excludes?.split(\",\"),\n cookies: process.env._civic_auth_cookie_config\n ? JSON.parse(process.env._civic_auth_cookie_config)\n : undefined,\n }) as AuthConfig;\n const mergedConfig = {\n ...defaultAuthConfig,\n ...configFromEnv, // Apply plugin-set config\n ...config, // Override with directly passed config\n cookies: {\n tokens: {\n ...defaultAuthConfig.cookies.tokens,\n ...(configFromEnv?.cookies?.tokens || {}),\n ...(config.cookies?.tokens || {}),\n },\n user: {\n ...defaultAuthConfig.cookies.user,\n ...(configFromEnv?.cookies?.user || {}),\n ...(config.cookies?.user || {}),\n },\n },\n };\n\n logger.debug(\n \"Config from environment:\",\n JSON.stringify(configFromEnv, null, 2),\n );\n logger.debug(\"Resolved config:\", JSON.stringify(mergedConfig, null, 2));\n if (mergedConfig.clientId === undefined) {\n throw new Error(\"Civic Auth client ID is required\");\n }\n return mergedConfig as AuthConfigWithDefaults & { clientId: string };\n};\n\n/**\n * Creates a Next.js plugin that handles auth configuration.\n *\n * This is the main configuration point for the auth system.\n * Do not set _civic_auth_* environment variables directly - instead,\n * pass your configuration here:\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * clientId: 'my-client-id',\n * callbackUrl: '/custom/callback',\n * loginUrl: '/custom/login',\n * logoutUrl: '/custom/logout',\n * include: ['/protected/*'],\n * exclude: ['/public/*']\n * })\n * ```\n *\n * The plugin sets internal environment variables that are used by\n * the auth system. These variables should not be set manually.\n */\nexport const createCivicAuthPlugin = (\n authConfig: AuthConfig & Pick<Required<AuthConfig>, \"clientId\">,\n) => {\n return (nextConfig?: NextConfig) => {\n logger.debug(\n \"createCivicAuthPlugin nextConfig\",\n JSON.stringify(nextConfig, null, 2),\n );\n const resolvedConfig = resolveAuthConfig({ ...authConfig });\n return {\n ...nextConfig,\n env: {\n ...nextConfig?.env,\n // Internal environment variables - do not set these manually\n _civic_auth_client_id: resolvedConfig.clientId,\n _civic_oauth_server: resolvedConfig.oauthServer,\n _civic_auth_callback_url: resolvedConfig.callbackUrl,\n _civic_auth_challenge_url: resolvedConfig.challengeUrl,\n _civic_auth_login_url: resolvedConfig.loginUrl,\n _civic_auth_logout_url: resolvedConfig.logoutUrl,\n _civic_auth_includes: resolvedConfig.include.join(\",\"),\n _civic_auth_excludes: resolvedConfig.exclude.join(\",\"),\n _civic_auth_cookie_config: JSON.stringify(resolvedConfig.cookies),\n },\n };\n };\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../../src/nextjs/cookies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,KAAK,EACV,YAAY,EAEZ,WAAW,EACX,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,aAAa,EACb,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AAEjC;;GAEG;AACH,QAAA,MAAM,kBAAkB,aACZ,QAAQ,eACL,WAAW,UAChB,UAAU,SA4BnB,CAAC;AAcF;;GAEG;AACH,QAAA,MAAM,oBAAoB,aACd,QAAQ,QACZ,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,eACnB,WAAW,UAChB,UAAU,SAyBnB,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,gBAAgB,WAAkB,UAAU,kBASjD,CAAC;AAEF,KAAK,SAAS,GAAG,WAAW,GAAG,YAAY,CAAC;AAC5C,cAAM,mBAAoB,SAAQ,aAAa;IACjC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC;gBAAnC,MAAM,GAAE,OAAO,CAAC,kBAAkB,CAAM;IAOvD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKxC,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxD;AAED,cAAM,mBAAoB,SAAQ,aAAa;gBACjC,MAAM,GAAE,OAAO,CAAC,qBAAqB,CAAM;IAQjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIrD;AAED,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,CAAC"}
@@ -1,2 +0,0 @@
1
- export { useUserCookie } from "@/nextjs/hooks/useUserCookie.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/nextjs/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC"}
@@ -1,2 +0,0 @@
1
- export { useUserCookie } from "@/nextjs/hooks/useUserCookie.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/nextjs/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export { useUserCookie } from \"@/nextjs/hooks/useUserCookie.js\";\n"]}
@@ -1,4 +0,0 @@
1
- import type { SessionData } from "@/types.js";
2
- declare const useRefresh: (session: SessionData | null) => void;
3
- export { useRefresh };
4
- //# sourceMappingURL=useRefresh.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRefresh.d.ts","sourceRoot":"","sources":["../../../../src/nextjs/hooks/useRefresh.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,QAAA,MAAM,UAAU,YAAa,WAAW,GAAG,IAAI,SAuC9C,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,38 +0,0 @@
1
- import { LocalStorageAdapter } from "@/browser/storage.js";
2
- import { useEffect, useMemo, useState } from "react";
3
- import { GenericAuthenticationRefresher } from "@/shared/lib/GenericAuthenticationRefresher.js";
4
- import { useCivicAuthConfig } from "@/shared/hooks/useCivicAuthConfig.js";
5
- const useRefresh = (session) => {
6
- const authConfig = useCivicAuthConfig();
7
- const storage = useMemo(() => new LocalStorageAdapter(), []);
8
- // setup token autorefresh
9
- const [refresher, setRefresher] = useState(undefined);
10
- useEffect(() => {
11
- if (!authConfig)
12
- return;
13
- const abortController = new AbortController();
14
- const currentRefresher = refresher;
15
- GenericAuthenticationRefresher.build({ ...authConfig }, storage).then((newRefresher) => {
16
- if (abortController.signal.aborted)
17
- return;
18
- currentRefresher?.clearAutorefresh();
19
- setRefresher(newRefresher);
20
- });
21
- return () => {
22
- abortController.abort();
23
- currentRefresher?.clearAutorefresh();
24
- };
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- }, [authConfig, storage]); // Only depend on what actually changes
27
- useEffect(() => {
28
- if (session?.authenticated) {
29
- refresher?.setupAutorefresh();
30
- }
31
- else {
32
- refresher?.clearAutorefresh();
33
- }
34
- return () => refresher?.clearAutorefresh();
35
- }, [refresher, session?.authenticated]);
36
- };
37
- export { useRefresh };
38
- //# 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,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,gDAAgD,CAAC;AAEhG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAE1E,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;IAE7D,0BAA0B;IAC1B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAExC,SAAS,CAAC,CAAC;IAEb,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,UAAU;YAAE,OAAO;QACxB,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,MAAM,gBAAgB,GAAG,SAAS,CAAC;QAEnC,8BAA8B,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,CACnE,CAAC,YAAY,EAAE,EAAE;YACf,IAAI,eAAe,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YAE3C,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;YACrC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7B,CAAC,CACF,CAAC;QAEF,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;AAC1C,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { LocalStorageAdapter } from \"@/browser/storage.js\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { GenericAuthenticationRefresher } from \"@/shared/lib/GenericAuthenticationRefresher.js\";\nimport type { SessionData } from \"@/types.js\";\nimport { useCivicAuthConfig } from \"@/shared/hooks/useCivicAuthConfig.js\";\n\nconst useRefresh = (session: SessionData | null) => {\n const authConfig = useCivicAuthConfig();\n const storage = useMemo(() => new LocalStorageAdapter(), []);\n\n // setup token autorefresh\n const [refresher, setRefresher] = useState<\n GenericAuthenticationRefresher | undefined\n >(undefined);\n\n useEffect(() => {\n if (!authConfig) return;\n const abortController = new AbortController();\n const currentRefresher = refresher;\n\n GenericAuthenticationRefresher.build({ ...authConfig }, storage).then(\n (newRefresher) => {\n if (abortController.signal.aborted) return;\n\n currentRefresher?.clearAutorefresh();\n setRefresher(newRefresher);\n },\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};\n\nexport { useRefresh };\n"]}
@@ -1,3 +0,0 @@
1
- import type { OAuthTokens } from "@/shared/lib/types.js";
2
- export declare const useTokenCookie: (tokenName: OAuthTokens) => string | null;
3
- //# sourceMappingURL=useTokenCookie.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTokenCookie.d.ts","sourceRoot":"","sources":["../../../../src/nextjs/hooks/useTokenCookie.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAUzD,eAAO,MAAM,cAAc,cAAe,WAAW,KAAG,MAAM,GAAG,IAyBhE,CAAC"}
@@ -1,37 +0,0 @@
1
- "use client";
2
- import { useEffect, useRef } from "react";
3
- import { useRouter } from "next/navigation.js";
4
- import { useQuery } from "@tanstack/react-query";
5
- import { getWindowCookieValue } from "@/lib/cookies.js";
6
- const getTokenFromCookie = (tokenName) => {
7
- return getWindowCookieValue({
8
- key: tokenName,
9
- window: globalThis.window,
10
- parseJson: false,
11
- });
12
- };
13
- export const useTokenCookie = (tokenName) => {
14
- const hasRunRef = useRef(false);
15
- const router = useRouter();
16
- const { data: token } = useQuery({
17
- queryKey: ["token", tokenName],
18
- queryFn: () => getTokenFromCookie(tokenName) || null,
19
- refetchInterval: 2000,
20
- refetchIntervalInBackground: true,
21
- enabled: !hasRunRef.current,
22
- refetchOnWindowFocus: true,
23
- });
24
- useEffect(() => {
25
- if (token) {
26
- if (!hasRunRef.current) {
27
- hasRunRef.current = true;
28
- router.refresh();
29
- }
30
- }
31
- else {
32
- hasRunRef.current = false;
33
- }
34
- }, [token, router]);
35
- return token ?? null;
36
- };
37
- //# sourceMappingURL=useTokenCookie.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTokenCookie.js","sourceRoot":"","sources":["../../../../src/nextjs/hooks/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AC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpB,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CAAC","sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { useRouter } from \"next/navigation.js\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { getWindowCookieValue } from \"@/lib/cookies.js\";\nimport type { OAuthTokens } from \"@/shared/lib/types.js\";\n\nconst getTokenFromCookie = (tokenName: OAuthTokens): string => {\n return getWindowCookieValue({\n key: tokenName,\n window: globalThis.window,\n parseJson: false,\n });\n};\n\nexport const useTokenCookie = (tokenName: OAuthTokens): string | null => {\n const hasRunRef = useRef(false);\n const router = useRouter();\n\n const { data: token } = useQuery({\n queryKey: [\"token\", tokenName],\n queryFn: () => getTokenFromCookie(tokenName) || null,\n refetchInterval: 2000,\n refetchIntervalInBackground: true,\n enabled: !hasRunRef.current,\n refetchOnWindowFocus: true,\n });\n\n useEffect(() => {\n if (token) {\n if (!hasRunRef.current) {\n hasRunRef.current = true;\n router.refresh();\n }\n } else {\n hasRunRef.current = false;\n }\n }, [token, router]);\n\n return token ?? null;\n};\n"]}
@@ -1,6 +0,0 @@
1
- import type { EmptyObject, User } from "@/types.js";
2
- export declare const useUserCookie: <T extends EmptyObject>() => {
3
- user: User<T> | null;
4
- idToken: string | undefined;
5
- };
6
- //# sourceMappingURL=useUserCookie.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useUserCookie.d.ts","sourceRoot":"","sources":["../../../../src/nextjs/hooks/useUserCookie.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAqBpD,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW;;;CAkDlD,CAAC"}