@civic/auth 0.0.1-beta.28 → 0.0.1-beta.29

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 (261) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-lint.log +14 -0
  3. package/.turbo/turbo-test.log +1678 -0
  4. package/civic-auth-0.0.1-beta.15.tgz +0 -0
  5. package/civic-auth-0.0.1-beta.17.tgz +0 -0
  6. package/dist/AuthProvider-BYZ8w92b.d.mts +15 -0
  7. package/dist/AuthProvider-BgOwv9h8.d.ts +15 -0
  8. package/dist/AuthProvider-Bj_Prt1x.d.ts +21 -0
  9. package/dist/AuthProvider-DUAoX4G9.d.mts +21 -0
  10. package/dist/UserProvider-BA2uflVB.d.ts +16 -0
  11. package/dist/UserProvider-Bl3j1PUO.d.mts +16 -0
  12. package/dist/UserProvider-CMLaYOUD.d.ts +16 -0
  13. package/dist/UserProvider-Cbm8MZkJ.d.mts +16 -0
  14. package/dist/chunk-4PLCDPEN.mjs +599 -0
  15. package/dist/chunk-4PLCDPEN.mjs.map +1 -0
  16. package/dist/chunk-5UQQYXCX.js +1 -0
  17. package/dist/chunk-5UQQYXCX.js.map +1 -0
  18. package/dist/chunk-63YGK3A7.mjs +223 -0
  19. package/dist/chunk-63YGK3A7.mjs.map +1 -0
  20. package/dist/chunk-6RFRDWIP.js +223 -0
  21. package/dist/chunk-6RFRDWIP.js.map +1 -0
  22. package/dist/chunk-7K3QN2AT.js +599 -0
  23. package/dist/chunk-7K3QN2AT.js.map +1 -0
  24. package/dist/chunk-AM2Y662I.js +601 -0
  25. package/dist/chunk-AM2Y662I.js.map +1 -0
  26. package/dist/chunk-AP4627CS.mjs +223 -0
  27. package/dist/chunk-AP4627CS.mjs.map +1 -0
  28. package/dist/chunk-CRTRMMJ7.js +59 -0
  29. package/dist/chunk-CRTRMMJ7.js.map +1 -0
  30. package/dist/chunk-CTVJJBBA.js +118 -0
  31. package/dist/chunk-CTVJJBBA.js.map +1 -0
  32. package/dist/chunk-EKLYHP2D.mjs +711 -0
  33. package/dist/chunk-EKLYHP2D.mjs.map +1 -0
  34. package/dist/chunk-FHRZSX3C.js +710 -0
  35. package/dist/chunk-FHRZSX3C.js.map +1 -0
  36. package/dist/chunk-GB3H3I47.js +711 -0
  37. package/dist/chunk-GB3H3I47.js.map +1 -0
  38. package/dist/chunk-JDZPCA3P.js +173 -0
  39. package/dist/chunk-JDZPCA3P.js.map +1 -0
  40. package/dist/chunk-JEOPLLWO.js +223 -0
  41. package/dist/chunk-JEOPLLWO.js.map +1 -0
  42. package/dist/chunk-MK7557NR.mjs +118 -0
  43. package/dist/chunk-MK7557NR.mjs.map +1 -0
  44. package/dist/chunk-NLRREFOX.mjs +710 -0
  45. package/dist/chunk-NLRREFOX.mjs.map +1 -0
  46. package/dist/chunk-O3WGNLRO.mjs +173 -0
  47. package/dist/chunk-O3WGNLRO.mjs.map +1 -0
  48. package/dist/chunk-OXXUQ36U.mjs +283 -0
  49. package/dist/chunk-OXXUQ36U.mjs.map +1 -0
  50. package/dist/chunk-PMJAV4JJ.mjs +1 -0
  51. package/dist/chunk-PMJAV4JJ.mjs.map +1 -0
  52. package/dist/chunk-Q7DSPTUG.mjs +601 -0
  53. package/dist/chunk-Q7DSPTUG.mjs.map +1 -0
  54. package/dist/chunk-RGHW4PYM.mjs +59 -0
  55. package/dist/chunk-RGHW4PYM.mjs.map +1 -0
  56. package/dist/chunk-TH6FI2XI.js +283 -0
  57. package/dist/chunk-TH6FI2XI.js.map +1 -0
  58. package/dist/cjs/src/browser/storage.d.ts +2 -2
  59. package/dist/cjs/src/browser/storage.d.ts.map +1 -1
  60. package/dist/cjs/src/browser/storage.js +3 -3
  61. package/dist/cjs/src/browser/storage.js.map +1 -1
  62. package/dist/cjs/src/nextjs/GetUser.d.ts +1 -1
  63. package/dist/cjs/src/nextjs/GetUser.d.ts.map +1 -1
  64. package/dist/cjs/src/nextjs/GetUser.js +3 -3
  65. package/dist/cjs/src/nextjs/GetUser.js.map +1 -1
  66. package/dist/cjs/src/nextjs/config.d.ts.map +1 -1
  67. package/dist/cjs/src/nextjs/config.js +0 -2
  68. package/dist/cjs/src/nextjs/config.js.map +1 -1
  69. package/dist/cjs/src/nextjs/cookies.d.ts +4 -4
  70. package/dist/cjs/src/nextjs/cookies.d.ts.map +1 -1
  71. package/dist/cjs/src/nextjs/cookies.js +14 -11
  72. package/dist/cjs/src/nextjs/cookies.js.map +1 -1
  73. package/dist/cjs/src/nextjs/routeHandler.d.ts.map +1 -1
  74. package/dist/cjs/src/nextjs/routeHandler.js +1 -5
  75. package/dist/cjs/src/nextjs/routeHandler.js.map +1 -1
  76. package/dist/cjs/src/reactjs/hooks/index.d.ts +0 -1
  77. package/dist/cjs/src/reactjs/hooks/index.d.ts.map +1 -1
  78. package/dist/cjs/src/reactjs/hooks/index.js +1 -3
  79. package/dist/cjs/src/reactjs/hooks/index.js.map +1 -1
  80. package/dist/cjs/src/server/ServerAuthenticationResolver.d.ts.map +1 -1
  81. package/dist/cjs/src/server/ServerAuthenticationResolver.js +2 -7
  82. package/dist/cjs/src/server/ServerAuthenticationResolver.js.map +1 -1
  83. package/dist/cjs/src/server/login.d.ts +1 -1
  84. package/dist/cjs/src/server/login.d.ts.map +1 -1
  85. package/dist/cjs/src/server/login.js +2 -2
  86. package/dist/cjs/src/server/login.js.map +1 -1
  87. package/dist/cjs/src/services/AuthenticationService.d.ts.map +1 -1
  88. package/dist/cjs/src/services/AuthenticationService.js +6 -16
  89. package/dist/cjs/src/services/AuthenticationService.js.map +1 -1
  90. package/dist/cjs/src/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
  91. package/dist/cjs/src/shared/components/CivicAuthIframeContainer.js +0 -2
  92. package/dist/cjs/src/shared/components/CivicAuthIframeContainer.js.map +1 -1
  93. package/dist/cjs/src/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
  94. package/dist/cjs/src/shared/lib/GenericAuthenticationRefresher.js +2 -6
  95. package/dist/cjs/src/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
  96. package/dist/cjs/src/shared/lib/UserSession.d.ts +4 -4
  97. package/dist/cjs/src/shared/lib/UserSession.d.ts.map +1 -1
  98. package/dist/cjs/src/shared/lib/UserSession.js +4 -4
  99. package/dist/cjs/src/shared/lib/UserSession.js.map +1 -1
  100. package/dist/cjs/src/shared/lib/session.js +1 -1
  101. package/dist/cjs/src/shared/lib/session.js.map +1 -1
  102. package/dist/cjs/src/shared/lib/storage.d.ts +2 -2
  103. package/dist/cjs/src/shared/lib/storage.d.ts.map +1 -1
  104. package/dist/cjs/src/shared/lib/storage.js.map +1 -1
  105. package/dist/cjs/src/shared/lib/util.d.ts +4 -4
  106. package/dist/cjs/src/shared/lib/util.d.ts.map +1 -1
  107. package/dist/cjs/src/shared/lib/util.js +16 -15
  108. package/dist/cjs/src/shared/lib/util.js.map +1 -1
  109. package/dist/cjs/src/types.d.ts +2 -2
  110. package/dist/cjs/src/types.d.ts.map +1 -1
  111. package/dist/cjs/src/types.js.map +1 -1
  112. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  113. package/dist/esm/src/browser/storage.d.ts +2 -2
  114. package/dist/esm/src/browser/storage.d.ts.map +1 -1
  115. package/dist/esm/src/browser/storage.js +3 -3
  116. package/dist/esm/src/browser/storage.js.map +1 -1
  117. package/dist/esm/src/nextjs/GetUser.d.ts +1 -1
  118. package/dist/esm/src/nextjs/GetUser.d.ts.map +1 -1
  119. package/dist/esm/src/nextjs/GetUser.js +3 -3
  120. package/dist/esm/src/nextjs/GetUser.js.map +1 -1
  121. package/dist/esm/src/nextjs/config.d.ts.map +1 -1
  122. package/dist/esm/src/nextjs/config.js +0 -2
  123. package/dist/esm/src/nextjs/config.js.map +1 -1
  124. package/dist/esm/src/nextjs/cookies.d.ts +4 -4
  125. package/dist/esm/src/nextjs/cookies.d.ts.map +1 -1
  126. package/dist/esm/src/nextjs/cookies.js +14 -11
  127. package/dist/esm/src/nextjs/cookies.js.map +1 -1
  128. package/dist/esm/src/nextjs/routeHandler.d.ts.map +1 -1
  129. package/dist/esm/src/nextjs/routeHandler.js +1 -5
  130. package/dist/esm/src/nextjs/routeHandler.js.map +1 -1
  131. package/dist/esm/src/reactjs/hooks/index.d.ts +0 -1
  132. package/dist/esm/src/reactjs/hooks/index.d.ts.map +1 -1
  133. package/dist/esm/src/reactjs/hooks/index.js +0 -1
  134. package/dist/esm/src/reactjs/hooks/index.js.map +1 -1
  135. package/dist/esm/src/server/ServerAuthenticationResolver.d.ts.map +1 -1
  136. package/dist/esm/src/server/ServerAuthenticationResolver.js +2 -7
  137. package/dist/esm/src/server/ServerAuthenticationResolver.js.map +1 -1
  138. package/dist/esm/src/server/login.d.ts +1 -1
  139. package/dist/esm/src/server/login.d.ts.map +1 -1
  140. package/dist/esm/src/server/login.js +2 -2
  141. package/dist/esm/src/server/login.js.map +1 -1
  142. package/dist/esm/src/services/AuthenticationService.d.ts.map +1 -1
  143. package/dist/esm/src/services/AuthenticationService.js +6 -16
  144. package/dist/esm/src/services/AuthenticationService.js.map +1 -1
  145. package/dist/esm/src/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
  146. package/dist/esm/src/shared/components/CivicAuthIframeContainer.js +0 -2
  147. package/dist/esm/src/shared/components/CivicAuthIframeContainer.js.map +1 -1
  148. package/dist/esm/src/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
  149. package/dist/esm/src/shared/lib/GenericAuthenticationRefresher.js +2 -6
  150. package/dist/esm/src/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
  151. package/dist/esm/src/shared/lib/UserSession.d.ts +4 -4
  152. package/dist/esm/src/shared/lib/UserSession.d.ts.map +1 -1
  153. package/dist/esm/src/shared/lib/UserSession.js +4 -4
  154. package/dist/esm/src/shared/lib/UserSession.js.map +1 -1
  155. package/dist/esm/src/shared/lib/session.js +1 -1
  156. package/dist/esm/src/shared/lib/session.js.map +1 -1
  157. package/dist/esm/src/shared/lib/storage.d.ts +2 -2
  158. package/dist/esm/src/shared/lib/storage.d.ts.map +1 -1
  159. package/dist/esm/src/shared/lib/storage.js.map +1 -1
  160. package/dist/esm/src/shared/lib/util.d.ts +4 -4
  161. package/dist/esm/src/shared/lib/util.d.ts.map +1 -1
  162. package/dist/esm/src/shared/lib/util.js +16 -15
  163. package/dist/esm/src/shared/lib/util.js.map +1 -1
  164. package/dist/esm/src/types.d.ts +2 -2
  165. package/dist/esm/src/types.d.ts.map +1 -1
  166. package/dist/esm/src/types.js.map +1 -1
  167. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  168. package/dist/index.css +340 -0
  169. package/dist/index.css.map +1 -0
  170. package/dist/index.d.mts +5 -0
  171. package/dist/index.d.ts +5 -0
  172. package/dist/index.js +3 -0
  173. package/dist/index.js.map +1 -0
  174. package/dist/index.mjs +3 -0
  175. package/dist/index.mjs.map +1 -0
  176. package/dist/nextjs/client.css +340 -0
  177. package/dist/nextjs/client.css.map +1 -0
  178. package/dist/nextjs/client.d.mts +10 -0
  179. package/dist/nextjs/client.d.ts +10 -0
  180. package/dist/nextjs/client.js +185 -0
  181. package/dist/nextjs/client.js.map +1 -0
  182. package/dist/nextjs/client.mjs +185 -0
  183. package/dist/nextjs/client.mjs.map +1 -0
  184. package/dist/nextjs.d.mts +267 -0
  185. package/dist/nextjs.d.ts +267 -0
  186. package/dist/nextjs.js +315 -0
  187. package/dist/nextjs.js.map +1 -0
  188. package/dist/nextjs.mjs +315 -0
  189. package/dist/nextjs.mjs.map +1 -0
  190. package/dist/react.d.mts +65 -0
  191. package/dist/react.d.ts +65 -0
  192. package/dist/react.js +226 -0
  193. package/dist/react.js.map +1 -0
  194. package/dist/react.mjs +226 -0
  195. package/dist/react.mjs.map +1 -0
  196. package/dist/server.d.mts +35 -0
  197. package/dist/server.d.ts +35 -0
  198. package/dist/server.js +20 -0
  199. package/dist/server.js.map +1 -0
  200. package/dist/server.mjs +20 -0
  201. package/dist/server.mjs.map +1 -0
  202. package/dist/src/shared/components/LoadingIcon.d.ts.map +1 -1
  203. package/dist/src/shared/components/LoadingIcon.js +0 -6
  204. package/dist/src/shared/components/LoadingIcon.js.map +1 -1
  205. package/dist/storage-ANmRwpZ3.d.ts +25 -0
  206. package/dist/storage-B2eAQNdv.d.ts +25 -0
  207. package/dist/storage-BJPUpxhm.d.mts +25 -0
  208. package/dist/storage-BJyqsZwC.d.mts +25 -0
  209. package/dist/tsconfig.tsbuildinfo +1 -1
  210. package/dist/types-Bqm9OCZN.d.mts +22 -0
  211. package/dist/types-Bqm9OCZN.d.ts +22 -0
  212. package/dist/types-BxAubCqO.d.mts +58 -0
  213. package/dist/types-BxAubCqO.d.ts +58 -0
  214. package/dist/types-DOfl9w7j.d.mts +23 -0
  215. package/dist/types-DOfl9w7j.d.ts +23 -0
  216. package/dist/types-HdCjGldB.d.mts +58 -0
  217. package/dist/types-HdCjGldB.d.ts +58 -0
  218. package/package.json +1 -1
  219. package/src/browser/storage.ts +3 -3
  220. package/src/nextjs/GetUser.ts +3 -3
  221. package/src/nextjs/config.ts +0 -2
  222. package/src/nextjs/cookies.ts +14 -18
  223. package/src/nextjs/routeHandler.ts +1 -5
  224. package/src/reactjs/hooks/index.ts +0 -1
  225. package/src/server/ServerAuthenticationResolver.ts +2 -7
  226. package/src/server/login.ts +2 -2
  227. package/src/services/AuthenticationService.ts +6 -16
  228. package/src/shared/components/CivicAuthIframeContainer.tsx +0 -4
  229. package/src/shared/lib/GenericAuthenticationRefresher.ts +3 -8
  230. package/src/shared/lib/UserSession.ts +6 -6
  231. package/src/shared/lib/session.ts +1 -1
  232. package/src/shared/lib/storage.ts +2 -2
  233. package/src/shared/lib/util.ts +21 -18
  234. package/src/types.ts +2 -2
  235. package/test/unit/nextjs/getUser.test.ts +8 -8
  236. package/test/unit/publicApi/__snapshots__/apiSnapshot.test.ts.snap +0 -7
  237. package/test/unit/server/login.test.ts +20 -18
  238. package/test/unit/server/session.test.ts +4 -4
  239. package/test/unit/services/AuthenticationService.test.ts +3 -3
  240. package/test/unit/services/ServerAuthenticationResolver.test.ts +11 -6
  241. package/test/unit/shared/GenericAuthenticationRefresher.test.ts +4 -4
  242. package/test/unit/shared/UserSession.test.ts +6 -6
  243. package/test/unit/shared/storage.test.ts +6 -6
  244. package/dist/cjs/src/nextjs/client/index.d.ts +0 -2
  245. package/dist/cjs/src/nextjs/client/index.d.ts.map +0 -1
  246. package/dist/cjs/src/nextjs/client/index.js +0 -6
  247. package/dist/cjs/src/nextjs/client/index.js.map +0 -1
  248. package/dist/cjs/src/styles.css +0 -387
  249. package/dist/esm/src/nextjs/client/index.d.ts +0 -2
  250. package/dist/esm/src/nextjs/client/index.d.ts.map +0 -1
  251. package/dist/esm/src/nextjs/client/index.js +0 -2
  252. package/dist/esm/src/nextjs/client/index.js.map +0 -1
  253. package/dist/esm/src/styles.css +0 -387
  254. package/dist/src/nextjs/client/index.d.ts +0 -2
  255. package/dist/src/nextjs/client/index.d.ts.map +0 -1
  256. package/dist/src/nextjs/client/index.js +0 -2
  257. package/dist/src/nextjs/client/index.js.map +0 -1
  258. package/dist/test/unit/nextjs/routeHandler.test.d.ts +0 -2
  259. package/dist/test/unit/nextjs/routeHandler.test.d.ts.map +0 -1
  260. package/dist/test/unit/nextjs/routeHandler.test.js +0 -271
  261. package/dist/test/unit/nextjs/routeHandler.test.js.map +0 -1
@@ -3,23 +3,23 @@ import { UserStorage } from "@/shared/lib/types.js";
3
3
  import { convertForwardedTokenFormat } from "@/lib/jwt.js";
4
4
 
5
5
  export interface UserSession {
6
- get(): User | null;
7
- set(user: User): void;
6
+ get(): Promise<User | null>;
7
+ set(user: User): Promise<void>;
8
8
  }
9
9
 
10
10
  export class GenericUserSession implements UserSession {
11
11
  constructor(readonly storage: AuthStorage) {}
12
12
 
13
- get(): User | null {
14
- const user = this.storage.get(UserStorage.USER);
13
+ async get(): Promise<User | null> {
14
+ const user = await this.storage.get(UserStorage.USER);
15
15
  return user ? JSON.parse(user) : null;
16
16
  }
17
17
 
18
- set(user: User | null): void {
18
+ async set(user: User | null): Promise<void> {
19
19
  const forwardedTokens = user?.forwardedTokens
20
20
  ? convertForwardedTokenFormat(user?.forwardedTokens as ForwardedTokensJWT)
21
21
  : null;
22
22
  const value = user ? JSON.stringify({ ...user, forwardedTokens }) : "";
23
- this.storage.set(UserStorage.USER, value);
23
+ await this.storage.set(UserStorage.USER, value);
24
24
  }
25
25
  }
@@ -3,7 +3,7 @@ import { parseJWT } from "oslo/jwt";
3
3
  import type { AuthStorage, User } from "@/types.js";
4
4
 
5
5
  export async function getUser(storage: AuthStorage): Promise<User | null> {
6
- const tokens = retrieveTokens(storage);
6
+ const tokens = await retrieveTokens(storage);
7
7
  if (!tokens) return null;
8
8
 
9
9
  // Assumes all information is in the ID token
@@ -35,6 +35,6 @@ export abstract class CookieStorage implements AuthStorage {
35
35
  path: settings.path ?? "/",
36
36
  };
37
37
  }
38
- abstract get(key: string): string | null;
39
- abstract set(key: string, value: string): void;
38
+ abstract get(key: string): Promise<string | null>;
39
+ abstract set(key: string, value: string): Promise<void>;
40
40
  }
@@ -83,7 +83,6 @@ export async function generateOauthLoginUrl(config: {
83
83
  // Required by the auth server for offline_access scope
84
84
  oAuthUrl.searchParams.append("prompt", "consent");
85
85
 
86
- console.log("Generated OAuth URL", oAuthUrl.toString());
87
86
  return oAuthUrl;
88
87
  }
89
88
 
@@ -139,36 +138,40 @@ export async function exchangeTokens(
139
138
  return tokens;
140
139
  }
141
140
 
142
- export function storeTokens(
141
+ export async function storeTokens(
143
142
  storage: AuthStorage,
144
143
  tokens: OIDCTokenResponseBody,
145
144
  ) {
146
145
  // store tokens in storage ( TODO we should probably store them against the state to allow multiple logins )
147
- storage.set(OAuthTokens.ID_TOKEN, tokens.id_token);
148
- storage.set(OAuthTokens.ACCESS_TOKEN, tokens.access_token);
149
- if (tokens.refresh_token)
150
- storage.set(OAuthTokens.REFRESH_TOKEN, tokens.refresh_token);
146
+ await storage.set(OAuthTokens.ID_TOKEN, tokens.id_token);
147
+ await storage.set(OAuthTokens.ACCESS_TOKEN, tokens.access_token);
148
+ if (tokens.refresh_token) {
149
+ await storage.set(OAuthTokens.REFRESH_TOKEN, tokens.refresh_token);
150
+ }
151
151
  }
152
152
 
153
- export function clearTokens(storage: AuthStorage) {
154
- Object.values(OAuthTokens).forEach((cookie) => {
155
- storage.set(cookie, "");
156
- });
157
- Object.values(CodeVerifier.COOKIE_NAME).forEach((cookie) => {
153
+ export async function clearTokens(storage: AuthStorage) {
154
+ const clearOAuthPromises = Object.values(OAuthTokens).map((cookie) => {
158
155
  storage.set(cookie, "");
159
156
  });
157
+ const clearCodeVerifierPromises = Object.values(CodeVerifier.COOKIE_NAME).map(
158
+ (cookie) => {
159
+ storage.set(cookie, "");
160
+ },
161
+ );
162
+ await Promise.all([...clearOAuthPromises, ...clearCodeVerifierPromises]);
160
163
  }
161
- export function clearUser(storage: AuthStorage) {
164
+ export async function clearUser(storage: AuthStorage) {
162
165
  const userSession = new GenericUserSession(storage);
163
- userSession.set(null);
166
+ await userSession.set(null);
164
167
  }
165
168
 
166
- export function retrieveTokens(
169
+ export async function retrieveTokens(
167
170
  storage: AuthStorage,
168
- ): OIDCTokenResponseBody | null {
169
- const idToken = storage.get(OAuthTokens.ID_TOKEN);
170
- const accessToken = storage.get(OAuthTokens.ACCESS_TOKEN);
171
- const refreshToken = storage.get(OAuthTokens.REFRESH_TOKEN);
171
+ ): Promise<OIDCTokenResponseBody | null> {
172
+ const idToken = await storage.get(OAuthTokens.ID_TOKEN);
173
+ const accessToken = await storage.get(OAuthTokens.ACCESS_TOKEN);
174
+ const refreshToken = await storage.get(OAuthTokens.REFRESH_TOKEN);
172
175
 
173
176
  if (!idToken || !accessToken) return null;
174
177
 
package/src/types.ts CHANGED
@@ -222,6 +222,6 @@ export type {
222
222
  };
223
223
 
224
224
  export interface AuthStorage {
225
- get(key: string): string | null;
226
- set(key: string, value: string): void;
225
+ get(key: string): Promise<string | null>;
226
+ set(key: string, value: string): Promise<void>;
227
227
  }
@@ -17,25 +17,25 @@ const mockUser: User = {
17
17
  describe("getUser", () => {
18
18
  beforeEach(() => {
19
19
  vi.clearAllMocks();
20
- vi.spyOn(GenericUserSession.prototype, "get").mockReturnValue(mockUser);
20
+ vi.spyOn(GenericUserSession.prototype, "get").mockResolvedValue(mockUser);
21
21
  vi.spyOn(NextjsClientStorage.prototype, "get").mockImplementation(
22
- (cookieName: string) => {
22
+ async (cookieName: string) => {
23
23
  switch (cookieName) {
24
24
  case "access_token":
25
- return "test-access-token";
25
+ return Promise.resolve("test-access-token");
26
26
  case "id_token":
27
- return "test-id-token";
27
+ return Promise.resolve("test-id-token");
28
28
  case "refresh_token":
29
- return "test-refresh-token";
29
+ return Promise.resolve("test-refresh-token");
30
30
  default:
31
- return null;
31
+ return Promise.resolve(null);
32
32
  }
33
33
  },
34
34
  );
35
35
  });
36
36
 
37
- it("should get the user from session", () => {
38
- const user = getUser();
37
+ it("should get the user from session", async () => {
38
+ const user = await getUser();
39
39
  expect(user).toEqual(mockUser);
40
40
  });
41
41
  });
@@ -1,11 +1,5 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- /**
4
- * IMPORTANT: If you modify this snapshot, it indicates changes to the public API of the auth SDK, which may impact consumers.
5
- * Ensure such changes are discussed and agreed with the team and that the documentation is updated accordingly.
6
- * Docmentation is managed on GitBook: https://app.gitbook.com/o/-MbHRfakrvYmMaAu3Awh/s/PrqdylKqzZDnu8FytHLf/
7
- */
8
-
9
3
  exports[`Auth Client Public API Snapshot > should match the previous API snapshot 1`] = `
10
4
  {
11
5
  "CivicAuthIframeContainer": [Function],
@@ -18,7 +12,6 @@ exports[`Auth Client Public API Snapshot > should match the previous API snapsho
18
12
  "useIframe": [Function],
19
13
  "useSession": [Function],
20
14
  "useToken": [Function],
21
- "useTokenCookie": [Function],
22
15
  "useUser": [Function],
23
16
  }
24
17
  `;
@@ -1,20 +1,20 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
1
+ import { describe, it, expect, vi } from "vitest";
2
2
  import {
3
3
  resolveOAuthAccessCode,
4
4
  isLoggedIn,
5
5
  buildLoginUrl,
6
- } from "@/server/login.js";
7
- import { ServerAuthenticationResolver } from "@/server/ServerAuthenticationResolver.js";
8
- import { GenericAuthenticationInitiator } from "@/services/AuthenticationService.js";
6
+ } from "@/server/login";
7
+ import { ServerAuthenticationResolver } from "@/server/ServerAuthenticationResolver";
8
+ import { GenericAuthenticationInitiator } from "@/services/AuthenticationService";
9
9
  import { GenericPublicClientPKCEProducer } from "@/services/PKCE.js";
10
- import { DEFAULT_AUTH_SERVER, DEFAULT_SCOPES } from "@/constants.js";
11
- import type { OIDCTokenResponseBody, AuthStorage } from "@/types.js";
12
- import type { AuthConfig } from "@/server/config.js";
13
- import type { PKCEProducer } from "@/services/types.js";
10
+ import { DEFAULT_AUTH_SERVER, DEFAULT_SCOPES } from "@/constants";
11
+ import type { AuthStorage, OIDCTokenResponseBody } from "@/types.js";
12
+ import type { AuthConfig } from "@/server/config.ts";
13
+ import type { PKCEProducer } from "@/services/types.ts";
14
14
 
15
15
  vi.mock("@/server/ServerAuthenticationResolver");
16
16
  vi.mock("@/services/AuthenticationService");
17
- vi.mock("@/services/PKCE");
17
+ vi.mock("@/services/PKCE.js");
18
18
 
19
19
  class StubPKCEProducer implements PKCEProducer {
20
20
  constructor() {}
@@ -70,18 +70,18 @@ describe("Login Utilities", () => {
70
70
  });
71
71
 
72
72
  describe("isLoggedIn", () => {
73
- it("should return true if id_token is in storage", () => {
74
- vi.mocked(mockStorage.get).mockReturnValue("mockIdToken");
73
+ it("should return true if id_token is in storage", async () => {
74
+ vi.mocked(mockStorage.get).mockResolvedValue("mockIdToken");
75
75
 
76
- const result = isLoggedIn(mockStorage);
76
+ const result = await isLoggedIn(mockStorage);
77
77
 
78
78
  expect(result).toBe(true);
79
79
  });
80
80
 
81
- it("should return false if id_token is not in storage", () => {
82
- vi.mocked(mockStorage.get).mockReturnValue(null);
81
+ it("should return false if id_token is not in storage", async () => {
82
+ vi.mocked(mockStorage.get).mockResolvedValue(null);
83
83
 
84
- const result = isLoggedIn(mockStorage);
84
+ const result = await isLoggedIn(mockStorage);
85
85
 
86
86
  expect(result).toBe(false);
87
87
  });
@@ -171,9 +171,11 @@ describe("Login Utilities", () => {
171
171
  mockStorage,
172
172
  );
173
173
 
174
- expect(GenericAuthenticationInitiator).toHaveBeenCalledWith(expect.objectContaining({
175
- nonce,
176
- }));
174
+ expect(GenericAuthenticationInitiator).toHaveBeenCalledWith(
175
+ expect.objectContaining({
176
+ nonce,
177
+ }),
178
+ );
177
179
  });
178
180
  });
179
181
  });
@@ -1,4 +1,4 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
1
+ import { describe, it, expect, vi } from "vitest";
2
2
  import type { JWT } from "oslo/jwt";
3
3
  import { parseJWT } from "oslo/jwt";
4
4
  import { getUser } from "@/shared/lib/session.js";
@@ -20,7 +20,7 @@ describe("getUser", () => {
20
20
  });
21
21
 
22
22
  it("should return null if no tokens are retrieved", async () => {
23
- vi.mocked(retrieveTokens).mockReturnValue(null);
23
+ vi.mocked(retrieveTokens).mockResolvedValue(null);
24
24
 
25
25
  const result = await getUser(mockStorage);
26
26
  expect(result).toBeNull();
@@ -29,7 +29,7 @@ describe("getUser", () => {
29
29
 
30
30
  it("should return a User if tokens are retrieved and parsed successfully", async () => {
31
31
  const mockTokens = { id_token: "mockIdToken" } as OIDCTokenResponseBody;
32
- vi.mocked(retrieveTokens).mockReturnValue(mockTokens);
32
+ vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
33
33
  vi.mocked(parseJWT).mockReturnValue({ payload: mockUser } as JWT);
34
34
 
35
35
  const result = await getUser(mockStorage);
@@ -40,7 +40,7 @@ describe("getUser", () => {
40
40
 
41
41
  it("should return null if parsing the ID token fails", async () => {
42
42
  const mockTokens = { id_token: "mockIdToken" } as OIDCTokenResponseBody;
43
- vi.mocked(retrieveTokens).mockReturnValue(mockTokens);
43
+ vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
44
44
  vi.mocked(parseJWT).mockReturnValue(null); // Simulate parse failure
45
45
 
46
46
  const result = await getUser(mockStorage);
@@ -29,7 +29,7 @@ vi.mock("@/shared/lib/util.js", () => ({
29
29
  clearUser: vi.fn(),
30
30
  }));
31
31
  vi.mock("@/browser/storage");
32
- vi.mock("@/services/PKCE");
32
+ vi.mock("@/services/PKCE.js");
33
33
 
34
34
  describe("Authentication Services", () => {
35
35
  const mockConfig = {
@@ -51,7 +51,7 @@ describe("Authentication Services", () => {
51
51
  new URL("http://mockLoginUrl"),
52
52
  );
53
53
 
54
- const url = await initiator.signIn(null);
54
+ const url = await initiator.signIn({} as HTMLIFrameElement);
55
55
 
56
56
  expect(url.toString()).toBe("http://mockloginurl/");
57
57
  });
@@ -114,7 +114,7 @@ describe("Authentication Services", () => {
114
114
  ...mockConfig,
115
115
  });
116
116
  vi.mocked(exchangeTokens).mockResolvedValue(mockTokens);
117
- vi.mocked(retrieveTokens).mockReturnValue(mockTokens);
117
+ vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
118
118
  });
119
119
 
120
120
  it("should exchange auth code for tokens and store them", async () => {
@@ -6,13 +6,18 @@ import {
6
6
  retrieveTokens,
7
7
  storeTokens,
8
8
  } from "@/shared/lib/util.js";
9
- import type { Endpoints, OIDCTokenResponseBody, SessionData, AuthStorage } from "@/types.js";
10
- import type { AuthConfig } from "@/server/config.js";
9
+ import type {
10
+ AuthStorage,
11
+ Endpoints,
12
+ OIDCTokenResponseBody,
13
+ SessionData,
14
+ } from "@/types.js";
15
+ import type { AuthConfig } from "@/server/config.ts";
11
16
  import { GenericPublicClientPKCEProducer } from "@/services/PKCE.js";
12
- import type { AuthenticationResolver } from '@/services/types.js';
17
+ import type { AuthenticationResolver } from "@/services/types.ts";
13
18
 
14
19
  vi.mock("oslo/oauth2");
15
- vi.mock("@/services/PKCE");
20
+ vi.mock("@/services/PKCE.js");
16
21
  vi.mock("@/shared/lib/util.js");
17
22
 
18
23
  describe("ServerAuthenticationResolver", () => {
@@ -84,7 +89,7 @@ describe("ServerAuthenticationResolver", () => {
84
89
 
85
90
  describe("getSessionData", () => {
86
91
  it("should retrieve session data from storage", async () => {
87
- vi.mocked(retrieveTokens).mockReturnValue(mockTokens);
92
+ vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
88
93
 
89
94
  const sessionData: SessionData = {
90
95
  authenticated: true,
@@ -100,7 +105,7 @@ describe("ServerAuthenticationResolver", () => {
100
105
  });
101
106
 
102
107
  it("should return null if no tokens are found in storage", async () => {
103
- vi.mocked(retrieveTokens).mockReturnValue(null);
108
+ vi.mocked(retrieveTokens).mockResolvedValue(null);
104
109
 
105
110
  const result = await resolver.getSessionData();
106
111
 
@@ -5,9 +5,9 @@ import {
5
5
  retrieveTokens,
6
6
  storeTokens,
7
7
  } from "@/shared/lib/util.js";
8
- import type { Endpoints, OIDCTokenResponseBody, AuthStorage} from "@/types.js";
8
+ import type { AuthStorage, Endpoints, OIDCTokenResponseBody } from "@/types.js";
9
9
  import { OAuth2Client } from "oslo/oauth2";
10
- import type { AuthConfig } from "@/server/config.js";
10
+ import type { AuthConfig } from "@/server/config.ts";
11
11
 
12
12
  vi.mock("@/shared/lib/util.js");
13
13
  vi.mock("oslo/oauth2");
@@ -55,7 +55,7 @@ describe("GenericAuthenticationRefresher", () => {
55
55
 
56
56
  describe("refreshTokens", () => {
57
57
  it("should refresh tokens and store them", async () => {
58
- vi.mocked(retrieveTokens).mockReturnValue(mockTokens);
58
+ vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
59
59
  const refreshedTokens: OIDCTokenResponseBody = {
60
60
  id_token: "newIdToken",
61
61
  access_token: "newAccessToken",
@@ -76,7 +76,7 @@ describe("GenericAuthenticationRefresher", () => {
76
76
  });
77
77
 
78
78
  it("should throw an error if no refresh token is available", async () => {
79
- vi.mocked(retrieveTokens).mockReturnValue({
79
+ vi.mocked(retrieveTokens).mockResolvedValue({
80
80
  ...mockTokens,
81
81
  refresh_token: undefined,
82
82
  });
@@ -12,10 +12,10 @@ const mockUser: User = {
12
12
 
13
13
  let storage: Record<string, string> = {};
14
14
  class TestStorage implements AuthStorage {
15
- get(key: string): string | null {
15
+ async get(key: string): Promise<string | null> {
16
16
  return storage[key] ?? null;
17
17
  }
18
- set(key: string, value: string): void {
18
+ async set(key: string, value: string): Promise<void> {
19
19
  storage[key] = value;
20
20
  }
21
21
  }
@@ -26,16 +26,16 @@ describe("UserSession", () => {
26
26
  });
27
27
 
28
28
  describe("GenericUserSession", () => {
29
- it("should get the user from session", () => {
29
+ it("should get the user from session", async () => {
30
30
  const userSession = new GenericUserSession(new TestStorage());
31
31
  userSession.set(mockUser);
32
- const user = userSession.get();
32
+ const user = await userSession.get();
33
33
  expect(user).toEqual(mockUser);
34
34
  });
35
35
 
36
- it("should return null if user it not found", () => {
36
+ it("should return null if user it not found", async () => {
37
37
  const userSession = new GenericUserSession(new TestStorage());
38
- const user = userSession.get();
38
+ const user = await userSession.get();
39
39
  expect(user).toBeNull();
40
40
  });
41
41
  });
@@ -13,10 +13,10 @@ describe("CookieStorage", () => {
13
13
  super(settings);
14
14
  }
15
15
 
16
- get(key: string): string | null {
16
+ async get(key: string): Promise<string | null> {
17
17
  return this.storage[key] ?? null;
18
18
  }
19
- set(key: string, value: string): void {
19
+ async set(key: string, value: string): Promise<void> {
20
20
  this.storage[key] = value;
21
21
  }
22
22
  }
@@ -57,11 +57,11 @@ describe("CookieStorage", () => {
57
57
  expect(storage["settings"]).toMatchObject(customSettings);
58
58
  });
59
59
 
60
- it("should set and get values correctly", () => {
60
+ it("should set and get values correctly", async () => {
61
61
  const storage = new MockCookieStorage({});
62
62
 
63
- storage.set("testKey", "testValue");
64
- expect(storage.get("testKey")).toBe("testValue");
65
- expect(storage.get("nonExistentKey")).toBe(null);
63
+ await storage.set("testKey", "testValue");
64
+ expect(await storage.get("testKey")).toBe("testValue");
65
+ expect(await storage.get("nonExistentKey")).toBe(null);
66
66
  });
67
67
  });
@@ -1,2 +0,0 @@
1
- export { CivicNextAuthProvider as CivicAuthProvider, type NextCivicAuthProviderProps as AuthProviderProps, } from "@/nextjs/providers/NextAuthProvider.jsx";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/nextjs/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,IAAI,iBAAiB,EAC1C,KAAK,0BAA0B,IAAI,iBAAiB,GACrD,MAAM,yCAAyC,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CivicAuthProvider = void 0;
4
- var NextAuthProvider_jsx_1 = require("@/nextjs/providers/NextAuthProvider.jsx");
5
- Object.defineProperty(exports, "CivicAuthProvider", { enumerable: true, get: function () { return NextAuthProvider_jsx_1.CivicNextAuthProvider; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/nextjs/client/index.ts"],"names":[],"mappings":";;;AAAA,gFAGiD;AAF/C,yHAAA,qBAAqB,OAAqB","sourcesContent":["export {\n CivicNextAuthProvider as CivicAuthProvider,\n type NextCivicAuthProviderProps as AuthProviderProps,\n} from \"@/nextjs/providers/NextAuthProvider.jsx\";\n"]}